aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/object.h
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-08-13 14:20:54 -0700
committerGravatar Tom Willemse2022-08-13 14:20:54 -0700
commitac0f95683ff94d20114c46b365088910dd60fdda (patch)
tree13ccfc37c660f106d896ec554bb724cc4f2ff178 /clox/src/object.h
parent07f691425c95a53323229accd8a907c5dea7e530 (diff)
downloadcrafting-interpreters-ac0f95683ff94d20114c46b365088910dd60fdda.tar.gz
crafting-interpreters-ac0f95683ff94d20114c46b365088910dd60fdda.zip
Chapter 28.2
Diffstat (limited to 'clox/src/object.h')
-rw-r--r--clox/src/object.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/clox/src/object.h b/clox/src/object.h
index 4c115ce..e51d7d8 100644
--- a/clox/src/object.h
+++ b/clox/src/object.h
@@ -8,6 +8,7 @@
#define OBJ_TYPE(value) (AS_OBJ(value)->type)
+#define IS_BOUND_METHOD(value) isObjType(value, OBJ_BOUND_METHOD)
#define IS_CLASS(value) isObjType(value, OBJ_CLASS)
#define IS_CLOSURE(value) isObjType(value, OBJ_CLOSURE)
#define IS_FUNCTION(value) isObjType(value, OBJ_FUNCTION)
@@ -15,6 +16,7 @@
#define IS_NATIVE(value) isObjType(value, OBJ_NATIVE)
#define IS_STRING(value) isObjType(value, OBJ_STRING)
+#define AS_BOUND_METHOD(value) ((ObjBoundMethod *)AS_OBJ(value))
#define AS_CLASS(value) ((ObjClass *)AS_OBJ(value))
#define AS_CLOSURE(value) ((ObjClosure *)AS_OBJ(value))
#define AS_FUNCTION(value) ((ObjFunction *)AS_OBJ(value))
@@ -24,6 +26,7 @@
#define AS_CSTRING(value) (((ObjString *)AS_OBJ(value))->chars)
typedef enum {
+ OBJ_BOUND_METHOD,
OBJ_CLASS,
OBJ_CLOSURE,
OBJ_FUNCTION,
@@ -87,6 +90,13 @@ typedef struct {
Table fields;
} ObjInstance;
+typedef struct {
+ Obj obj;
+ Value receiver;
+ ObjClosure *method;
+} ObjBoundMethod;
+
+ObjBoundMethod *newBoundMethod(Value receiver, ObjClosure *method);
ObjClass *newClass(ObjString *name);
ObjClosure *newClosure(ObjFunction *function);
ObjFunction *newFunction();