aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/object.c
diff options
context:
space:
mode:
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;