aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/interpreter
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-03-09 18:11:17 +0000
committerMichael Williamson <mike@zwobble.org>2016-03-09 18:11:17 +0000
commit20dc1e124d606cf4298d5112b6d3c4f6c74e9b68 (patch)
tree47914e8b0356b2f40e3723eae650d3bb6f100dd4 /src/main/java/org/zwobble/couscous/interpreter
parent8ac6cb16b727b5e3d28ab89fee1d169a4f74d9a1 (diff)
Introduce Type interface
Diffstat (limited to 'src/main/java/org/zwobble/couscous/interpreter')
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/Environment.java17
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/Evaluator.java9
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/Interpreter.java7
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/InterpreterTypes.java18
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java14
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/Project.java4
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/errors/InvalidCast.java12
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/errors/UnexpectedValueType.java12
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/types/InterpreterType.java6
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/types/IntrinsicInterpreterType.java33
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/types/UserDefinedInterpreterType.java12
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java2
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/values/Callable.java5
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/values/InterpreterValues.java4
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java8
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java8
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/values/TypeInterpreterValue.java8
17 files changed, 95 insertions, 84 deletions
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<TypeName, StaticReceiverValue> types;
+ private final Map<ScalarType, StaticReceiverValue> types;
private final Optional<InterpreterValue> thisValue;
private final Map<Identifier, VariableEntry> 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<InterpreterValue> value;
- private VariableEntry(final TypeName type, final Optional<InterpreterValue> value) {
+ private VariableEntry(final Type type, final Optional<InterpreterValue> value) {
this.type = type;
this.value = value;
}
- public static VariableEntry of(final TypeName type, final Optional<InterpreterValue> value) {
+ public static VariableEntry of(final Type type, final Optional<InterpreterValue> value) {
return new VariableEntry(type, value);
}
- public TypeName getType() {
+ public Type getType() {
return this.type;
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/Evaluator.java b/src/main/java/org/zwobble/couscous/interpreter/Evaluator.java
index 1d88c6b..37038ab 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/Evaluator.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/Evaluator.java
@@ -1,6 +1,7 @@
package org.zwobble.couscous.interpreter;
import org.zwobble.couscous.ast.*;
+import org.zwobble.couscous.ast.types.ScalarType;
import org.zwobble.couscous.ast.visitors.AssignableExpressionNodeVisitor;
import org.zwobble.couscous.ast.visitors.ExpressionNodeMapper;
import org.zwobble.couscous.interpreter.errors.ConditionMustBeBoolean;
@@ -12,6 +13,8 @@ import org.zwobble.couscous.values.IntegerValue;
import java.util.List;
import java.util.stream.Collectors;
+import static org.zwobble.couscous.ast.types.Types.erasure;
+
public class Evaluator implements ExpressionNodeMapper<InterpreterValue> {
public static InterpreterValue eval(Environment environment, ExpressionNode expression) {
return new Evaluator(environment).eval(expression);
@@ -93,7 +96,7 @@ public class Evaluator implements ExpressionNodeMapper<InterpreterValue> {
@Override
public InterpreterValue visit(ConstructorCallNode call) {
- StaticReceiverValue clazz = environment.findClass(call.getType());
+ StaticReceiverValue clazz = environment.findClass(erasure(call.getType()));
List<InterpreterValue> arguments = evalArguments(call.getArguments());
return clazz.callConstructor(environment, arguments);
}
@@ -127,7 +130,7 @@ public class Evaluator implements ExpressionNodeMapper<InterpreterValue> {
public InterpreterValue visit(CastNode cast) {
InterpreterValue value = eval(cast.getExpression());
if (!InterpreterTypes.isSubType(cast.getType(), value.getType())) {
- throw new InvalidCast(cast.getType(), value.getType().getName());
+ throw new InvalidCast(cast.getType(), value.getType().getType());
}
return value;
}
@@ -166,7 +169,7 @@ public class Evaluator implements ExpressionNodeMapper<InterpreterValue> {
}
@Override
- public ReceiverValue visit(TypeName receiver) {
+ public ReceiverValue visit(ScalarType receiver) {
return environment.findClass(receiver);
}
});
diff --git a/src/main/java/org/zwobble/couscous/interpreter/Interpreter.java b/src/main/java/org/zwobble/couscous/interpreter/Interpreter.java
index 8ec461a..fcf20d9 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/Interpreter.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/Interpreter.java
@@ -2,7 +2,8 @@ package org.zwobble.couscous.interpreter;
import com.google.common.collect.ImmutableMap;
import org.zwobble.couscous.ast.MethodSignature;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.ScalarType;
+import org.zwobble.couscous.ast.types.Type;
import org.zwobble.couscous.interpreter.values.InterpreterValue;
import org.zwobble.couscous.interpreter.values.StaticReceiverValue;
@@ -18,7 +19,7 @@ public class Interpreter {
this.project = project;
}
- public InterpreterValue run(TypeName className, String methodName, List<InterpreterValue> arguments, TypeName returnType) {
+ public InterpreterValue run(ScalarType className, String methodName, List<InterpreterValue> arguments, Type returnType) {
final Environment environment = new Environment(
project,
Optional.empty(),
@@ -27,7 +28,7 @@ public class Interpreter {
StaticReceiverValue clazz = environment.findClass(className);
MethodSignature signature = new MethodSignature(
methodName,
- eagerMap(arguments, argument -> argument.getType().getName()),
+ eagerMap(arguments, argument -> argument.getType().getType()),
returnType);
return clazz.callMethod(environment, signature, arguments);
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/InterpreterTypes.java b/src/main/java/org/zwobble/couscous/interpreter/InterpreterTypes.java
index b9221de..0ec63b0 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/InterpreterTypes.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/InterpreterTypes.java
@@ -1,26 +1,26 @@
package org.zwobble.couscous.interpreter;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.Type;
import org.zwobble.couscous.interpreter.errors.UnexpectedValueType;
import org.zwobble.couscous.interpreter.types.InterpreterType;
import org.zwobble.couscous.interpreter.values.InterpreterValue;
import org.zwobble.couscous.values.ObjectValues;
public class InterpreterTypes {
- public static void checkIsInstance(TypeName type, InterpreterValue value) {
+ public static void checkIsInstance(Type type, InterpreterValue value) {
checkIsSubType(type, value.getType());
}
- private static void checkIsSubType(TypeName superTypeName, InterpreterType subType) {
- if (!isSubType(superTypeName, subType)) {
- throw new UnexpectedValueType(superTypeName, subType.getName());
+ private static void checkIsSubType(Type superType, InterpreterType subType) {
+ if (!isSubType(superType, subType)) {
+ throw new UnexpectedValueType(superType, subType.getType());
}
}
- public static boolean isSubType(TypeName superTypeName, InterpreterType subType) {
+ public static boolean isSubType(Type superType, InterpreterType subType) {
return
- superTypeName.equals(subType.getName()) ||
- superTypeName.equals(ObjectValues.OBJECT) ||
- subType.getSuperTypes().contains(superTypeName);
+ superType.equals(subType.getType()) ||
+ superType.equals(ObjectValues.OBJECT) ||
+ subType.getSuperTypes().contains(superType);
}
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java b/src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java
index eca6ba9..ebc31ae 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/MapBackedProject.java
@@ -1,25 +1,27 @@
package org.zwobble.couscous.interpreter;
import com.google.common.collect.ImmutableMap;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.ScalarType;
import org.zwobble.couscous.interpreter.types.InterpreterType;
import java.util.Map;
+import static org.zwobble.couscous.ast.types.Types.erasure;
+
public class MapBackedProject implements Project {
public static Builder builder() {
return new Builder();
}
public static class Builder {
- private final ImmutableMap.Builder<TypeName, InterpreterType> classes;
+ private final ImmutableMap.Builder<ScalarType, InterpreterType> classes;
private Builder() {
classes = ImmutableMap.builder();
}
public Builder addClass(InterpreterType clazz) {
- classes.put(clazz.getName(), clazz);
+ classes.put(erasure(clazz.getType()), clazz);
return this;
}
@@ -35,14 +37,14 @@ public class MapBackedProject implements Project {
}
}
- private Map<TypeName, InterpreterType> classes;
+ private Map<ScalarType, InterpreterType> classes;
- public MapBackedProject(Map<TypeName, InterpreterType> classes) {
+ public MapBackedProject(Map<ScalarType, InterpreterType> classes) {
this.classes = classes;
}
@Override
- public InterpreterType findClass(TypeName name) {
+ public InterpreterType findClass(ScalarType name) {
if (classes.containsKey(name)) {
return classes.get(name);
} else {
diff --git a/src/main/java/org/zwobble/couscous/interpreter/Project.java b/src/main/java/org/zwobble/couscous/interpreter/Project.java
index 7e749b4..edfbaba 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/Project.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/Project.java
@@ -1,8 +1,8 @@
package org.zwobble.couscous.interpreter;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.ScalarType;
import org.zwobble.couscous.interpreter.types.InterpreterType;
public interface Project {
- InterpreterType findClass(TypeName name);
+ InterpreterType findClass(ScalarType name);
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/errors/InvalidCast.java b/src/main/java/org/zwobble/couscous/interpreter/errors/InvalidCast.java
index 2aef47b..a13612b 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/errors/InvalidCast.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/errors/InvalidCast.java
@@ -1,22 +1,22 @@
package org.zwobble.couscous.interpreter.errors;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.Type;
public class InvalidCast extends InterpreterException {
- private final TypeName expected;
- private final TypeName actual;
+ private final Type expected;
+ private final Type actual;
- public InvalidCast(TypeName expected, TypeName actual) {
+ public InvalidCast(Type expected, Type actual) {
this.expected = expected;
this.actual = actual;
}
- public TypeName getExpected() {
+ public Type getExpected() {
return expected;
}
- public TypeName getActual() {
+ public Type getActual() {
return actual;
}
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/errors/UnexpectedValueType.java b/src/main/java/org/zwobble/couscous/interpreter/errors/UnexpectedValueType.java
index ca40c7c..459d9d7 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/errors/UnexpectedValueType.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/errors/UnexpectedValueType.java
@@ -1,22 +1,22 @@
package org.zwobble.couscous.interpreter.errors;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.Type;
public final class UnexpectedValueType extends InterpreterException {
private static final long serialVersionUID = 1L;
- private final TypeName expected;
- private final TypeName actual;
+ private final Type expected;
+ private final Type actual;
- public UnexpectedValueType(final TypeName expected, final TypeName actual) {
+ public UnexpectedValueType(final Type expected, final Type actual) {
this.expected = expected;
this.actual = actual;
}
- public TypeName getExpected() {
+ public Type getExpected() {
return this.expected;
}
- public TypeName getActual() {
+ public Type getActual() {
return this.actual;
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/types/InterpreterType.java b/src/main/java/org/zwobble/couscous/interpreter/types/InterpreterType.java
index f5316ae..5ee1ae0 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/types/InterpreterType.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/types/InterpreterType.java
@@ -3,7 +3,7 @@ package org.zwobble.couscous.interpreter.types;
import org.zwobble.couscous.ast.FieldDeclarationNode;
import org.zwobble.couscous.ast.MethodSignature;
import org.zwobble.couscous.ast.StatementNode;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.Type;
import org.zwobble.couscous.interpreter.Environment;
import org.zwobble.couscous.interpreter.values.InterpreterValue;
@@ -12,8 +12,8 @@ import java.util.Optional;
import java.util.Set;
public interface InterpreterType {
- TypeName getName();
- Set<TypeName> getSuperTypes();
+ Type getType();
+ Set<Type> getSuperTypes();
Optional<FieldDeclarationNode> getField(String fieldName);
List<StatementNode> getStaticConstructor();
InterpreterValue callConstructor(Environment environment, List<InterpreterValue> arguments);
diff --git a/src/main/java/org/zwobble/couscous/interpreter/types/IntrinsicInterpreterType.java b/src/main/java/org/zwobble/couscous/interpreter/types/IntrinsicInterpreterType.java
index 5bfc221..96973cb 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/types/IntrinsicInterpreterType.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/types/IntrinsicInterpreterType.java
@@ -3,8 +3,9 @@ package org.zwobble.couscous.interpreter.types;
import com.google.common.collect.ImmutableMap;
import org.zwobble.couscous.ast.FieldDeclarationNode;
import org.zwobble.couscous.ast.MethodSignature;
+import org.zwobble.couscous.ast.types.ScalarType;
import org.zwobble.couscous.ast.StatementNode;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.Type;
import org.zwobble.couscous.interpreter.Environment;
import org.zwobble.couscous.interpreter.PositionalArguments;
import org.zwobble.couscous.interpreter.errors.NoSuchMethod;
@@ -21,12 +22,12 @@ import static org.zwobble.couscous.util.ExtraLists.list;
import static org.zwobble.couscous.util.ExtraSets.set;
public class IntrinsicInterpreterType implements InterpreterType {
- public static <T> Builder<T> builder(Class<T> interpreterValueType, TypeName reference) {
+ public static <T> Builder<T> builder(Class<T> interpreterValueType, ScalarType reference) {
return new Builder<>(interpreterValueType, reference);
}
public static <T> Builder<T> builder(Class<T> interpreterValueType, String name) {
- return builder(interpreterValueType, TypeName.of(name));
+ return builder(interpreterValueType, ScalarType.of(name));
}
public static Builder<ObjectInterpreterValue> classBuilder(String name) {
@@ -39,34 +40,34 @@ public class IntrinsicInterpreterType implements InterpreterType {
private final ImmutableMap.Builder<MethodSignature, MethodValue> methods = ImmutableMap.builder();
private final ImmutableMap.Builder<MethodSignature, StaticMethodValue> staticMethods = ImmutableMap.builder();
private final Class<T> interpreterValueType;
- private final TypeName name;
+ private final ScalarType name;
- public Builder(Class<T> interpreterValueType, TypeName name) {
+ public Builder(Class<T> interpreterValueType, ScalarType name) {
this.interpreterValueType = interpreterValueType;
this.name = name;
}
- public Builder<T> field(String name, TypeName type) {
+ public Builder<T> field(String name, ScalarType type) {
fields.put(name, FieldDeclarationNode.field(name, type));
return this;
}
- public Builder<T> constructor(List<TypeName> argumentsTypes, BiFunction<Environment, MethodCallArguments<T>, InterpreterValue> method) {
+ public Builder<T> constructor(List<Type> argumentsTypes, BiFunction<Environment, MethodCallArguments<T>, InterpreterValue> method) {
constructor = toMethodValue(argumentsTypes, method);
return this;
}
public Builder<T> method(
String name,
- List<TypeName> argumentsTypes,
- TypeName returnType,
+ List<Type> argumentsTypes,
+ Type returnType,
BiFunction<Environment, MethodCallArguments<T>, InterpreterValue> method)
{
methods.put(new MethodSignature(name, argumentsTypes, returnType), toMethodValue(argumentsTypes, method));
return this;
}
- private MethodValue toMethodValue(List<TypeName> argumentsTypes, BiFunction<Environment, MethodCallArguments<T>, InterpreterValue> method) {
+ private MethodValue toMethodValue(List<Type> argumentsTypes, BiFunction<Environment, MethodCallArguments<T>, InterpreterValue> method) {
return new MethodValue(
argumentsTypes,
(environment, arguments) ->
@@ -77,8 +78,8 @@ public class IntrinsicInterpreterType implements InterpreterType {
public Builder<T> staticMethod(
String name,
- List<TypeName> argumentsTypes,
- TypeName returnType,
+ List<Type> argumentsTypes,
+ Type returnType,
BiFunction<Environment, PositionalArguments, InterpreterValue> method)
{
staticMethods.put(new MethodSignature(name, argumentsTypes, returnType), new StaticMethodValue(argumentsTypes, method));
@@ -95,14 +96,14 @@ public class IntrinsicInterpreterType implements InterpreterType {
}
}
- private final TypeName name;
+ private final ScalarType name;
private final Map<String, FieldDeclarationNode> fields;
private final MethodValue constructor;
private final Map<MethodSignature, MethodValue> methods;
private final Map<MethodSignature, StaticMethodValue> staticMethods;
private IntrinsicInterpreterType(
- TypeName name,
+ ScalarType name,
Map<String, FieldDeclarationNode> fields,
MethodValue constructor,
Map<MethodSignature, MethodValue> methods,
@@ -116,12 +117,12 @@ public class IntrinsicInterpreterType implements InterpreterType {
}
@Override
- public TypeName getName() {
+ public ScalarType getType() {
return name;
}
@Override
- public Set<TypeName> getSuperTypes() {
+ public Set<Type> getSuperTypes() {
return set();
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/types/UserDefinedInterpreterType.java b/src/main/java/org/zwobble/couscous/interpreter/types/UserDefinedInterpreterType.java
index a253180..6d596ee 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/types/UserDefinedInterpreterType.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/types/UserDefinedInterpreterType.java
@@ -1,6 +1,8 @@
package org.zwobble.couscous.interpreter.types;
import org.zwobble.couscous.ast.*;
+import org.zwobble.couscous.ast.types.ScalarType;
+import org.zwobble.couscous.ast.types.Type;
import org.zwobble.couscous.interpreter.Environment;
import org.zwobble.couscous.interpreter.Executor;
import org.zwobble.couscous.interpreter.InterpreterTypes;
@@ -38,12 +40,12 @@ public class UserDefinedInterpreterType implements InterpreterType {
}
@Override
- public TypeName getName() {
+ public ScalarType getType() {
return type.getName();
}
@Override
- public Set<TypeName> getSuperTypes() {
+ public Set<Type> getSuperTypes() {
return type.getSuperTypes();
}
@@ -65,7 +67,7 @@ public class UserDefinedInterpreterType implements InterpreterType {
// TODO: add test for this case
.orElseThrow(() -> new RuntimeException("Cannot instantiate non-class types"))
.getConstructor();
- List<TypeName> formalArgumentTypes = eagerMap(
+ List<Type> formalArgumentTypes = eagerMap(
constructor.getArguments(),
FormalArgumentNode::getType);
checkMethodArguments(formalArgumentTypes, arguments);
@@ -78,12 +80,12 @@ public class UserDefinedInterpreterType implements InterpreterType {
return object;
}
- private static void checkMethodArguments(final List<TypeName> argumentTypes, List<InterpreterValue> arguments) {
+ private static void checkMethodArguments(final List<Type> argumentTypes, List<InterpreterValue> arguments) {
if (argumentTypes.size() != arguments.size()) {
throw new WrongNumberOfArguments(argumentTypes.size(), arguments.size());
}
for (int index = 0; index < arguments.size(); index++) {
- TypeName formalArgumentType = argumentTypes.get(index);
+ Type formalArgumentType = argumentTypes.get(index);
InterpreterTypes.checkIsInstance(formalArgumentType, arguments.get(index));
}
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java
index 5c477af..18d0c34 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/values/BoxedIntegerInterpreterValue.java
@@ -38,7 +38,7 @@ public class BoxedIntegerInterpreterValue {
.method("equals", list(ObjectValues.OBJECT), BooleanValue.REF,
(environment, arguments) -> {
InterpreterValue right = arguments.getPositionalArguments().get(0);
- if (right.getType().getName().equals(ObjectValues.BOXED_INT)) {
+ if (right.getType().getType().equals(ObjectValues.BOXED_INT)) {
IntegerInterpreterValue leftValue = (IntegerInterpreterValue)arguments.getReceiver().getField("value");
IntegerInterpreterValue rightValue = (IntegerInterpreterValue)right.getField("value");
return BooleanInterpreterValue.of(leftValue.getValue() == rightValue.getValue());
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/Callable.java b/src/main/java/org/zwobble/couscous/interpreter/values/Callable.java
index f96ba9a..c296797 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/values/Callable.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/values/Callable.java
@@ -2,8 +2,9 @@ package org.zwobble.couscous.interpreter.values;
import java.util.List;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.ScalarType;
+import org.zwobble.couscous.ast.types.Type;
public interface Callable {
- List<TypeName> getArgumentTypes();
+ List<Type> getArgumentTypes();
}
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterValues.java b/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterValues.java
index 4e8f1e6..3841d7c 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterValues.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterValues.java
@@ -1,6 +1,6 @@
package org.zwobble.couscous.interpreter.values;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.ScalarType;
import org.zwobble.couscous.values.PrimitiveValue;
import org.zwobble.couscous.values.PrimitiveValueVisitor;
@@ -40,7 +40,7 @@ public class InterpreterValues {
}
@Override
- public InterpreterValue visitType(TypeName value) {
+ public InterpreterValue visitType(ScalarType value) {
return TypeInterpreterValue.of(value);
}
});
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java
index 01b2f35..eeda6f4 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/values/MethodValue.java
@@ -1,25 +1,25 @@
package org.zwobble.couscous.interpreter.values;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.Type;
import org.zwobble.couscous.interpreter.Environment;
import java.util.List;
import java.util.function.BiFunction;
public final class MethodValue implements Callable {
- private final List<TypeName> argumentTypes;
+ private final List<Type> argumentTypes;
private final BiFunction<Environment, MethodCallArguments<InterpreterValue>, InterpreterValue> apply;
public InterpreterValue apply(Environment environment, MethodCallArguments<InterpreterValue> arguments) {
return apply.apply(environment, arguments);
}
- public MethodValue(final List<TypeName> argumentTypes, final BiFunction<Environment, MethodCallArguments<InterpreterValue>, InterpreterValue> apply) {
+ public MethodValue(final List<Type> argumentTypes, final BiFunction<Environment, MethodCallArguments<InterpreterValue>, InterpreterValue> apply) {
this.argumentTypes = argumentTypes;
this.apply = apply;
}
- public List<TypeName> getArgumentTypes() {
+ public List<Type> getArgumentTypes() {
return this.argumentTypes;
}
} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java
index fabf1ad..e8223ac 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/values/StaticMethodValue.java
@@ -1,6 +1,6 @@
package org.zwobble.couscous.interpreter.values;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.Type;
import org.zwobble.couscous.interpreter.Environment;
import org.zwobble.couscous.interpreter.PositionalArguments;
@@ -8,19 +8,19 @@ import java.util.List;
import java.util.function.BiFunction;
public final class StaticMethodValue implements Callable {
- private final List<TypeName> argumentTypes;
+ private final List<Type> argumentTypes;
private final BiFunction<Environment, PositionalArguments, InterpreterValue> apply;
public InterpreterValue apply(Environment environment, PositionalArguments arguments) {
return apply.apply(environment, arguments);
}
- public StaticMethodValue(final List<TypeName> argumentTypes, final BiFunction<Environment, PositionalArguments, InterpreterValue> apply) {
+ public StaticMethodValue(final List<Type> argumentTypes, final BiFunction<Environment, PositionalArguments, InterpreterValue> apply) {
this.argumentTypes = argumentTypes;
this.apply = apply;
}
- public List<TypeName> getArgumentTypes() {
+ public List<Type> getArgumentTypes() {
return this.argumentTypes;
}
} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/TypeInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/TypeInterpreterValue.java
index f221ea0..a4efddb 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/values/TypeInterpreterValue.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/values/TypeInterpreterValue.java
@@ -1,6 +1,6 @@
package org.zwobble.couscous.interpreter.values;
-import org.zwobble.couscous.ast.TypeName;
+import org.zwobble.couscous.ast.types.ScalarType;
import org.zwobble.couscous.interpreter.errors.NoSuchField;
import org.zwobble.couscous.interpreter.types.InterpreterType;
import org.zwobble.couscous.interpreter.types.IntrinsicInterpreterType;
@@ -15,13 +15,13 @@ public class TypeInterpreterValue implements InterpreterValue {
.builder(TypeInterpreterValue.class, ObjectValues.CLASS)
.build();
- public static InterpreterValue of(TypeName type) {
+ public static InterpreterValue of(ScalarType type) {
return new TypeInterpreterValue(type);
}
- private final TypeName type;
+ private final ScalarType type;
- public TypeInterpreterValue(TypeName type) {
+ public TypeInterpreterValue(ScalarType type) {
this.type = type;
}