diff options
Diffstat (limited to 'clox/src/object.h')
-rw-r--r-- | clox/src/object.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clox/src/object.h b/clox/src/object.h index 812c464..b5942d6 100644 --- a/clox/src/object.h +++ b/clox/src/object.h @@ -8,14 +8,17 @@ #define OBJ_TYPE(value) (AS_OBJ(value)->type) #define IS_FUNCTION(value) isObjType(value, OBJ_FUNCTION) +#define IS_NATIVE(value) isObjType(value, OBJ_NATIVE) #define IS_STRING(value) isObjType(value, OBJ_STRING) #define AS_FUNCTION(value) ((ObjFunction *)AS_OBJ(value)) +#define AS_NATIVE(value) (((ObjNative *)AS_OBJ(value))->function) #define AS_STRING(value) ((ObjString *)AS_OBJ(value)) #define AS_CSTRING(value) (((ObjString *)AS_OBJ(value))->chars) typedef enum { OBJ_FUNCTION, + OBJ_NATIVE, OBJ_STRING, } ObjType; @@ -31,6 +34,13 @@ typedef struct { ObjString *name; } ObjFunction; +typedef Value (*NativeFn)(int argCount, Value *args); + +typedef struct { + Obj obj; + NativeFn function; +} ObjNative; + struct ObjString { Obj obj; int length; @@ -39,6 +49,7 @@ struct ObjString { }; ObjFunction *newFunction(); +ObjNative *newNative(NativeFn function); ObjString *takeString(char *chars, int length); ObjString *copyString(const char *chars, int length); void printObject(Value value); |