Squashed commit of the following:

commit 0a3f5772b9450672fb033a6306fbf7fb0d972d5c
Author: Skydark Chen <[email protected]>
Date:   Fri Nov 27 10:54:46 2015 +0800

    Fix for-each iterator
    It should not pop from stack at the end while compiling.

commit 07c057e7502eb51ab3e6088eb2aee9ceb7d07576
Author: Skydark Chen <[email protected]>
Date:   Tue Nov 24 11:45:07 2015 +0800

    Fix non-int type arithmetic compare
    It was an error if we compare two double/float/long in scripts
    since the bytecode compiled in ExpressionArithmeticCompare.java were
    ICMPEQ/ICMPNE/... which assumed that two expressions had an int type.

commit 941b32c8be
Author: Skydark Chen <[email protected]>
Date:   Sun Nov 15 21:24:25 2015 +0800

    Fix ZenGetter and ZenSetter annotations
    Before this commit, ZenGetter and ZenSetter in ZenExpansion could not
    be defined. Since ZenExpansion requires static methods to work, but
    the getters and setters will be invoked as virtual.

commit bd55380b5a
Author: Skydark Chen <[email protected]>
Date:   Sun Nov 15 19:58:21 2015 +0800

    Fix block comments regexp

    Before this commit, comments like this could not be recognized:

        /* blah blah * blah  / <- this slash failed */

commit 2924666ad4
Author: Skydark Chen <[email protected]>
Date:   Sun Nov 15 19:44:02 2015 +0800

    Add support to return void in a function

    * statement `return;` is valid now.
    * functions return void by default, an explicit return is not necessary now

commit 33c2bd0c94
Author: Skydark Chen <[email protected]>
Date:   Sat Nov 14 13:48:53 2015 +0800

    Add unicode support for zenscripts

    The unicode characters can be recognized in strings and comments.
    The encoding of scripts should be utf-8.

commit 89b2548d02
Author: Skydark Chen <[email protected]>
Date:   Thu Nov 12 23:39:25 2015 +0800

    Fix nested foreach loop cause out of index
This commit is contained in:
Skydark Chen committed 2015-11-30 19:15:25 +08:00
1 parent 31375828c2
commit c35e3b1f78
11 files changed
+30 -12

No files matched your search

@@ -95,7 +95,7 @@ public class ZenTokener extends TokenStream {
private static final String[] REGEXPS = {
"#[^\n]*[\n\\e]",
"//[^\n]*[\n\\e]",
"/\\*[^\\*]*(\\*[^/]*)*\\*/",
"/\\*[^\\*]*(\\*|\\*[^/\\*][^\\*]*)*\\*/",
"[ \t\r\n]*",
"[a-zA-Z_][a-zA-Z_0-9]*",
"\\-?(0|[1-9][0-9]*)\\.[0-9]+([eE][\\+\\-]?[0-9]+)?",
@@ -69,10 +69,13 @@ public class ExpressionArithmeticCompare extends Expression {
if (a.getType() == ZenTypeLong.INSTANCE) {
output.lCmp();
output.iConst0();
} else if (a.getType() == ZenTypeFloat.INSTANCE) {
output.fCmp();
output.iConst0();
} else if (a.getType() == ZenTypeDouble.INSTANCE) {
output.dCmp();
output.iConst0();
} else if (a.getType() == ZenTypeByte.INSTANCE
|| a.getType() == ZenTypeShort.INSTANCE
|| a.getType() == ZenTypeInt.INSTANCE) {
@@ -90,6 +90,7 @@ public class ExpressionJavaLambda extends Expression {
for (Statement statement : statements) {
statement.compile(environmentMethod);
}
output.ret();
output.end();
environment.putClass(clsName, cw.toByteArray());
@@ -21,6 +21,10 @@ public class NFA {
public static final int NOFINAL = Integer.MIN_VALUE;
public static final int EPSILON = Integer.MIN_VALUE + 1;
/* UNICODE_ESCAPE should be between 128 and 256, so unicode chars can be
matched by regexp like '.' and '[^a]' and not by '[a-zA-Z]' */
public static final int UNICODE_ESCAPE = 256;
private final NFAState initial;
private HashMap<NodeSet, DFA.DFAState> converted;
@@ -318,6 +322,8 @@ public class NFA {
/* Processes a single character */
private int processChar(CharStream stream) {
if (stream.optional('\\')) {
if (stream.optional('u'))
return UNICODE_ESCAPE;
if (stream.optional('e'))
return -1;
if (stream.optional('r'))
@@ -212,12 +212,17 @@ public class TokenStream implements Iterator<Token> {
StringBuilder value = new StringBuilder();
int tLine = line;
int tLineOffset = lineOffset;
while (dfa.transitions[state].containsKey(nextChar)) {
value.append((char) nextChar);
state = dfa.transitions[state].get(nextChar);
int _fakeNextChar = nextChar > 127 ? NFA.UNICODE_ESCAPE : nextChar;
while (dfa.transitions[state].containsKey(_fakeNextChar)) {
if (nextChar < 0)
value.append((char) nextChar);
else
value.appendCodePoint(nextChar);
state = dfa.transitions[state].get(_fakeNextChar);
line = reader.line;
lineOffset = reader.lineOffset;
nextChar = reader.read();
_fakeNextChar = nextChar > 127 ? NFA.UNICODE_ESCAPE : nextChar;
}
if (line < 0)
@@ -26,7 +26,10 @@ public abstract class Statement {
}
case T_RETURN: {
parser.next();
ParsedExpression expression = ParsedExpression.read(parser, environment);
ParsedExpression expression = null;
if (parser.peek() != null && !parser.isNext(T_SEMICOLON)) {
expression = ParsedExpression.read(parser, environment);
}
parser.required(T_SEMICOLON, "; expected");
return new StatementReturn(next.getPosition(), returnType, expression);
}
@@ -57,5 +57,6 @@ public class StatementForeach extends Statement {
body.compile(local);
iterator.compilePostIterate(localVariables, exit, repeat);
methodOutput.label(exit);
iterator.compileEnd();
}
}
@@ -77,12 +77,12 @@ public class ZenExpandMember {
@Override
public Expression eval(IEnvironmentGlobal environment) {
return new ExpressionCallVirtual(position, environment, getter, value.eval(environment));
return new ExpressionCallStatic(position, environment, getter, value.eval(environment));
}
@Override
public Expression assign(ZenPosition position, IEnvironmentGlobal environment, Expression other) {
return new ExpressionCallVirtual(position, environment, setter, value.eval(environment), other);
return new ExpressionCallStatic(position, environment, setter, value.eval(environment), other);
}
@Override
@@ -61,6 +61,5 @@ public class IteratorIterable implements IZenIterator {
@Override
public void compileEnd() {
methodOutput.pop();
}
}
@@ -39,15 +39,16 @@ public class IteratorList implements IZenIterator {
@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.toASMType().getInternalName());
methodOutput.store(iteratorType.toASMType(), locals[1]);
}
@@ -59,7 +60,6 @@ public class IteratorList implements IZenIterator {
@Override
public void compileEnd() {
methodOutput.pop();
}
@Override