From 57ed9226c06b5fbe016e62857fe9662c51da3dfd Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 2 Jun 2022 22:27:43 -0700 Subject: Chapter 25.3 & 25.4 --- clox/src/object.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'clox/src/object.h') 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) { -- cgit v1.2.3-54-g00ecf