diff options
author | Tom Willemse | 2022-06-02 22:27:43 -0700 |
---|---|---|
committer | Tom Willemse | 2022-06-02 22:27:43 -0700 |
commit | 57ed9226c06b5fbe016e62857fe9662c51da3dfd (patch) | |
tree | f8bdae71c33f92ba1e105612ee848fcf168d3777 /clox/src/object.h | |
parent | e74cbddb0463e93f5d9742accc20bbed027d0b9b (diff) | |
download | crafting-interpreters-57ed9226c06b5fbe016e62857fe9662c51da3dfd.tar.gz crafting-interpreters-57ed9226c06b5fbe016e62857fe9662c51da3dfd.zip |
Chapter 25.3 & 25.4
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 f650b30..e6b842d 100644 --- a/clox/src/object.h +++ b/clox/src/object.h @@ -23,6 +23,7 @@ typedef enum { OBJ_FUNCTION, OBJ_NATIVE, OBJ_STRING, + OBJ_UPVALUE, } ObjType; struct Obj { @@ -52,9 +53,18 @@ struct ObjString { uint32_t hash; }; +typedef struct ObjUpvalue { + Obj obj; + Value *location; + Value closed; + struct ObjUpvalue *next; +} ObjUpvalue; + typedef struct { Obj obj; ObjFunction *function; + ObjUpvalue **upvalues; + int upvalueCount; } ObjClosure; ObjClosure *newClosure(ObjFunction *function); @@ -62,6 +72,7 @@ ObjFunction *newFunction(); ObjNative *newNative(NativeFn function); ObjString *takeString(char *chars, int length); ObjString *copyString(const char *chars, int length); +ObjUpvalue *newUpvalue(Value *slot); void printObject(Value value); static inline bool isObjType(Value value, ObjType type) { |