diff options
author | 2022-01-21 21:24:26 -0800 | |
---|---|---|
committer | 2022-01-21 21:24:26 -0800 | |
commit | 9025da8168e505e2b0e32b89a0d94db935dace93 (patch) | |
tree | 162fa69ce309ab3eb0359ba59d1180c02d4869ec /clox/src/object.h | |
parent | 37ac05af6d0aa57ccc5ea805af262a407fedeeae (diff) | |
download | crafting-interpreters-9025da8168e505e2b0e32b89a0d94db935dace93.tar.gz crafting-interpreters-9025da8168e505e2b0e32b89a0d94db935dace93.zip |
Chapter 24.1
Diffstat (limited to 'clox/src/object.h')
-rw-r--r-- | clox/src/object.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/clox/src/object.h b/clox/src/object.h index 717031b..812c464 100644 --- a/clox/src/object.h +++ b/clox/src/object.h @@ -1,17 +1,21 @@ #ifndef OBJECT_H #define OBJECT_H +#include "chunk.h" #include "common.h" #include "value.h" #define OBJ_TYPE(value) (AS_OBJ(value)->type) +#define IS_FUNCTION(value) isObjType(value, OBJ_FUNCTION) #define IS_STRING(value) isObjType(value, OBJ_STRING) +#define AS_FUNCTION(value) ((ObjFunction *)AS_OBJ(value)) #define AS_STRING(value) ((ObjString *)AS_OBJ(value)) #define AS_CSTRING(value) (((ObjString *)AS_OBJ(value))->chars) typedef enum { + OBJ_FUNCTION, OBJ_STRING, } ObjType; @@ -20,6 +24,13 @@ struct Obj { struct Obj *next; }; +typedef struct { + Obj obj; + int arity; + Chunk chunk; + ObjString *name; +} ObjFunction; + struct ObjString { Obj obj; int length; @@ -27,6 +38,7 @@ struct ObjString { uint32_t hash; }; +ObjFunction *newFunction(); ObjString *takeString(char *chars, int length); ObjString *copyString(const char *chars, int length); void printObject(Value value); |