diff options
author | 2022-03-22 17:15:17 -0700 | |
---|---|---|
committer | 2022-03-22 17:15:17 -0700 | |
commit | 3da4016d5784adef217fff0ad1e3a0ceff76290f (patch) | |
tree | ef7c41c0a013b2e9a5212f9f3b74bdfb85e84336 /clox/src/object.h | |
parent | baedf99f635735c50936bb555e4a77058ec9e2e0 (diff) | |
download | crafting-interpreters-3da4016d5784adef217fff0ad1e3a0ceff76290f.tar.gz crafting-interpreters-3da4016d5784adef217fff0ad1e3a0ceff76290f.zip |
Chapter 24.7
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); |