mirror of
https://github.com/GTNewHorizons/CraftTweaker.git
synced 2026-11-18 03:15:14 +00:00
Tons of changes:
- Added interface to game, client and server - Added transformations - Made ingredient conditions more practical to use, no longer requires imports - Started implementation of event handling - Moved commands and logic to the common API code - Added common interface to MineTweaker recipes - Added string methods - Moved the logger from static value to static getter - Fixed crashes on dedicated servers - Fixed bracket resolution for <id:meta> values in 1.6.4 - Fixed scripts not being sent to multiplayer clients in 1.6.4
This commit is contained in:
1 parent
7f6235f30d
commit
115593efa5
131 files changed
+3215
-1930
No files matched your search
@@ -56,7 +56,7 @@ public class ZenModule {
|
||||
* @param environmentGlobal global compile environment
|
||||
*/
|
||||
public static void compileScripts(String mainFileName, List<ZenParsedFile> scripts, IEnvironmentGlobal environmentGlobal) {
|
||||
ClassWriter clsMain = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
ClassWriter clsMain = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
clsMain.visitSource(mainFileName, null);
|
||||
|
||||
clsMain.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, "__ZenMain__", null, internal(Object.class), new String[] {internal(Runnable.class)});
|
||||
@@ -76,7 +76,7 @@ public class ZenModule {
|
||||
}
|
||||
|
||||
for (ZenParsedFile script : scripts) {
|
||||
ClassWriter clsScript = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
ClassWriter clsScript = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
clsScript.visitSource(script.getFileName(), null);
|
||||
EnvironmentClass environmentScript = new EnvironmentClass(clsScript, script.getEnvironment());
|
||||
|
||||
@@ -155,6 +155,7 @@ public class ZenModule {
|
||||
*
|
||||
* @param single file to be compiled
|
||||
* @param environment compile environment
|
||||
* @param baseClassLoader
|
||||
* @return compiled module
|
||||
* @throws IOException if the file could not be read
|
||||
*/
|
||||
|
||||
@@ -179,4 +179,9 @@ public class ZenParsedFile {
|
||||
public Map<String, ParsedFunction> getFunctions() {
|
||||
return functions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,8 @@ public class ZenTokener extends TokenStream {
|
||||
"[a-zA-Z_][a-zA-Z_0-9]*",
|
||||
"\\-?(0|[1-9][0-9]*)\\.[0-9]+([eE][\\+\\-]?[0-9]+)?",
|
||||
"\\-?(0|[1-9][0-9]*)",
|
||||
"\"([^\"\\\\]|\\\\([\"\\\\/bfnrt]|u[0-9a-fA-F]{4}))*\"",
|
||||
"\"([^\"\\\\]|\\\\([\'\"\\\\/bfnrt]|u[0-9a-fA-F]{4}))*\"",
|
||||
"\'([^\'\\\\]|\\\\([\'\"\\\\/bfnrt]|u[0-9a-fA-F]{4}))*\'",
|
||||
"\\{",
|
||||
"\\}",
|
||||
"\\[",
|
||||
@@ -152,6 +153,7 @@ public class ZenTokener extends TokenStream {
|
||||
T_FLOATVALUE,
|
||||
T_INTVALUE,
|
||||
T_STRINGVALUE,
|
||||
T_STRINGVALUE,
|
||||
T_AOPEN,
|
||||
T_ACLOSE,
|
||||
T_SQBROPEN,
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ExpressionJavaLambda extends Expression {
|
||||
// generate class
|
||||
String clsName = environment.makeClassName();
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, clsName, null, "java/lang/Object", new String[] { internal(interfaceClass) });
|
||||
|
||||
MethodOutput constructor = new MethodOutput(cw, Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
|
||||
|
||||
@@ -12,18 +12,35 @@ import stanhebben.zenscript.ZenParsedFile;
|
||||
* @author Stan
|
||||
*/
|
||||
public class ParseException extends RuntimeException {
|
||||
private final ZenParsedFile file;
|
||||
private final int line;
|
||||
private final int lineOffset;
|
||||
|
||||
private final Token token;
|
||||
private final String message;
|
||||
|
||||
public ParseException(Token token, String error) {
|
||||
super(token == null ? "Error at end of file - " + error : "Error parsing line " + token.getPosition().getLine() + ":" + token.getPosition().getLineOffset() + " - " + error + " (last token: " + token.getValue() + ")");
|
||||
|
||||
this.file = token.getPosition().getFile();
|
||||
this.line = token.getPosition().getLine();
|
||||
this.lineOffset = token.getPosition().getLineOffset();
|
||||
|
||||
this.token = token;
|
||||
this.message = error;
|
||||
}
|
||||
|
||||
public ParseException(ZenParsedFile file, int line, int lineOffset, String error) {
|
||||
this.file = file;
|
||||
this.line = line;
|
||||
this.lineOffset = lineOffset;
|
||||
|
||||
token = null;
|
||||
message = error;
|
||||
}
|
||||
|
||||
public ZenParsedFile getFile() {
|
||||
return token == null ? null : token.getPosition().getFile();
|
||||
return file;
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
|
||||
@@ -76,6 +76,14 @@ public class TokenStream implements Iterator<Token> {
|
||||
public ZenParsedFile getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
public int getLineOffset() {
|
||||
return lineOffset;
|
||||
}
|
||||
|
||||
public Token peek() {
|
||||
if (tokenMemoryCurrent < tokenMemoryOffset + tokenMemory.size()) {
|
||||
@@ -102,7 +110,7 @@ public class TokenStream implements Iterator<Token> {
|
||||
if (t != null && t.getType() == type) {
|
||||
return next();
|
||||
} else {
|
||||
throw new ParseException(t, error);
|
||||
throw new ParseException(file, line, lineOffset, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-2
@@ -42,10 +42,24 @@ public abstract class ParsedExpression {
|
||||
}
|
||||
|
||||
private static ParsedExpression readAssignExpression(ZenTokener parser, IEnvironmentGlobal environment) {
|
||||
ZenPosition position = parser.peek().getPosition();
|
||||
Token token = parser.peek();
|
||||
if (token == null) {
|
||||
ZenPosition position = new ZenPosition(parser.getFile(), parser.getLine(), parser.getLineOffset());
|
||||
environment.error(position, "unexpected end of file; expression expected");
|
||||
return new ParsedExpressionInvalid(position);
|
||||
}
|
||||
|
||||
ZenPosition position = token.getPosition();
|
||||
|
||||
ParsedExpression left = readConditionalExpression(position, parser, environment);
|
||||
switch (parser.peek() == null ? -1 : parser.peek().getType()) {
|
||||
|
||||
if (parser.peek() == null) {
|
||||
ZenPosition position2 = new ZenPosition(parser.getFile(), parser.getLine(), parser.getLineOffset());
|
||||
environment.error(position2, "unexpected end of file - ; expected");
|
||||
return new ParsedExpressionInvalid(position2);
|
||||
}
|
||||
|
||||
switch (parser.peek().getType()) {
|
||||
case T_ASSIGN:
|
||||
parser.next();
|
||||
return new ParsedExpressionAssign(position, left, readAssignExpression(parser, environment));
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class Statement {
|
||||
names.add(parser.required(T_ID, "identifier expected").getValue());
|
||||
}
|
||||
|
||||
parser.required(T_COLON, ": expected");
|
||||
parser.required(T_IN, "in expected");
|
||||
ParsedExpression source = ParsedExpression.read(parser, environment);
|
||||
Statement content = read(parser, environment);
|
||||
return new StatementForeach(
|
||||
|
||||
@@ -41,8 +41,9 @@ public class StatementForeach extends Statement {
|
||||
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));
|
||||
SymbolLocal localVar = new SymbolLocal(iterator.getType(i), true);
|
||||
local.putValue(varnames[i], localVar);
|
||||
localVariables[i] = local.getLocal(localVar);
|
||||
}
|
||||
|
||||
cList.compile(true, environment);
|
||||
|
||||
@@ -30,21 +30,22 @@ public class IteratorIterable implements IZenIterator {
|
||||
@Override
|
||||
public void compileStart(int[] locals) {
|
||||
iterator = methodOutput.local(Type.getType(Iterator.class));
|
||||
methodOutput.invokeVirtual(Iterator.class, "iterator", Iterator.class);
|
||||
methodOutput.invokeInterface(Iterable.class, "iterator", Iterator.class);
|
||||
methodOutput.storeObject(iterator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void compilePreIterate(int[] locals, Label exit) {
|
||||
methodOutput.dup();
|
||||
methodOutput.loadObject(iterator);
|
||||
methodOutput.invokeInterface(
|
||||
Iterator.class,
|
||||
"hasNext",
|
||||
boolean.class);
|
||||
methodOutput.ifEQ(exit);
|
||||
|
||||
methodOutput.dup();
|
||||
methodOutput.loadObject(iterator);
|
||||
methodOutput.invokeInterface(Iterator.class, "next", Object.class);
|
||||
methodOutput.checkCast(iteratorType.getSignature());
|
||||
methodOutput.store(iteratorType.toASMType(), locals[0]);
|
||||
}
|
||||
|
||||
@@ -60,7 +61,6 @@ public class IteratorIterable implements IZenIterator {
|
||||
|
||||
@Override
|
||||
public void compileEnd() {
|
||||
// pop iterator
|
||||
methodOutput.pop();
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,10 @@ public class MethodOutput {
|
||||
visitor.visitTypeInsn(CHECKCAST, signature(newClass));
|
||||
}
|
||||
|
||||
public void checkCast(String newClass) {
|
||||
visitor.visitTypeInsn(CHECKCAST, newClass.substring(1, newClass.length() - 1));
|
||||
}
|
||||
|
||||
public void iNeg() {
|
||||
visitor.visitInsn(INEG);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class StringUtil {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
result.append('.');
|
||||
result.append(separator);
|
||||
}
|
||||
result.append(value);
|
||||
}
|
||||
@@ -189,7 +189,8 @@ public class StringUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String unescapeString(String oldstr) {
|
||||
if (oldstr.charAt(0) != '"' || oldstr.charAt(oldstr.length() - 1) != '"') {
|
||||
if ((oldstr.charAt(0) != '"' || oldstr.charAt(oldstr.length() - 1) != '"')
|
||||
&& (oldstr.charAt(0) != '\'' || oldstr.charAt(oldstr.length() - 1) != '\'')) {
|
||||
// TODO: error
|
||||
//throw new TweakerExecuteException("Not a valid string constant: "
|
||||
// + oldstr);
|
||||
|
||||
Reference in new issue
Block a user