From e6f463257720bee91a1b4954d97684dbb3398cbf Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 6 Oct 2015 16:24:37 +0100 Subject: Add support for constructors and fields --- .../interpreter/values/ObjectInterpreterValue.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java') diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java index 4383353..acb6ef7 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/ObjectInterpreterValue.java @@ -1,14 +1,18 @@ package org.zwobble.couscous.interpreter.values; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import org.zwobble.couscous.values.PrimitiveValue; public class ObjectInterpreterValue implements InterpreterValue { private final ConcreteType type; + private final Map fields; public ObjectInterpreterValue(ConcreteType type) { this.type = type; + this.fields = new HashMap<>(); } @Override @@ -20,4 +24,17 @@ public class ObjectInterpreterValue implements InterpreterValue { public Optional toPrimitiveValue() { return Optional.empty(); } + + @Override + public InterpreterValue getField(String fieldName) { + if (fields.containsKey(fieldName)) { + return fields.get(fieldName); + } else { + throw new UnsupportedOperationException(); + } + } + + public void setField(String fieldName, InterpreterValue value) { + fields.put(fieldName, value); + } } -- cgit v1.2.3