From c1ee7d06ba4b7cc6171837aea36c864293a0737c Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 4 Feb 2023 14:25:39 +0200 Subject: [PATCH] LiteralValue, LiteralValueFloat - Made the `data` field `private` and now accessible through a call to `string getLiteralValue()` UnaryOpInstr - Use `Value` instead of `Instruction` for unary operator instructions DGen - Switched to using `getLiteralValue()` where required due to the aforementioned reasons --- source/tlang/compiler/codegen/emit/dgen.d | 3 ++- source/tlang/compiler/codegen/instruction.d | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/source/tlang/compiler/codegen/emit/dgen.d b/source/tlang/compiler/codegen/emit/dgen.d index 3c094e64..3e2132cc 100644 --- a/source/tlang/compiler/codegen/emit/dgen.d +++ b/source/tlang/compiler/codegen/emit/dgen.d @@ -170,6 +170,7 @@ public final class DCodeEmitter : CodeEmitter if(typedEntityVariable.getAssignment()) { Value varAssInstr = varDecInstr.getAssignmentInstr(); + gprintln("VarDec(with assignment): My assignment type is: "~varAssInstr.getInstrType().getName()); // Generate the code to emit return typeTransform(cast(Type)varDecInstr.varType)~" "~renamedSymbol~" = "~transform(varAssInstr)~";"; @@ -191,7 +192,7 @@ public final class DCodeEmitter : CodeEmitter LiteralValue literalValueInstr = cast(LiteralValue)instruction; - return to!(string)(literalValueInstr.data); + return to!(string)(literalValueInstr.getLiteralValue()); } /* FetchValueVar */ else if(cast(FetchValueVar)instruction) diff --git a/source/tlang/compiler/codegen/instruction.d b/source/tlang/compiler/codegen/instruction.d index b8fb872a..94f0b027 100644 --- a/source/tlang/compiler/codegen/instruction.d +++ b/source/tlang/compiler/codegen/instruction.d @@ -140,7 +140,7 @@ public final class FetchValueVar : Value public final class LiteralValue : Value { /* Data */ - public string data; + private string data; this(string data, Type type) { @@ -150,6 +150,11 @@ public final class LiteralValue : Value addInfo = "Data: "~to!(string)(data)~", Type: "~to!(string)(type); } + public string getLiteralValue() + { + return data; + } + public override string toString() { return produceToStrEnclose("Data: "~to!(string)(data)~", Type: "~to!(string)(type)); @@ -159,7 +164,7 @@ public final class LiteralValue : Value public final class LiteralValueFloat : Value { /* Data */ - public string data; /* TODO: Is this best way to store? Consirring floats/doubles */ + private string data; this(string data, Type type) { @@ -169,6 +174,11 @@ public final class LiteralValueFloat : Value addInfo = "Data: "~to!(string)(data)~", Type: "~to!(string)(type); } + public string getLiteralValue() + { + return data; + } + public override string toString() { return produceToStrEnclose("Data: "~to!(string)(data)~", Type: "~to!(string)(type)); @@ -252,10 +262,10 @@ public class BinOpInstr : Value */ public class UnaryOpInstr : Value { - private Instruction exp; + private Value exp; private SymbolType operator; - this(Instruction exp, SymbolType operator) + this(Value exp, SymbolType operator) { this.exp = exp; this.operator = operator; @@ -268,7 +278,7 @@ public class UnaryOpInstr : Value return operator; } - public Instruction getOperand() + public Value getOperand() { return exp; }