aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/object.c
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-01-21 21:24:26 -0800
committerGravatar Tom Willemse2022-01-21 21:24:26 -0800
commit9025da8168e505e2b0e32b89a0d94db935dace93 (patch)
tree162fa69ce309ab3eb0359ba59d1180c02d4869ec /clox/src/object.c
parent37ac05af6d0aa57ccc5ea805af262a407fedeeae (diff)
downloadcrafting-interpreters-9025da8168e505e2b0e32b89a0d94db935dace93.tar.gz
crafting-interpreters-9025da8168e505e2b0e32b89a0d94db935dace93.zip
Chapter 24.1
Diffstat (limited to 'clox/src/object.c')
-rw-r--r--clox/src/object.c15
1 files changed, 15 insertions, 0 deletions
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("<fn %s>", 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;