aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/compiler.c22
-rw-r--r--src/semantic.c6
-rw-r--r--tests/compilation.bad26
3 files changed, 42 insertions, 12 deletions
diff --git a/src/compiler.c b/src/compiler.c
index f46d00d..0f9607e 100644
--- a/src/compiler.c
+++ b/src/compiler.c
@@ -652,6 +652,28 @@ compile_expr(Chunk *chunk, Node *node) {
652 652
653 return (CompResult){.type = COMP_NIL}; 653 return (CompResult){.type = COMP_NIL};
654 } break; 654 } break;
655 case NODE_SET: {
656 Str name = node->unique_name;
657 StrVarMap *map = varmap_lookup(&chunk->varmap, name);
658 if (!map) {
659 println("you wot mate?: %s", name);
660 }
661 CompResult res = compile_expr(chunk, node->var_val);
662 switch (res.type) {
663 case COMP_CONST: {
664 EMIT_OP(OP_STGVARI, map->val.idx, res.idx, 0, node->var_val,
665 chunk);
666 } break;
667 case COMP_REG: {
668 EMIT_OP(OP_STGVAR, map->val.idx, res.idx, 0, node->var_val,
669 chunk);
670 } break;
671 default: {
672 return (CompResult){.type = COMP_ERR};
673 } break;
674 }
675 return (CompResult){.type = COMP_NIL};
676 } break;
655 case NODE_SYMBOL: { 677 case NODE_SYMBOL: {
656 Str name = node->unique_name; 678 Str name = node->unique_name;
657 StrVarMap *map = varmap_lookup(&chunk->varmap, name); 679 StrVarMap *map = varmap_lookup(&chunk->varmap, name);
diff --git a/src/semantic.c b/src/semantic.c
index d782cac..9b119df 100644
--- a/src/semantic.c
+++ b/src/semantic.c
@@ -550,6 +550,12 @@ type_inference(Analyzer *a, Node *node, Scope *scope) {
550 a->err = true; 550 a->err = true;
551 return cstr(""); 551 return cstr("");
552 } 552 }
553 Str symbol = node->var_name->value.str;
554 FindSymbolResult sym = find_symbol(scope, symbol);
555 node->unique_name = str_concat(cstr("."), symbol, a->storage);
556 node->unique_name =
557 str_concat(node->unique_name,
558 str_from_int(sym.scope->id, a->storage), a->storage);
553 node->type = cstr("nil"); 559 node->type = cstr("nil");
554 return node->type; 560 return node->type;
555 } break; 561 } break;
diff --git a/tests/compilation.bad b/tests/compilation.bad
index 4b25a76..afb2be0 100644
--- a/tests/compilation.bad
+++ b/tests/compilation.bad
@@ -7,19 +7,21 @@
7 7
8; a + b + c 8; a + b + c
9 9
10if true { 10; if true {
11 2 11; 2
12} 12; }
13 13
14if true { 14; if true {
15 1 + 2 15; 1 + 2
16; } else {
17; 3 + 4
18; }
19
20let a = 0
21if 1 != 1 {
22 set a = 1
16} else { 23} else {
17 3 + 4 24 set a = 2
18} 25}
19 26
20; let a = 0 27a
21; if 1 != 1 {
22; set a = 1
23; } else {
24; set a = 2
25; }