diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-03-21 08:13:45 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-03-21 08:13:45 +0000 |
| commit | fe113241971cfe87b163a9eb4dc51e9d5e32410e (patch) | |
| tree | f9e435c44020ffbbb9231df79719a4d407ea8000 /src/main/java/org/zwobble/couscous/backends/python | |
| parent | 22f5765125eea28ae158bab4d9e96ae6472b73d4 (diff) | |
Move standard type definitions into a Types class
Diffstat (limited to 'src/main/java/org/zwobble/couscous/backends/python')
3 files changed, 11 insertions, 8 deletions
diff --git a/src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java b/src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java index 9e0a0b9..5b1691b 100644 --- a/src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java +++ b/src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java @@ -13,6 +13,7 @@ import org.zwobble.couscous.ast.visitors.NodeMapperWithDefault; import org.zwobble.couscous.ast.visitors.StatementNodeMapper; import org.zwobble.couscous.backends.Names; import org.zwobble.couscous.backends.python.ast.*; +import org.zwobble.couscous.types.Types; import org.zwobble.couscous.values.*; import java.util.*; @@ -113,7 +114,7 @@ public class PythonCodeGenerator { @Override public Stream<ScalarType> visit(TypeCoercionNode typeCoercion) { if (isIntegerBox(typeCoercion)) { - return Stream.of(ObjectValues.BOXED_INT); + return Stream.of(Types.BOXED_INT); } else { return Stream.empty(); } @@ -312,7 +313,7 @@ public class PythonCodeGenerator { if (isIntegerBox(typeCoercion)) { // TODO: perform this replacement at the start so that we don't split the import handling and actual expression return visit(ConstructorCallNode.constructorCall( - ObjectValues.BOXED_INT, + Types.BOXED_INT, list(typeCoercion.getExpression()))); } else if (isIntegerUnbox(typeCoercion)) { return pythonAttributeAccess(value, "_value"); @@ -353,7 +354,7 @@ public class PythonCodeGenerator { } private static boolean isInteger(Type type) { - return type.equals(IntegerValue.REF) || type.equals(ObjectValues.BOXED_INT); + return type.equals(Types.INT) || type.equals(Types.BOXED_INT); } private static PythonVariableReferenceNode typeReference(Type className) { diff --git a/src/main/java/org/zwobble/couscous/backends/python/PythonPrimitiveMethods.java b/src/main/java/org/zwobble/couscous/backends/python/PythonPrimitiveMethods.java index a290c54..40c794e 100644 --- a/src/main/java/org/zwobble/couscous/backends/python/PythonPrimitiveMethods.java +++ b/src/main/java/org/zwobble/couscous/backends/python/PythonPrimitiveMethods.java @@ -7,6 +7,7 @@ import org.zwobble.couscous.types.ScalarType; import org.zwobble.couscous.backends.python.ast.PythonBinaryOperation; import org.zwobble.couscous.backends.python.ast.PythonExpressionNode; import org.zwobble.couscous.backends.python.ast.PythonNotNode; +import org.zwobble.couscous.types.Types; import org.zwobble.couscous.values.*; import java.util.List; @@ -112,10 +113,10 @@ public class PythonPrimitiveMethods { private static final Map<ScalarType, Map<String, PrimitiveMethodGenerator>> METHODS = ImmutableMap.<ScalarType, Map<String, PrimitiveMethodGenerator>>builder() - .put(StringValue.REF, STRING_METHODS) - .put(BooleanValue.REF, BOOLEAN_METHODS) - .put(IntegerValue.REF, INT_METHODS) - .put(ObjectValues.BOXED_INT, INT_METHODS) + .put(Types.STRING, STRING_METHODS) + .put(Types.BOOLEAN, BOOLEAN_METHODS) + .put(Types.INT, INT_METHODS) + .put(Types.BOXED_INT, INT_METHODS) .build(); private static final Map<String, PrimitiveStaticMethodGenerator> INTERNAL_METHODS = @@ -135,7 +136,7 @@ public class PythonPrimitiveMethods { private static final Map<ScalarType, Map<String, PrimitiveStaticMethodGenerator>> STATIC_METHODS = ImmutableMap.<ScalarType, Map<String, PrimitiveStaticMethodGenerator>>builder() .put(InternalCouscousValue.REF, INTERNAL_METHODS) - .put(ObjectValues.BOXED_INT, BOXED_INT_STATIC_METHODS) + .put(Types.BOXED_INT, BOXED_INT_STATIC_METHODS) .build(); public static Optional<PrimitiveMethodGenerator> getPrimitiveMethod(ScalarType type, String methodName) { diff --git a/src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java b/src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java index 7732a87..89711a2 100644 --- a/src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java +++ b/src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java @@ -13,6 +13,7 @@ public class PythonSerializer implements PythonNodeVisitor { ); PythonSerializer serializer = new PythonSerializer(writer); serializer.write(node); + System.out.println(writer.asString()); return writer.asString(); } |
