diff options
author | ubq323 <ubq323@ubq323.website> | 2024-06-22 11:51:59 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-06-22 11:51:59 +0100 |
commit | ba0eb2042cefce45efa5c1ad294f05d0122815ee (patch) | |
tree | 1bd6f747538b315e5091eea6a773b7401db16929 | |
parent | 24f5d4f4456fce3a9e8cd5a7c1225facd60ae979 (diff) |
fix circular dependencies
-rw-r--r-- | com.c | 8 | ||||
-rw-r--r-- | ht.h | 1 | ||||
-rw-r--r-- | val.c | 4 | ||||
-rw-r--r-- | val.h | 13 |
4 files changed, 23 insertions, 3 deletions
@@ -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 }, @@ -2,7 +2,6 @@ #define _ht_h typedef struct _ht Ht; -typedef struct _state State; #include "val.h" @@ -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; } @@ -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) }) |