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.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/clox/src/object.c b/clox/src/object.c
index 935a258..a431314 100644
--- a/clox/src/object.c
+++ b/clox/src/object.c
@@ -53,6 +53,13 @@ ObjFunction *newFunction() {
return function;
}
+ObjInstance *newInstance(ObjClass *klass) {
+ ObjInstance *instance = ALLOCATE_OBJ(ObjInstance, OBJ_INSTANCE);
+ instance->klass = klass;
+ initTable(&instance->fields);
+ return instance;
+}
+
ObjNative *newNative(NativeFn function) {
ObjNative *native = ALLOCATE_OBJ(ObjNative, OBJ_NATIVE);
native->function = function;
@@ -131,6 +138,9 @@ void printObject(Value value) {
case OBJ_FUNCTION:
printFunction(AS_FUNCTION(value));
break;
+ case OBJ_INSTANCE:
+ printf("%s instance", AS_INSTANCE(value)->klass->name->chars);
+ break;
case OBJ_NATIVE:
printf("<native fn>");
break;