diff options
author | Tom Willemse | 2022-03-23 17:00:22 -0700 |
---|---|---|
committer | Tom Willemse | 2022-03-23 17:00:22 -0700 |
commit | 1ae50814d3c7fc75fe02f7ce53497cb17f8114ff (patch) | |
tree | d54dbf36a1fd0bbd9855482843e812ecc06e2009 /clox/src/object.c | |
parent | 3da4016d5784adef217fff0ad1e3a0ceff76290f (diff) | |
download | crafting-interpreters-1ae50814d3c7fc75fe02f7ce53497cb17f8114ff.tar.gz crafting-interpreters-1ae50814d3c7fc75fe02f7ce53497cb17f8114ff.zip |
Chapter 25.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 d4afccc..c12fb82 100644 --- a/clox/src/object.c +++ b/clox/src/object.c @@ -19,6 +19,12 @@ static Obj *allocateObject(size_t size, ObjType type) { return object; } +ObjClosure *newClosure(ObjFunction *function) { + ObjClosure *closure = ALLOCATE_OBJ(ObjClosure, OBJ_CLOSURE); + closure->function = function; + return closure; +} + ObjFunction *newFunction() { ObjFunction *function = ALLOCATE_OBJ(ObjFunction, OBJ_FUNCTION); function->arity = 0; @@ -84,6 +90,9 @@ static void printFunction(ObjFunction *function) { void printObject(Value value) { switch (OBJ_TYPE(value)) { + case OBJ_CLOSURE: + printFunction(AS_CLOSURE(value)->function); + break; case OBJ_FUNCTION: printFunction(AS_FUNCTION(value)); break; |