diff options
author | Tom Willemse | 2022-08-12 20:13:25 -0700 |
---|---|---|
committer | Tom Willemse | 2022-08-12 20:13:25 -0700 |
commit | 63527558a72fb56d11d1166ce958dcfc8a765482 (patch) | |
tree | 28c3425cce1a70b21710bc95a690fab6388f8b50 /clox/src/object.c | |
parent | ad6a98f6ad3cce9d69648360d00d5dcd67d8ca0f (diff) | |
download | crafting-interpreters-63527558a72fb56d11d1166ce958dcfc8a765482.tar.gz crafting-interpreters-63527558a72fb56d11d1166ce958dcfc8a765482.zip |
Chapter 27.1
Diffstat (limited to 'clox/src/object.c')
-rw-r--r-- | clox/src/object.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/clox/src/object.c b/clox/src/object.c index 376742f..935a258 100644 --- a/clox/src/object.c +++ b/clox/src/object.c @@ -25,6 +25,12 @@ static Obj *allocateObject(size_t size, ObjType type) { return object; } +ObjClass *newClass(ObjString *name) { + ObjClass *klass = ALLOCATE_OBJ(ObjClass, OBJ_CLASS); + klass->name = name; + return klass; +} + ObjClosure *newClosure(ObjFunction *function) { ObjUpvalue **upvalues = ALLOCATE(ObjUpvalue *, function->upvalueCount); for (int i = 0; i < function->upvalueCount; i++) { @@ -116,6 +122,9 @@ static void printFunction(ObjFunction *function) { void printObject(Value value) { switch (OBJ_TYPE(value)) { + case OBJ_CLASS: + printf("%s", AS_CLASS(value)->name->chars); + break; case OBJ_CLOSURE: printFunction(AS_CLOSURE(value)->function); break; |