From 20dc1e124d606cf4298d5112b6d3c4f6c74e9b68 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 9 Mar 2016 18:11:17 +0000 Subject: Introduce Type interface --- .../org/zwobble/couscous/interpreter/Environment.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main/java/org/zwobble/couscous/interpreter/Environment.java') diff --git a/src/main/java/org/zwobble/couscous/interpreter/Environment.java b/src/main/java/org/zwobble/couscous/interpreter/Environment.java index daee3ed..fa5958b 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/Environment.java +++ b/src/main/java/org/zwobble/couscous/interpreter/Environment.java @@ -1,9 +1,10 @@ package org.zwobble.couscous.interpreter; -import org.zwobble.couscous.ast.TypeName; +import org.zwobble.couscous.ast.types.ScalarType; import org.zwobble.couscous.ast.VariableDeclaration; import org.zwobble.couscous.ast.VariableNode; import org.zwobble.couscous.ast.identifiers.Identifier; +import org.zwobble.couscous.ast.types.Type; import org.zwobble.couscous.interpreter.errors.UnboundVariable; import org.zwobble.couscous.interpreter.errors.VariableNotInScope; import org.zwobble.couscous.interpreter.values.InterpreterValue; @@ -16,7 +17,7 @@ import java.util.Optional; import static java.util.stream.Collectors.toMap; public class Environment { - private final Map types; + private final Map types; private final Optional thisValue; private final Map stackFrame; private final Project project; @@ -51,7 +52,7 @@ public class Environment { put(variable.getDeclaration().getId(), value); } - public StaticReceiverValue findClass(TypeName className) { + public StaticReceiverValue findClass(ScalarType className) { if (!types.containsKey(className)) { StaticReceiverValue value = new StaticReceiverValue(project.findClass(className)); types.put(className, value); @@ -71,24 +72,24 @@ public class Environment { } private void checkVariableType(Identifier variableId, InterpreterValue value) { - TypeName variableType = stackFrame.get(variableId).getType(); + Type variableType = stackFrame.get(variableId).getType(); InterpreterTypes.checkIsInstance(variableType, value); } private static class VariableEntry { - private final TypeName type; + private final Type type; private Optional value; - private VariableEntry(final TypeName type, final Optional value) { + private VariableEntry(final Type type, final Optional value) { this.type = type; this.value = value; } - public static VariableEntry of(final TypeName type, final Optional value) { + public static VariableEntry of(final Type type, final Optional value) { return new VariableEntry(type, value); } - public TypeName getType() { + public Type getType() { return this.type; } -- cgit v1.2.3