mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-21 20:42:16 +00:00
Added projects and basic build scripts. Project for scripting engine, API, Main 1.7 version and one for each mod supported in 1.7.
This commit is contained in:
1 parent
219106f392
commit
38b78ce305
281 files changed
+25090
-49
No files matched your search
@@ -0,0 +1,110 @@
|
||||
package stanhebben.zenscript.statements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import stanhebben.zenscript.ZenParser;
|
||||
import static stanhebben.zenscript.ZenParser.*;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentGlobal;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.parser.Token;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public abstract class Statement {
|
||||
public static Statement read(ZenParser parser, IEnvironmentGlobal environment) {
|
||||
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));
|
||||
}
|
||||
return new StatementBlock(t.getPosition(), statements);
|
||||
}
|
||||
case T_RETURN: {
|
||||
parser.next();
|
||||
ParsedExpression expression = ParsedExpression.read(parser, environment);
|
||||
parser.required(T_SEMICOLON, "; expected");
|
||||
return new StatementReturn(next.getPosition(), expression);
|
||||
}
|
||||
case T_VAR:
|
||||
case T_VAL: {
|
||||
Token start = parser.next();
|
||||
String name = parser.required(T_ID, "identifier expected").getValue();
|
||||
|
||||
ZenType type = null;
|
||||
ParsedExpression initializer = null;
|
||||
if (parser.optional(T_AS) != null) {
|
||||
type = ZenType.read(parser, environment);
|
||||
}
|
||||
if (parser.optional(T_ASSIGN) != null) {
|
||||
initializer = ParsedExpression.read(parser, environment);
|
||||
}
|
||||
parser.required(T_SEMICOLON, "; expected");
|
||||
return new StatementVar(start.getPosition(), name, type, initializer, start.getType() == T_VAL);
|
||||
}
|
||||
case T_IF: {
|
||||
Token t = parser.next();
|
||||
ParsedExpression expression = ParsedExpression.read(parser, environment);
|
||||
Statement onIf = read(parser, environment);
|
||||
Statement onElse = null;
|
||||
if (parser.optional(T_ELSE) != null) {
|
||||
onElse = read(parser, environment);
|
||||
}
|
||||
return new StatementIf(t.getPosition(), expression, onIf, onElse);
|
||||
}
|
||||
case T_FOR: {
|
||||
Token t = parser.next();
|
||||
String name = parser.required(T_ID, "identifier expected").getValue();
|
||||
List<String> names = new ArrayList<String>();
|
||||
names.add(name);
|
||||
|
||||
while (parser.optional(T_COMMA) != null) {
|
||||
names.add(parser.required(T_ID, "identifier expected").getValue());
|
||||
}
|
||||
|
||||
parser.required(T_COLON, ": expected");
|
||||
ParsedExpression source = ParsedExpression.read(parser, environment);
|
||||
Statement content = read(parser, environment);
|
||||
return new StatementForeach(
|
||||
t.getPosition(),
|
||||
names.toArray(new String[names.size()]),
|
||||
source,
|
||||
content);
|
||||
}
|
||||
case T_VERSION: {
|
||||
Token t = parser.next();
|
||||
parser.required(T_INTVALUE, "integer expected");
|
||||
|
||||
//MineTweaker.logWarning("The version statement is no longer necessary");
|
||||
|
||||
parser.required(T_SEMICOLON, "; expected");
|
||||
return new StatementNull(t.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
ZenPosition position = parser.peek().getPosition();
|
||||
StatementExpression result = new StatementExpression(position, ParsedExpression.read(parser, environment));
|
||||
parser.required(T_SEMICOLON, "; expected");
|
||||
return result;
|
||||
}
|
||||
|
||||
private final ZenPosition position;
|
||||
|
||||
public Statement(ZenPosition position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public ZenPosition getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public boolean isReturn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract void compile(IEnvironmentMethod environment);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package stanhebben.zenscript.statements;
|
||||
|
||||
import java.util.List;
|
||||
import stanhebben.zenscript.compiler.EnvironmentScope;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public class StatementBlock extends Statement {
|
||||
private final List<Statement> statements;
|
||||
|
||||
public StatementBlock(ZenPosition position, List<Statement> statements) {
|
||||
super(position);
|
||||
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
IEnvironmentMethod local = new EnvironmentScope(environment);
|
||||
for (Statement statement : statements) {
|
||||
statement.compile(local);
|
||||
if (statement.isReturn()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package stanhebben.zenscript.statements;
|
||||
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public class StatementExpression extends Statement {
|
||||
private final ParsedExpression expression;
|
||||
|
||||
public StatementExpression(ZenPosition position, ParsedExpression expression) {
|
||||
super(position);
|
||||
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
environment.getOutput().position(getPosition());
|
||||
expression.compile(environment)
|
||||
.eval(environment)
|
||||
.compile(false, environment);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package stanhebben.zenscript.statements;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
import stanhebben.zenscript.compiler.EnvironmentScope;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.type.IZenIterator;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.symbols.SymbolLocal;
|
||||
import stanhebben.zenscript.util.MethodOutput;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public class StatementForeach extends Statement {
|
||||
private final String[] varnames;
|
||||
private final ParsedExpression list;
|
||||
private final Statement body;
|
||||
|
||||
public StatementForeach(ZenPosition position, String[] varnames, ParsedExpression list, Statement body) {
|
||||
super(position);
|
||||
|
||||
this.varnames = varnames;
|
||||
this.list = list;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
Expression cList = list.compile(environment).eval(environment);
|
||||
ZenType listType = cList.getType();
|
||||
|
||||
IZenIterator iterator = listType.makeIterator(varnames.length, environment);
|
||||
if (iterator == null) {
|
||||
environment.error(getPosition(), "No iterator with " + varnames.length + " variables");
|
||||
return;
|
||||
}
|
||||
|
||||
MethodOutput methodOutput = environment.getOutput();
|
||||
environment.getOutput().position(getPosition());
|
||||
|
||||
IEnvironmentMethod local = new EnvironmentScope(environment);
|
||||
int[] localVariables = new int[varnames.length];
|
||||
for (int i = 0; i < localVariables.length; i++) {
|
||||
localVariables[i] = methodOutput.local(iterator.getType(i).toASMType());
|
||||
local.putValue(varnames[i], new SymbolLocal(iterator.getType(i), true));
|
||||
}
|
||||
|
||||
cList.compile(true, environment);
|
||||
iterator.compileStart(localVariables);
|
||||
|
||||
Label repeat = new Label();
|
||||
Label exit = new Label();
|
||||
|
||||
methodOutput.label(repeat);
|
||||
iterator.compilePreIterate(localVariables, exit);
|
||||
body.compile(local);
|
||||
iterator.compilePostIterate(localVariables, exit, repeat);
|
||||
methodOutput.label(exit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package stanhebben.zenscript.statements;
|
||||
|
||||
import org.objectweb.asm.Label;
|
||||
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.symbols.IZenNamespace;
|
||||
import stanhebben.zenscript.util.MethodOutput;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public class StatementIf extends Statement {
|
||||
private final ParsedExpression condition;
|
||||
private final Statement onThen;
|
||||
private final Statement onElse;
|
||||
|
||||
public StatementIf(ZenPosition position, ParsedExpression condition, Statement onThen, Statement onElse) {
|
||||
super(position);
|
||||
|
||||
this.condition = condition;
|
||||
this.onThen = onThen;
|
||||
this.onElse = onElse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
environment.getOutput().position(getPosition());
|
||||
|
||||
Expression cCondition = condition.compile(environment).eval(environment);
|
||||
ZenType expressionType = cCondition.getType();
|
||||
if (expressionType.canCastImplicit(ZenTypeBool.INSTANCE, environment)) {
|
||||
Label labelEnd = new Label();
|
||||
Label labelElse = onElse == null ? labelEnd : new Label();
|
||||
|
||||
cCondition.compileIf(labelElse, environment);
|
||||
onThen.compile(environment);
|
||||
|
||||
MethodOutput methodOutput = environment.getOutput();
|
||||
if (onElse != null) {
|
||||
methodOutput.goTo(labelEnd);
|
||||
methodOutput.label(labelElse);
|
||||
onElse.compile(environment);
|
||||
}
|
||||
|
||||
methodOutput.label(labelEnd);
|
||||
} else {
|
||||
environment.error(getPosition(), "condition is not a boolean");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.statements;
|
||||
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class StatementNull extends Statement {
|
||||
public StatementNull(ZenPosition position) {
|
||||
super(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package stanhebben.zenscript.statements;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
public class StatementReturn extends Statement {
|
||||
private final ParsedExpression expression;
|
||||
|
||||
public StatementReturn(ZenPosition position, ParsedExpression expression) {
|
||||
super(position);
|
||||
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public ParsedExpression getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReturn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
environment.getOutput().position(getPosition());
|
||||
|
||||
if (expression == null) {
|
||||
environment.getOutput().ret();
|
||||
} else {
|
||||
Expression cExpression = expression.compile(environment).eval(environment);
|
||||
cExpression.compile(true, environment);
|
||||
|
||||
Type returnType = cExpression.getType().toASMType();
|
||||
environment.getOutput().returnType(returnType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.statements;
|
||||
|
||||
import stanhebben.zenscript.compiler.IEnvironmentMethod;
|
||||
import stanhebben.zenscript.expression.Expression;
|
||||
import stanhebben.zenscript.parser.expression.ParsedExpression;
|
||||
import stanhebben.zenscript.symbols.SymbolLocal;
|
||||
import stanhebben.zenscript.type.ZenType;
|
||||
import stanhebben.zenscript.type.ZenTypeAny;
|
||||
import stanhebben.zenscript.util.ZenPosition;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stanneke
|
||||
*/
|
||||
public class StatementVar extends Statement {
|
||||
private final String name;
|
||||
private final ZenType type;
|
||||
private final ParsedExpression initializer;
|
||||
private final boolean isFinal;
|
||||
|
||||
public StatementVar(ZenPosition position, String name, ZenType type, ParsedExpression initializer, boolean isFinal) {
|
||||
super(position);
|
||||
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.initializer = initializer;
|
||||
this.isFinal = isFinal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compile(IEnvironmentMethod environment) {
|
||||
environment.getOutput().position(getPosition());
|
||||
|
||||
Expression cInitializer = initializer == null
|
||||
? null
|
||||
: initializer.compile(environment).eval(environment);
|
||||
ZenType cType = type == null ? (cInitializer == null ? ZenTypeAny.INSTANCE : cInitializer.getType()) : type;
|
||||
SymbolLocal symbol = new SymbolLocal(cType, isFinal);
|
||||
|
||||
environment.putValue(name, symbol);
|
||||
|
||||
if (cInitializer != null) {
|
||||
cInitializer.compile(true, environment);
|
||||
environment.getOutput().store(symbol.getType().toASMType(), environment.getLocal(symbol));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user