new built-in variables for each type
This commit is contained in:
@@ -83,7 +83,7 @@ static int hash(Object *self)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Object *Object_NewStaticMap(const StaticMapSlot *slots, Runtime *runt, Error *error)
|
||||
Object *Object_NewStaticMap(StaticMapSlot slots[], void (*initfn)(StaticMapSlot[]), Runtime *runt, Error *error)
|
||||
{
|
||||
Heap *heap = Runtime_GetHeap(runt);
|
||||
|
||||
@@ -97,6 +97,9 @@ Object *Object_NewStaticMap(const StaticMapSlot *slots, Runtime *runt, Error *er
|
||||
obj->slots = slots;
|
||||
}
|
||||
|
||||
if(initfn != NULL)
|
||||
initfn(slots);
|
||||
|
||||
return (Object*) obj;
|
||||
}
|
||||
|
||||
@@ -130,7 +133,7 @@ static Object *select(Object *self, Object *key, Heap *heap, Error *error)
|
||||
case SM_FLOAT: return Object_FromFloat(slot.as_float, heap, error);
|
||||
case SM_FUNCT: return Object_FromNativeFunction(map->runt, slot.as_funct, slot.argc, heap, error);
|
||||
case SM_STRING: return Object_FromString(slot.as_string, slot.length, heap, error);
|
||||
case SM_SMAP: return Object_NewStaticMap(slot.as_smap, map->runt, error);
|
||||
case SM_SMAP: return Object_NewStaticMap(slot.as_smap, NULL, map->runt, error);
|
||||
case SM_NONE: return Object_NewNone(heap, error);
|
||||
case SM_TYPE: return (Object*) slot.as_type;
|
||||
default: assert(0); break;
|
||||
|
||||
@@ -74,18 +74,18 @@ struct StaticMapSlot {
|
||||
const char *name;
|
||||
StaticMapSlotKind kind;
|
||||
union {
|
||||
const StaticMapSlot *as_smap;
|
||||
const char *as_string;
|
||||
_Bool as_bool;
|
||||
long long int as_int;
|
||||
double as_float;
|
||||
int (*as_funct)(Runtime*, Object**, unsigned int, Object**, unsigned int, Error*);
|
||||
TypeObject *as_type;
|
||||
StaticMapSlot *as_smap;
|
||||
const char *as_string;
|
||||
_Bool as_bool;
|
||||
long long int as_int;
|
||||
double as_float;
|
||||
int (*as_funct)(Runtime*, Object**, unsigned int, Object**, unsigned int, Error*);
|
||||
TypeObject *as_type;
|
||||
};
|
||||
union { int argc; int length; };
|
||||
};
|
||||
|
||||
Object *Object_NewStaticMap(const StaticMapSlot *slots, Runtime *runt, Error *error);
|
||||
Object *Object_NewStaticMap(StaticMapSlot slots[], void (*initfn)(StaticMapSlot[]), Runtime *runt, Error *error);
|
||||
Object *Object_FromNojaFunction(Runtime *runtime, Executable *exe, int index, int argc, Object *closure, Heap *heap, Error *error);
|
||||
Object *Object_FromNativeFunction(Runtime *runtime, int (*callback)(Runtime*, Object**, unsigned int, Object**, unsigned int, Error*), int argc, Heap *heap, Error *error);
|
||||
typedef struct {
|
||||
|
||||
Reference in New Issue
Block a user