From ac0f95683ff94d20114c46b365088910dd60fdda Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sat, 13 Aug 2022 14:20:54 -0700 Subject: Chapter 28.2 --- clox/src/object.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'clox/src/object.h') 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(); -- cgit v1.2.3-54-g00ecf