summaryrefslogtreecommitdiff
path: root/val.h
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-22 11:51:59 +0100
committerubq323 <ubq323@ubq323.website>2024-06-22 11:51:59 +0100
commitba0eb2042cefce45efa5c1ad294f05d0122815ee (patch)
tree1bd6f747538b315e5091eea6a773b7401db16929 /val.h
parent24f5d4f4456fce3a9e8cd5a7c1225facd60ae979 (diff)
fix circular dependencies
Diffstat (limited to 'val.h')
-rw-r--r--val.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/val.h b/val.h
index 1db122b..e4227a4 100644
--- a/val.h
+++ b/val.h
@@ -5,10 +5,8 @@
#include <stdint.h>
#include <stddef.h>
-
typedef struct _val Val;
typedef struct _obj Obj;
-typedef struct _state State;
typedef enum {
@@ -26,6 +24,8 @@ typedef struct _val {
Obj *o;
} as;
} Val;
+
+
void print_val(Val v);
void println_val(Val v);
const char *typename_str(Val v);
@@ -36,6 +36,7 @@ bool val_equal(Val a, Val b);
typedef enum {
OTY_STRING,
+ OTY_FUNC,
} ObjTy;
typedef struct _obj {
@@ -48,6 +49,12 @@ typedef struct {
uint32_t hash;
char *d;
} ObjString;
+#include "chunk.h"
+
+typedef struct {
+ Obj obj;
+ Chunk chunk;
+} ObjFunc;
// Constructs a new objstring from the given C string,
// creating its own fresh copy of the data.
@@ -57,6 +64,7 @@ ObjString *objstring_copy_cstr(State *s, char *str);
// taking ownership of the provided data.
ObjString *objstring_take(State *S, char *src, size_t len);
+ObjFunc *objfunc_new(State *S);
#define IS_NIL(x) (x.ty == TY_NIL)
#define IS_NUM(x) (x.ty == TY_NUM)
@@ -71,6 +79,7 @@ ObjString *objstring_take(State *S, char *src, size_t len);
#define AS_STRING(x) ((ObjString*)AS_OBJ(x))
#define AS_CSTRING(x) (AS_STRING(x)->d)
+#define AS_FUNC(x) ((ObjFunc*)AS_OBJ(x))
#define VAL_NIL ((Val){.ty=TY_NIL})
#define VAL_NUM(x) ((Val){.ty=TY_NUM, .as.d=(x) })