- Added /mt blocks and /mt entities commands

- Further preparation of event manager for the event update
- Can now request all blocks and entities using the global game variable
- Improved automatic handling of version numbers
This commit is contained in:
Stan Hebben committed 2014-08-21 23:41:08 +02:00
1 parent b50a88227b
commit 56b8c9355c
81 files changed
+751 -506

No files matched your search

@@ -68,7 +68,7 @@ public class ZenModule {
fn.getName(),
fn.getSignature(),
fn.getArgumentTypes(),
fn.getReturnType()));
fn.getReturnType()), fn.getPosition());
}
}
@@ -89,7 +89,7 @@ public class ZenModule {
List<ParsedFunctionArgument> arguments = function.getValue().getArguments();
for (int i = 0; i < arguments.size(); i++) {
ParsedFunctionArgument argument = arguments.get(i);
methodEnvironment.putValue(argument.getName(), new SymbolArgument(i, argument.getType()));
methodEnvironment.putValue(argument.getName(), new SymbolArgument(i, argument.getType()), fn.getPosition());
}
methodOutput.start();
@@ -110,10 +110,10 @@ public class ZenParsedFile {
if (symbol == null) {
environmentScript.error(imprt.getPosition(), "Not a valid type");
} else {
environmentScript.putValue(imprt.getRename(), type.toSymbol());
environmentScript.putValue(imprt.getRename(), type.toSymbol(), imprt.getPosition());
}
} else {
environmentScript.putValue(imprt.getRename(), new SymbolType(ZenType.ANY));
environmentScript.putValue(imprt.getRename(), new SymbolType(ZenType.ANY), imprt.getPosition());
}
}
@@ -78,8 +78,12 @@ public class EnvironmentClass implements IEnvironmentClass {
}
@Override
public void putValue(String name, IZenSymbol value) {
local.put(name, value);
public void putValue(String name, IZenSymbol value, ZenPosition position) {
if (local.containsKey(name)) {
error(position, "Value already defined in this scope: " + name);
} else {
local.put(name, value);
}
}
@Override
@@ -97,9 +97,9 @@ public class EnvironmentGlobal implements IEnvironmentGlobal {
}
@Override
public void putValue(String name, IZenSymbol value) {
public void putValue(String name, IZenSymbol value, ZenPosition position) {
if (local.containsKey(name)) {
throw new RuntimeException("already exists");
error(position, "Value already defined in this scope: " + name);
} else {
local.put(name, value);
}
@@ -105,8 +105,12 @@ public class EnvironmentMethod implements IEnvironmentMethod {
}
@Override
public void putValue(String name, IZenSymbol value) {
local.put(name, value);
public void putValue(String name, IZenSymbol value, ZenPosition position) {
if (local.containsKey(name)) {
error(position, "Value already defined in this scope: " + name);
} else {
local.put(name, value);
}
}
@Override
@@ -94,8 +94,12 @@ public class EnvironmentScope implements IEnvironmentMethod {
}
@Override
public void putValue(String name, IZenSymbol value) {
local.put(name, value);
public void putValue(String name, IZenSymbol value, ZenPosition position) {
if (local.containsKey(name)) {
error(position, "Value already defined in this scope: " + name);
} else {
local.put(name, value);
}
}
@Override
@@ -67,10 +67,14 @@ public class EnvironmentScript implements IEnvironmentGlobal {
}
@Override
public void putValue(String name, IZenSymbol value) {
public void putValue(String name, IZenSymbol value, ZenPosition position) {
if (value == null) throw new IllegalArgumentException("value cannot be null");
imports.put(name, value);
if (imports.containsKey(name)) {
error(position, "Value already defined in this scope: " + name);
} else {
imports.put(name, value);
}
}
@Override
@@ -35,5 +35,5 @@ public interface IEnvironmentGlobal extends ITypeRegistry, IZenErrorLogger {
public IPartialExpression getValue(String name, ZenPosition position);
public void putValue(String name, IZenSymbol value);
public void putValue(String name, IZenSymbol value, ZenPosition position);
}
@@ -29,7 +29,7 @@ public abstract class Expression implements IPartialExpression {
}
public Expression cast(ZenPosition position, IEnvironmentGlobal environment, ZenType type) {
if (getType() == type) {
if (getType().equals(type)) {
return this;
} else {
ICastingRule castingRule = getType().getCastingRule(type, environment);
@@ -31,6 +31,7 @@ public class ExpressionInvalid extends Expression {
this.type = type;
// XXX: remove before release
//throw new RuntimeException("Constructing invalid expression");
}
@@ -81,7 +81,8 @@ public class ExpressionJavaLambda extends Expression {
for (int i = 0; i < arguments.size(); i++) {
environmentMethod.putValue(
arguments.get(i).getName(),
new SymbolArgument(i + 1, environment.getType(method.getGenericParameterTypes()[i])));
new SymbolArgument(i + 1, environment.getType(method.getGenericParameterTypes()[i])),
getPosition());
}
output.start();
@@ -6,6 +6,7 @@
package stanhebben.zenscript.parser.expression;
import java.util.Collections;
import java.util.List;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.expression.Expression;
@@ -60,6 +61,9 @@ public class ParsedExpressionArray extends ParsedExpression {
}
}
System.out.println("Predicted array base type " + (predictedBaseType == null ? "none" : predictedBaseType.getName()));
System.out.println("Contents are: " + contents);
Expression[] cContents = new Expression[contents.size()];
for (int i = 0; i < contents.size(); i++) {
cContents[i] = contents.get(i).compile(environment, predictedBaseType).eval(environment);
@@ -42,7 +42,7 @@ public class StatementForeach extends Statement {
int[] localVariables = new int[varnames.length];
for (int i = 0; i < localVariables.length; i++) {
SymbolLocal localVar = new SymbolLocal(iterator.getType(i), true);
local.putValue(varnames[i], localVar);
local.putValue(varnames[i], localVar, getPosition());
localVariables[i] = local.getLocal(localVar);
}
@@ -25,7 +25,10 @@ public class StatementIf extends Statement {
public void compile(IEnvironmentMethod environment) {
environment.getOutput().position(getPosition());
Expression cCondition = condition.compile(environment, ZenType.BOOL).eval(environment);
Expression cCondition = condition.compile(environment, ZenType.BOOL)
.eval(environment)
.cast(getPosition(), environment, ZenType.BOOL);
ZenType expressionType = cCondition.getType();
if (expressionType.canCastImplicit(ZenType.BOOL, environment)) {
Label labelEnd = new Label();
@@ -43,7 +43,7 @@ public class StatementVar extends Statement {
ZenType cType = type == null ? (cInitializer == null ? ZenTypeAny.INSTANCE : cInitializer.getType()) : type;
SymbolLocal symbol = new SymbolLocal(cType, isFinal);
environment.putValue(name, symbol);
environment.putValue(name, symbol, getPosition());
if (cInitializer != null) {
cInitializer.compile(true, environment);
@@ -243,7 +243,7 @@ public abstract class ZenType {
public ICastingRule getCastingRule(ZenType type, IEnvironmentGlobal environment) {
if (castingRules == null) {
castingRules = new HashMap<ZenType, ICastingRule>();
constructCastingRules(environment, new CastingRuleDelegateMap(castingRules), true);
constructCastingRules(environment, new CastingRuleDelegateMap(this, castingRules), true);
}
return castingRules.get(type);
@@ -395,4 +395,18 @@ public abstract class ZenType {
return false;
}
@Override
public int hashCode() {
return getName().hashCode();
}
@Override
public boolean equals(Object other) {
if (other instanceof ZenType) {
return getName().equals(((ZenType) other).getName());
} else {
return false;
}
}
}
@@ -151,7 +151,7 @@ public class ZenTypeBoolObject extends ZenType {
@Override
public String getName() {
return "bool";
return "bool?";
}
@Override
@@ -184,7 +184,7 @@ public class ZenTypeByteObject extends ZenType {
@Override
public String getName() {
return "byte";
return "byte?";
}
@Override
@@ -190,7 +190,7 @@ public class ZenTypeDoubleObject extends ZenType {
@Override
public String getName() {
return "double";
return "double?";
}
@Override
@@ -190,7 +190,7 @@ public class ZenTypeFloatObject extends ZenType {
@Override
public String getName() {
return "float";
return "float?";
}
@Override
@@ -190,7 +190,7 @@ public class ZenTypeIntObject extends ZenType {
@Override
public String getName() {
return "int";
return "int?";
}
@Override
@@ -44,6 +44,7 @@ import stanhebben.zenscript.expression.ExpressionInvalid;
import stanhebben.zenscript.expression.ExpressionNull;
import stanhebben.zenscript.expression.ExpressionString;
import stanhebben.zenscript.expression.partial.IPartialExpression;
import stanhebben.zenscript.type.casting.CastingNotNull;
import stanhebben.zenscript.type.casting.CastingRuleNone;
import stanhebben.zenscript.type.casting.CastingRuleNullableStaticMethod;
import stanhebben.zenscript.type.casting.ICastingRuleDelegate;
@@ -55,7 +56,6 @@ import stanhebben.zenscript.type.natives.JavaMethod;
import stanhebben.zenscript.type.natives.ZenNativeCaster;
import stanhebben.zenscript.type.natives.ZenNativeMember;
import stanhebben.zenscript.type.natives.ZenNativeOperator;
import stanhebben.zenscript.util.AnyClassWriter;
import static stanhebben.zenscript.util.AnyClassWriter.throwCastException;
import static stanhebben.zenscript.util.AnyClassWriter.throwUnsupportedException;
import stanhebben.zenscript.util.IAnyDefinition;
@@ -422,6 +422,7 @@ public class ZenTypeNative extends ZenType {
}
}
rules.registerCastingRule(BOOL, new CastingNotNull(this));
rules.registerCastingRule(ANY, new CastingRuleNullableStaticMethod(JavaMethod.getStatic(
getAnyClassName(environment),
"valueOf",
@@ -0,0 +1,48 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package stanhebben.zenscript.type.casting;
import org.objectweb.asm.Label;
import stanhebben.zenscript.compiler.IEnvironmentMethod;
import stanhebben.zenscript.type.ZenType;
import stanhebben.zenscript.util.MethodOutput;
/**
*
* @author Stan
*/
public class CastingNotNull implements ICastingRule {
public ZenType fromType;
public CastingNotNull(ZenType fromType) {
this.fromType = fromType;
}
@Override
public void compile(IEnvironmentMethod method) {
MethodOutput output = method.getOutput();
Label labelElse = new Label();
Label labelAfter = new Label();
output.ifNull(labelElse);
output.iConst1();
output.goTo(labelAfter);
output.label(labelElse);
output.iConst0();
output.label(labelAfter);
}
@Override
public ZenType getInputType() {
return fromType;
}
@Override
public ZenType getResultingType() {
return ZenType.BOOL;
}
}
@@ -14,14 +14,19 @@ import stanhebben.zenscript.type.ZenType;
* @author Stan
*/
public class CastingRuleDelegateMap implements ICastingRuleDelegate {
private final ZenType forType;
private final Map<ZenType, ICastingRule> target;
public CastingRuleDelegateMap(Map<ZenType, ICastingRule> target) {
public CastingRuleDelegateMap(ZenType forType, Map<ZenType, ICastingRule> target) {
this.forType = forType;
this.target = target;
}
@Override
public void registerCastingRule(ZenType type, ICastingRule rule) {
// XXX: remove before release
//System.out.println("Registering casting rule to convert " + forType + " to " + type + ": " + rule);
target.put(type, rule);
}
}
@@ -46,7 +46,7 @@ public class JavaMethod implements IJavaMethod {
}
public static IJavaMethod getStatic(String owner, String name, ZenType returnType, ZenType... arguments) {
return new JavaMethodGenerated(true, false, false, name, owner, returnType, arguments, new boolean[arguments.length]);
return new JavaMethodGenerated(true, false, false, owner, name, returnType, arguments, new boolean[arguments.length]);
}
public static IJavaMethod get(ITypeRegistry types, Method method) {