diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-30 08:32:41 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-30 08:32:41 +0200 |
commit | 85ee67a206a97954d69e50e962249b2d2e227b1b (patch) | |
tree | 4a03c75b794ab73203dcf9afeab13efc2be4913f /src | |
parent | 5f8aa9ed2eef33ca2f3a6f19b56588290ea74d2f (diff) | |
download | bdl-85ee67a206a97954d69e50e962249b2d2e227b1b.tar.gz bdl-85ee67a206a97954d69e50e962249b2d2e227b1b.zip |
Add compilation for set nodes
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler.c | 22 | ||||
-rw-r--r-- | src/semantic.c | 6 |
2 files changed, 28 insertions, 0 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; |