From 1ae50814d3c7fc75fe02f7ce53497cb17f8114ff Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 23 Mar 2022 17:00:22 -0700 Subject: Chapter 25.1 --- clox/src/object.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'clox/src/object.c') 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; -- cgit v1.2.3-54-g00ecf