1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/* -*- c -*- */
/*
* value.h
*
* chpp
*
* Copyright (C) 1997-1998 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __VALUE_H__
#define __VALUE_H__
#include "chash.h"
#include "avl.h"
#include "dynstring.h"
#include "internals.h"
#include "builtins/builtins.h"
struct _bytecode;
struct _environment;
#define VALUE_UNDEFINED 0
#define VALUE_INTERNAL 1
#define VALUE_BUILT_IN 2
#define VALUE_SCALAR 3
#define VALUE_LIST 4
#define VALUE_HASH 5
#define VALUE_LAMBDA 6
#define VALUE_WHATSIT 7
typedef struct _value
{
int type;
union
{
struct
{
internalSet setFunc;
internalGet getFunc;
} internal;
struct
{
builtIn function;
int evalParams;
builtInGlobalEffector globalEffector;
builtInEnvironmentor environmentor;
} builtIn;
struct
{
dynstring scalar;
} scalar;
struct
{
avlTree *list;
} list;
struct
{
hash hash;
} hash;
struct
{
int numParams;
int minVarArgs;
int maxVarArgs;
dynstring *paramNames;
char metaChar;
struct _bytecode *code;
struct _environment *env;
} lambda;
struct
{
void *data;
} whatsit;
} v;
} value;
value* valueNewUndefined (void);
value* valueNewInternal (internalSet setFunc, internalGet getFunc);
value* valueNewBuiltIn (builtIn function, int evalParams,
builtInGlobalEffector globalEffector,
builtInEnvironmentor environmentor);
value* valueNewScalar (dynstring *scalar);
value* valueNewScalarFromCString (const char *scalar);
value* valueNewScalarFromBytes (const char *scalar, int length);
value* valueNewList (void);
value* valueNewHash (void);
value* valueNewLambda (int numParams, int minVarArgs, int maxVarArgs,
dynstring *paramNames, char metaChar,
struct _bytecode *code, struct _environment *env);
value* valueNewWhatsit (void *data);
value* valueNewScalarFromValue (value *theValue);
value* valueCopy (value *theValue);
value* valueCopyDeep (value *theValue);
int valueCompare (value *value1, value *value2);
int valueAreSame (value *value1, value *value2);
int valueAreEqual (value *value1, value *value2);
value* valueAssign (value *dest, value *src, int share);
int valueBoolValue (value *theValue);
int valueHashCount (value *theValue);
void valueHashDefine (value *aValue, dynstring *key, value *defValue);
value* valueHashLookup (value *value, dynstring *key);
value* valueHashLookupCString (value *value, const char *key);
int valueListLength (value *value);
value* valueListGetElement (value *value, int index);
void valueListSetElement (value *theValue, int index, value *defValue);
void valueListInsertElement (value *theValue, int index, value *defValue);
void valueListDeleteElement (value *theValue, int index);
void valueListAppendList (value *list, value *appended, int destroy);
void valueListClear (value *theValue);
void* valueWhatsitData (value *theValue);
value* valueTransformToScalar (value *theValue);
const char* cStringForValueType (int type);
#endif
|