From 990f0ed1ccfa70bdb7873f925abdd2d16d6f03c3 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 13 Dec 2022 11:51:44 +0200 Subject: [PATCH] DGen - Implemented code emit for variable expressions (fetching their values) ---- Test cases - Updated test case `simple_variables.t` to be able to test the newly implemented `FetchValueInstr` code emit --- source/tlang/compiler/codegen/emit/dgen.d | 8 ++++++++ source/tlang/testing/simple_variables.t | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/source/tlang/compiler/codegen/emit/dgen.d b/source/tlang/compiler/codegen/emit/dgen.d index f9408a95..725a1dc1 100644 --- a/source/tlang/compiler/codegen/emit/dgen.d +++ b/source/tlang/compiler/codegen/emit/dgen.d @@ -113,7 +113,15 @@ public final class DCodeEmitter : CodeEmitter /* FetchValueVar */ else if(cast(FetchValueVar)instruction) { + FetchValueVar fetchValueVarInstr = cast(FetchValueVar)instruction; + Context context = fetchValueVarInstr.getContext(); + Variable typedEntityVariable = cast(Variable)context.tc.getResolver().resolveBest(context.getContainer(), fetchValueVarInstr.varName); //TODO: Remove `auto` + string typedEntityVariableName = context.tc.getResolver().generateName(context.getContainer(), typedEntityVariable); + + string renamedSymbol = SymbolMapper.symbolLookup(context.getContainer(), typedEntityVariableName); + + return renamedSymbol; } /* BinOpInstr */ else if(cast(BinOpInstr)instruction) diff --git a/source/tlang/testing/simple_variables.t b/source/tlang/testing/simple_variables.t index 0817fab0..89c76c61 100644 --- a/source/tlang/testing/simple_variables.t +++ b/source/tlang/testing/simple_variables.t @@ -2,7 +2,7 @@ module simple_variables_decls_ass; int x = 1+2*2/1-6; -int y = 2; +int y = 2+x; discard "TODO: Technically the below should not be allowed as we cannot do it in C - sadly"; y = 5+5;