From ba0eb2042cefce45efa5c1ad294f05d0122815ee Mon Sep 17 00:00:00 2001
From: ubq323 <ubq323@ubq323.website>
Date: Sat, 22 Jun 2024 11:51:59 +0100
Subject: fix circular dependencies

---
 com.c |  8 ++++++++
 ht.h  |  1 -
 val.c |  4 ++++
 val.h | 13 +++++++++++--
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/com.c b/com.c
index 3e97c55..4f377ce 100644
--- a/com.c
+++ b/com.c
@@ -3,6 +3,10 @@
 #include <stdio.h>
 
 #include "com.h"
+#include "mem.h"
+#include "chunk.h"
+#include "ast.h"
+#include "read.h"
 
 #define BYTECODE(C) (C->ch->bc)
 
@@ -146,6 +150,10 @@ void arith_form(Compiler *C, AstVec l, Op op) {
 	chunk_wbc(C, op);
 }
 
+// void fn_form(Compiler *C, AstVec l, Op op) {
+// 	Compiler subcompiler = compiler_new(C);
+	
+
 static BuiltinForm builtin_forms[] = {
 	{ "puts",  1, false, single_form, OP_PUTS },
 	{ "print", 1, false, single_form, OP_PRINT },
diff --git a/ht.h b/ht.h
index 36a1d2a..656df73 100644
--- a/ht.h
+++ b/ht.h
@@ -2,7 +2,6 @@
 #define _ht_h
 
 typedef struct _ht Ht;
-typedef struct _state State;
 
 #include "val.h"
 
diff --git a/val.c b/val.c
index 8e351ff..ec3e636 100644
--- a/val.c
+++ b/val.c
@@ -64,6 +64,9 @@ void print_val(Val v) {
 		case OTY_STRING:
 			printf("%s", AS_CSTRING(v));
 			break;
+		case OTY_FUNC:
+			printf("[function Function]");
+			break;
 		}
 		break;
 	}
@@ -101,6 +104,7 @@ const char *typename_str(Val v) {
 	case TY_OBJ:
 		switch (AS_OBJ(v)->oty) {
 		case OTY_STRING: return "String";
+		case OTY_FUNC: return "Func";
 		}
 		break;
 	}
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) })
-- 
cgit v1.2.3