summaryrefslogtreecommitdiff
path: root/com.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-20 18:11:09 +0100
committerubq323 <ubq323@ubq323.website>2024-06-20 18:11:09 +0100
commit600eaef90f9f0507635fec4cf98f7fa1d1779bd1 (patch)
treed057e694a4b9a6a0109523f61ad788a125a7f479 /com.c
parentb8d0ee2e105727021f9466790ec07ecbfee8dff6 (diff)
add readable globals
Diffstat (limited to 'com.c')
-rw-r--r--com.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/com.c b/com.c
index b97ffc0..ba45975 100644
--- a/com.c
+++ b/com.c
@@ -9,9 +9,11 @@
static void compile_node(State *S, Chunk *ch, AstNode a) {
switch (a.ty) {
- case AST_IDENT:
- printf("can't compile ident\n");
- exit(1);
+ case AST_IDENT:;
+ size_t len = strlen(a.as.str);
+ ObjString *o = objstring_copy(S, a.as.str, len);
+ chunk_wbc(S, ch, OP_GETGLOBAL);
+ chunk_wbc(S, ch, chunk_wconst(S, ch, VAL_OBJ(o)));
break;
case AST_NUM:
chunk_wbc(S, ch, OP_LOADK);
@@ -67,6 +69,17 @@ int main() {
Chunk ch = chunk_new(S);
th.ch = &ch;
+ char n1[] = "foo";
+ char n2[] = "bar";
+ char n3[] = "baz";
+ ObjString *o1 = objstring_copy(S, n1, 3);
+ ObjString *o2 = objstring_copy(S, n2, 3);
+ ObjString *o3 = objstring_copy(S, n3, 3);
+
+ ht_put(S, &st.globals, o1, VAL_NUM(69));
+ ht_put(S, &st.globals, o2, VAL_NUM(2));
+ ht_put(S, &st.globals, o3, VAL_NUM(3));
+
AstNode an = read();
compile_node(S, &ch, an);