- Basic types can now be converted to the "any" type

- Changed OreDict 'contains' to respond to the 'in' operator
This commit is contained in:
Stan Hebben committed 2014-07-20 21:30:40 +02:00
1 parent 52f92dcfd4
commit 1b72abb2b4
59 files changed
+3595 -976

No files matched your search

@@ -33,18 +33,15 @@ public abstract class Expression implements IPartialExpression {
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
if (getType() == type) {
return this;
} else if (getType().canCastImplicit(type, environment)) {
return new ExpressionAs(position, this, type);
} else {
environment.error(position, "Cannot cast " + getType() + " to " + type);
return new ExpressionInvalid(position, type);
return getType().cast(position, environment, this, type);
}
}
public abstract void compile(boolean result, IEnvironmentMethod environment);
public void compileIf(Label onElse, IEnvironmentMethod environment) {
if (getType() == ZenTypeBool.INSTANCE) {
if (getType() == ZenType.BOOL) {
compile(true, environment);
environment.getOutput().ifEQ(onElse);
} else if (getType().isPointer()) {
@@ -50,7 +50,7 @@ public class ExpressionArithmeticBinary extends Expression {
ZenType type = a.getType();
MethodOutput output = environment.getOutput();
if (type == ZenTypeBool.INSTANCE) {
if (type == ZenType.BOOL) {
switch (operator) {
case AND:
output.iAnd();
@@ -29,7 +29,7 @@ public class ExpressionArithmeticCompare extends Expression {
@Override
public ZenType getType() {
return ZenTypeBool.INSTANCE;
return ZenType.BOOL;
}
@Override
@@ -39,7 +39,7 @@ public class ExpressionArithmeticCompare extends Expression {
if (result) {
MethodOutput output = environment.getOutput();
if (a.getType() == ZenTypeBool.INSTANCE) {
if (a.getType() == ZenType.BOOL) {
if (type == CompareType.EQ) {
Label onThen = new Label();
Label onEnd = new Label();
@@ -36,7 +36,7 @@ public class ExpressionArithmeticUnary extends Expression {
MethodOutput output = environment.getOutput();
if (result) {
ZenType type = base.getType();
if (type == ZenTypeBool.INSTANCE) {
if (type == ZenType.BOOL) {
if (operator == OperatorType.NOT) {
output.iNot();
return;
@@ -18,10 +18,7 @@ public class ExpressionAs extends Expression {
@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
if (!this.type.canCastExplicit(type, environment)) {
environment.error(position, "cannot cast " + this.type + " to " + type);
}
return new ExpressionAs(getPosition(), this, type);
return this.type.cast(position, environment, this, type);
}
@Override
@@ -7,12 +7,9 @@
package stanhebben.zenscript.expression;
import org.objectweb.asm.Label;
import stanhebben.zenscript.compiler.EnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.compiler.EnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.type.ZenTypeBool;
import stanhebben.zenscript.util.ZenPosition;
/**
@@ -30,25 +27,22 @@ public class ExpressionBool extends Expression {
@Override
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
if (type == ZenTypeBool.INSTANCE) {
if (type == ZenType.BOOL) {
return this;
} else if (type.canCastExplicit(type, environment)) {
return new ExpressionAs(position, this, type);
} else {
environment.error(position, "Cannot cast a bool constant to " + type.toString());
return new ExpressionInvalid(position, type);
return ZenType.BOOL.cast(position, environment, this, type);
}
}
@Override
public Expression getMember(ZenPosition position, IEnvironmentGlobal environment, String name) {
environment.error(position, "Bool constants do not have members");
return new ExpressionInvalid(position, ZenTypeBool.INSTANCE);
return new ExpressionInvalid(position, ZenType.BOOL);
}
@Override
public ZenType getType() {
return ZenTypeBool.INSTANCE;
return ZenType.BOOL;
}
@Override
@@ -31,7 +31,7 @@ public class ExpressionCompareGeneric extends Expression {
@Override
public ZenType getType() {
return ZenTypeBool.INSTANCE;
return ZenType.BOOL;
}
@Override
@@ -41,7 +41,7 @@ public class ExpressionFloat extends Expression {
} else if (type == ZenTypeDouble.INSTANCE) {
environment.getOutput().constant(value);
} else {
// TODO: internal error
throw new RuntimeException("Internal compiler error: source type is not a floating point type");
}
}
}
@@ -68,7 +68,7 @@ public class ExpressionInt extends Expression {
} else if (type == ZenTypeLong.INSTANCE) {
output.constant(value);
} else {
// TODO: internal error
throw new RuntimeException("Internal compiler error: int constant type is not an int");
}
}
}
@@ -30,7 +30,7 @@ public class ExpressionMapContains extends Expression {
@Override
public ZenType getType() {
return ZenTypeBool.INSTANCE;
return ZenType.BOOL;
}
@Override