Add compiler by default.
This commit is contained in:
@@ -818,9 +818,11 @@ public class FuncState extends LuaC {
|
||||
case OP_MOD:
|
||||
r = (LNumber) v2.luaBinOpUnknown(op, v1);
|
||||
break;
|
||||
//* TODO: replace this with something reasonable.
|
||||
case OP_POW:
|
||||
r = new LDouble( Math.pow(v1.luaAsDouble(), v2.luaAsDouble() ) );
|
||||
break;
|
||||
//*/
|
||||
case OP_UNM:
|
||||
r = (LNumber) v1.luaUnaryMinus();
|
||||
break;
|
||||
|
||||
@@ -2,8 +2,6 @@ package lua.addon.compile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import lua.Lua;
|
||||
@@ -131,19 +129,24 @@ public class LexState extends LuaC {
|
||||
}
|
||||
|
||||
private boolean isalnum(int c) {
|
||||
return Character.isLetterOrDigit(c);
|
||||
return (c >= '0' && c <= '9')
|
||||
|| (c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z')
|
||||
|| (c == '_');
|
||||
// return Character.isLetterOrDigit(c);
|
||||
}
|
||||
|
||||
private boolean isalpha(int c) {
|
||||
return Character.isLetter(c);
|
||||
return (c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
private boolean isdigit(int c) {
|
||||
return Character.isDigit(c);
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
private boolean isspace(int c) {
|
||||
return Character.isWhitespace(c);
|
||||
return (c <= ' ');
|
||||
}
|
||||
|
||||
|
||||
@@ -294,14 +297,15 @@ public class LexState extends LuaC {
|
||||
}
|
||||
|
||||
boolean str2d(String str, SemInfo seminfo) {
|
||||
try {
|
||||
double d = Double.parseDouble(str);
|
||||
seminfo.r = new LDouble(d);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
double d;
|
||||
str = str.trim(); // TODO: get rid of this
|
||||
if ( str.startsWith("0x") ) {
|
||||
d = Long.parseLong(str.substring(2), 16);
|
||||
}
|
||||
else
|
||||
d = Double.parseDouble(str);
|
||||
seminfo.r = new LDouble(d);
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -320,6 +324,7 @@ public class LexState extends LuaC {
|
||||
// }
|
||||
// }
|
||||
//
|
||||
/*
|
||||
void trydecpoint(String str, SemInfo seminfo) {
|
||||
NumberFormat nf = NumberFormat.getInstance();
|
||||
try {
|
||||
@@ -330,6 +335,7 @@ public class LexState extends LuaC {
|
||||
lexerror("malformed number", TK_NUMBER);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void read_numeral(SemInfo seminfo) {
|
||||
_assert (isdigit(current));
|
||||
@@ -343,8 +349,9 @@ public class LexState extends LuaC {
|
||||
save('\0');
|
||||
buffreplace('.', decpoint); /* follow locale for decimal point */
|
||||
String str = new String(buff, 0, nbuff);
|
||||
if (!str2d(str, seminfo)) /* format error? */
|
||||
trydecpoint(str, seminfo); /* try to update decimal point separator */
|
||||
// if (!str2d(str, seminfo)) /* format error? */
|
||||
// trydecpoint(str, seminfo); /* try to update decimal point separator */
|
||||
str2d(str, seminfo);
|
||||
}
|
||||
|
||||
int skip_sep() {
|
||||
|
||||
@@ -455,7 +455,7 @@ public class LuaCompat extends LFunction {
|
||||
private static boolean loadis(VM vm, InputStream is, String chunkname ) {
|
||||
try {
|
||||
if ( 0 != vm.lua_load(is, chunkname) ) {
|
||||
vm.setErrorResult( LNil.NIL, "cannot load "+chunkname+": "+vm.getArgAsString(0) );
|
||||
vm.setErrorResult( LNil.NIL, "cannot load "+chunkname+": "+vm.lua_tolvalue(-1) );
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
||||
@@ -460,7 +460,7 @@ public class StrLib {
|
||||
|
||||
static boolean match_class( int c, int cl ) {
|
||||
boolean res;
|
||||
switch ( Character.toLowerCase( c ) ) {
|
||||
switch ( Character.toLowerCase( (char) c ) ) {
|
||||
case 'a': res = isalpha( c ); break;
|
||||
case 'd': res = Character.isDigit( (char) c ); break;
|
||||
case 'l': res = Character.isLowerCase( (char) c ); break;
|
||||
|
||||
@@ -3,6 +3,7 @@ package lua.io;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import lua.VM;
|
||||
import lua.value.LBoolean;
|
||||
@@ -32,7 +33,7 @@ public class LoadState {
|
||||
public static final int LUAC_HEADERSIZE = 12;
|
||||
|
||||
/** expected lua header bytes */
|
||||
private static final int LUAC_HEADER_SIGNATURE = ('\033'<<24) | ('L'<<16) | ('u'<<8) | ('a');
|
||||
private static final byte[] LUAC_HEADER_SIGNATURE = { '\033', 'L', 'u', 'a' };
|
||||
|
||||
// values read from the header
|
||||
private int luacVersion;
|
||||
@@ -225,7 +226,6 @@ public class LoadState {
|
||||
// IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
|
||||
// }
|
||||
public void loadHeader() throws IOException {
|
||||
int sig = is.readInt();
|
||||
luacVersion = is.readByte();
|
||||
luacFormat = is.readByte();
|
||||
luacLittleEndian = (0 != is.readByte());
|
||||
@@ -234,11 +234,27 @@ public class LoadState {
|
||||
luacSizeofInstruction = is.readByte();
|
||||
luacSizeofLuaNumber = is.readByte();
|
||||
luacIsNumberIntegral = (0 != is.readByte());
|
||||
if ( sig != LUAC_HEADER_SIGNATURE )
|
||||
throw new IllegalArgumentException("bad signature");
|
||||
}
|
||||
|
||||
public static Proto undump( VM L, InputStream stream, String name ) throws IOException {
|
||||
|
||||
// is this a source file?
|
||||
stream.mark(1);
|
||||
if ( stream.read() != LUAC_HEADER_SIGNATURE[0] ) {
|
||||
stream.reset();
|
||||
// TODO: handle UTF-8 here!
|
||||
return lua.addon.compile.Compiler.compile(
|
||||
new InputStreamReader(stream),
|
||||
name );
|
||||
}
|
||||
|
||||
// check signature
|
||||
for ( int i=1; i<4; i++ ) {
|
||||
if ( stream.read() != LUAC_HEADER_SIGNATURE[i] )
|
||||
throw new IllegalArgumentException("bad signature");
|
||||
}
|
||||
|
||||
// load file
|
||||
String sname = name;
|
||||
if ( name.startsWith("@") || name.startsWith("=") )
|
||||
sname = name.substring(1);
|
||||
|
||||
Reference in New Issue
Block a user