aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/object.h
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-08-12 20:13:25 -0700
committerGravatar Tom Willemse2022-08-12 20:13:25 -0700
commit63527558a72fb56d11d1166ce958dcfc8a765482 (patch)
tree28c3425cce1a70b21710bc95a690fab6388f8b50 /clox/src/object.h
parentad6a98f6ad3cce9d69648360d00d5dcd67d8ca0f (diff)
downloadcrafting-interpreters-63527558a72fb56d11d1166ce958dcfc8a765482.tar.gz
crafting-interpreters-63527558a72fb56d11d1166ce958dcfc8a765482.zip
Chapter 27.1
Diffstat (limited to 'clox/src/object.h')
-rw-r--r--clox/src/object.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/clox/src/object.h b/clox/src/object.h
index 36ec034..44de6ed 100644
--- a/clox/src/object.h
+++ b/clox/src/object.h
@@ -7,11 +7,13 @@
#define OBJ_TYPE(value) (AS_OBJ(value)->type)
+#define IS_CLASS(value) isObjType(value, OBJ_CLASS)
#define IS_CLOSURE(value) isObjType(value, OBJ_CLOSURE)
#define IS_FUNCTION(value) isObjType(value, OBJ_FUNCTION)
#define IS_NATIVE(value) isObjType(value, OBJ_NATIVE)
#define IS_STRING(value) isObjType(value, OBJ_STRING)
+#define AS_CLASS(value) ((ObjClass *)AS_OBJ(value))
#define AS_CLOSURE(value) ((ObjClosure *)AS_OBJ(value))
#define AS_FUNCTION(value) ((ObjFunction *)AS_OBJ(value))
#define AS_NATIVE(value) (((ObjNative *)AS_OBJ(value))->function)
@@ -19,6 +21,7 @@
#define AS_CSTRING(value) (((ObjString *)AS_OBJ(value))->chars)
typedef enum {
+ OBJ_CLASS,
OBJ_CLOSURE,
OBJ_FUNCTION,
OBJ_NATIVE,
@@ -68,6 +71,12 @@ typedef struct {
int upvalueCount;
} ObjClosure;
+typedef struct {
+ Obj obj;
+ ObjString *name;
+} ObjClass;
+
+ObjClass *newClass(ObjString *name);
ObjClosure *newClosure(ObjFunction *function);
ObjFunction *newFunction();
ObjNative *newNative(NativeFn function);