Eval: Add the corresponding named type to a struct Value.

This commit is contained in:
2023-03-22 00:14:24 +01:00
parent 534b507f7a
commit 9751a1da2f

View File

@@ -10,6 +10,8 @@ import de.hsrm.compiler.Klang.nodes.loops.DoWhileLoop;
import de.hsrm.compiler.Klang.nodes.loops.ForLoop;
import de.hsrm.compiler.Klang.nodes.loops.WhileLoop;
import de.hsrm.compiler.Klang.nodes.statements.*;
import de.hsrm.compiler.Klang.types.NamedType;
import de.hsrm.compiler.Klang.types.NullType;
import de.hsrm.compiler.Klang.types.Type;
public class EvalVisitor implements Visitor<Value> {
@@ -400,7 +402,7 @@ public class EvalVisitor implements Visitor<Value> {
@Override
public Value visit(Block e) {
for (var stmt : e.statements) {
Value result = stmt.welcome(this);
var result = stmt.welcome(this);
if (result != null) {
return result;
}
@@ -428,7 +430,7 @@ public class EvalVisitor implements Visitor<Value> {
this.env = newEnv;
// Execute
Value result = func.block.welcome(this);
var result = func.block.welcome(this);
// Das alte env wiederherstellen
this.env = oldEnv;
@@ -502,7 +504,10 @@ public class EvalVisitor implements Visitor<Value> {
struct.put(structDef.fields[i].name, arg);
}
return new Value(struct);
var structValue = new Value(struct);
structValue.type = structDef.type;
return structValue;
}
@Override