aboutsummaryrefslogtreecommitdiffstats
path: root/clox/src/object.h
diff options
context:
space:
mode:
Diffstat (limited to 'clox/src/object.h')
-rw-r--r--clox/src/object.h12
1 files changed, 12 insertions, 0 deletions
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);