From 9025da8168e505e2b0e32b89a0d94db935dace93 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 21 Jan 2022 21:24:26 -0800 Subject: Chapter 24.1 --- clox/src/object.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'clox/src/object.c') diff --git a/clox/src/object.c b/clox/src/object.c index 361e315..7170352 100644 --- a/clox/src/object.c +++ b/clox/src/object.c @@ -19,6 +19,14 @@ static Obj *allocateObject(size_t size, ObjType type) { return object; } +ObjFunction *newFunction() { + ObjFunction *function = ALLOCATE_OBJ(ObjFunction, OBJ_FUNCTION); + function->arity = 0; + function->name = NULL; + initChunk(&function->chunk); + return function; +} + static ObjString *allocateString(char *chars, int length, uint32_t hash) { ObjString *string = ALLOCATE_OBJ(ObjString, OBJ_STRING); string->length = length; @@ -60,8 +68,15 @@ ObjString *copyString(const char *chars, int length) { return allocateString(heapChars, length, hash); } +static void printFunction(ObjFunction *function) { + printf("", function->name->chars); +} + void printObject(Value value) { switch (OBJ_TYPE(value)) { + case OBJ_FUNCTION: + printFunction(AS_FUNCTION(value)); + break; case OBJ_STRING: printf("%s", AS_CSTRING(value)); break; -- cgit v1.2.3-54-g00ecf