mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 20:42:16 +00:00
- Rewrote the whole damn typecasting system. Now uses a more flexible and more structure casting rule system.
- Improved function literals. Function recipes are a thing! - Added mirrored shaped recipes - Fixed a few "any" type - related errors - Added environment to the bracket handlers. Breaks existing bracket handlers!! - Turned JavaMethod into an interface. Can now be used both for existing methods and generated ones. Makes a few things simpler :) - Added creative and adventure getters to player info
This commit is contained in:
1 parent
c67ad22270
commit
154c2242f9
172 files changed
+5400
-2134
No files matched your search
@@ -13,14 +13,14 @@ import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public abstract class Statement {
|
||||
public static Statement read(ZenTokener parser, IEnvironmentGlobal environment) {
|
||||
public static Statement read(ZenTokener parser, IEnvironmentGlobal environment, ZenType returnType) {
|
||||
Token next = parser.peek();
|
||||
switch (next.getType()) {
|
||||
case T_AOPEN: {
|
||||
Token t = parser.next();
|
||||
ArrayList<Statement> statements = new ArrayList<Statement>();
|
||||
while (parser.optional(T_ACLOSE) == null) {
|
||||
statements.add(read(parser, environment));
|
||||
statements.add(read(parser, environment, returnType));
|
||||
}
|
||||
return new StatementBlock(t.getPosition(), statements);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public abstract class Statement {
|
||||
parser.next();
|
||||
ParsedExpression expression = ParsedExpression.read(parser, environment);
|
||||
parser.required(T_SEMICOLON, "; expected");
|
||||
return new StatementReturn(next.getPosition(), expression);
|
||||
return new StatementReturn(next.getPosition(), returnType, expression);
|
||||
}
|
||||
case T_VAR:
|
||||
case T_VAL: {
|
||||
@@ -49,10 +49,10 @@ public abstract class Statement {
|
||||
case T_IF: {
|
||||
Token t = parser.next();
|
||||
ParsedExpression expression = ParsedExpression.read(parser, environment);
|
||||
Statement onIf = read(parser, environment);
|
||||
Statement onIf = read(parser, environment, returnType);
|
||||
Statement onElse = null;
|
||||
if (parser.optional(T_ELSE) != null) {
|
||||
onElse = read(parser, environment);
|
||||
onElse = read(parser, environment, returnType);
|
||||
}
|
||||
return new StatementIf(t.getPosition(), expression, onIf, onElse);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public abstract class Statement {
|
||||
|
||||
parser.required(T_IN, "in expected");
|
||||
ParsedExpression source = ParsedExpression.read(parser, environment);
|
||||
Statement content = read(parser, environment);
|
||||
Statement content = read(parser, environment, null);
|
||||
return new StatementForeach(
|
||||
t.getPosition(),
|
||||
names.toArray(new String[names.size()]),
|
||||
|
||||
@@ -16,7 +16,7 @@ public class StatementExpression extends Statement {
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
environment.getOutput().position(getPosition());
|
||||
expression.compile(environment)
|
||||
expression.compile(environment, null)
|
||||
.eval(environment)
|
||||
.compile(false, environment);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class StatementForeach extends Statement {
|
||||
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
Expression cList = list.compile(environment).eval(environment);
|
||||
Expression cList = list.compile(environment, ZenType.ANYARRAY).eval(environment);
|
||||
ZenType listType = cList.getType();
|
||||
|
||||
IZenIterator iterator = listType.makeIterator(varnames.length, environment);
|
||||
|
||||
@@ -5,7 +5,6 @@ import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.ZenTypeBool;
|
||||
import stanhebben.zenscript.util.MethodOutput;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
@@ -26,7 +25,7 @@ public class StatementIf extends Statement {
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
environment.getOutput().position(getPosition());
|
||||
|
||||
Expression cCondition = condition.compile(environment).eval(environment);
|
||||
Expression cCondition = condition.compile(environment, ZenType.BOOL).eval(environment);
|
||||
ZenType expressionType = cCondition.getType();
|
||||
if (expressionType.canCastImplicit(ZenType.BOOL, environment)) {
|
||||
Label labelEnd = new Label();
|
||||
|
||||
@@ -4,14 +4,17 @@ import org.objectweb.asm.Type;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public class StatementReturn extends Statement {
|
||||
private final ZenType returnType;
|
||||
private final ParsedExpression expression;
|
||||
|
||||
public StatementReturn(ZenPosition position, ParsedExpression expression) {
|
||||
public StatementReturn(ZenPosition position, ZenType returnType, ParsedExpression expression) {
|
||||
super(position);
|
||||
|
||||
this.returnType = returnType;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@@ -31,7 +34,7 @@ public class StatementReturn extends Statement {
|
||||
if (expression == null) {
|
||||
environment.getOutput().ret();
|
||||
} else {
|
||||
Expression cExpression = expression.compile(environment).eval(environment);
|
||||
Expression cExpression = expression.compile(environment, returnType).eval(environment);
|
||||
cExpression.compile(true, environment);
|
||||
|
||||
Type returnType = cExpression.getType().toASMType();
|
||||
|
||||
@@ -39,7 +39,7 @@ public class StatementVar extends Statement {
|
||||
|
||||
Expression cInitializer = initializer == null
|
||||
? null
|
||||
: initializer.compile(environment).eval(environment);
|
||||
: initializer.compile(environment, type).eval(environment);
|
||||
ZenType cType = type == null ? (cInitializer == null ? ZenTypeAny.INSTANCE : cInitializer.getType()) : type;
|
||||
SymbolLocal symbol = new SymbolLocal(cType, isFinal);
|
||||
|
||||
|
||||
Reference in new issue
Block a user