From 9025da8168e505e2b0e32b89a0d94db935dace93 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 21 Jan 2022 21:24:26 -0800 Subject: Chapter 24.1 --- clox/src/object.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'clox/src/object.h') diff --git a/clox/src/object.h b/clox/src/object.h index 717031b..812c464 100644 --- a/clox/src/object.h +++ b/clox/src/object.h @@ -1,17 +1,21 @@ #ifndef OBJECT_H #define OBJECT_H +#include "chunk.h" #include "common.h" #include "value.h" #define OBJ_TYPE(value) (AS_OBJ(value)->type) +#define IS_FUNCTION(value) isObjType(value, OBJ_FUNCTION) #define IS_STRING(value) isObjType(value, OBJ_STRING) +#define AS_FUNCTION(value) ((ObjFunction *)AS_OBJ(value)) #define AS_STRING(value) ((ObjString *)AS_OBJ(value)) #define AS_CSTRING(value) (((ObjString *)AS_OBJ(value))->chars) typedef enum { + OBJ_FUNCTION, OBJ_STRING, } ObjType; @@ -20,6 +24,13 @@ struct Obj { struct Obj *next; }; +typedef struct { + Obj obj; + int arity; + Chunk chunk; + ObjString *name; +} ObjFunction; + struct ObjString { Obj obj; int length; @@ -27,6 +38,7 @@ struct ObjString { uint32_t hash; }; +ObjFunction *newFunction(); ObjString *takeString(char *chars, int length); ObjString *copyString(const char *chars, int length); void printObject(Value value); -- cgit v1.2.3-54-g00ecf