summaryrefslogtreecommitdiff
path: root/com.c
diff options
context:
space:
mode:
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);