org.luaj.vm2.Prototype Java Examples
The following examples show how to use
org.luaj.vm2.Prototype.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: VideoOS-Android-SDK Author: VideoOS File: LuaPrint.java License: GNU General Public License v3.0 | 6 votes |
void buildHeader(Prototype f) { String s = String.valueOf(f.source); if (s.startsWith("@") || s.startsWith("=")) s = s.substring(1); else if ("\033Lua".equals(s)) s = "(bstring)"; else s = "(string)"; String a = (f.linedefined == 0) ? "main" : "function"; ps.append("\n%" + a + " <" + s + ":" + f.linedefined + "," + f.lastlinedefined + "> (" + f.code.length + " instructions, " + f.code.length * 4 + " bytes at " + id(f) + ")\n"); ps.append(f.numparams + " param, " + f.maxstacksize + " slot, " + f.upvalues.length + " upvalue, "); ps.append(f.locvars.length + " local, " + f.k.length + " constant, " + f.p.length + " function\n"); }
Example #2
Source Project: VideoOS-Android-SDK Author: VideoOS File: DebugLib.java License: GNU General Public License v3.0 | 6 votes |
public void funcinfo(LuaFunction f) { if (f.isclosure()) { Prototype p = f.checkclosure().p; this.source = p.source != null ? p.source.tojstring() : "=?"; this.linedefined = p.linedefined; this.lastlinedefined = p.lastlinedefined; this.what = (this.linedefined == 0) ? "main" : "Lua"; this.short_src = p.shortsource(); } else { this.source = "=[Java]"; this.linedefined = -1; this.lastlinedefined = -1; this.what = "Java"; this.short_src = f.name(); } }
Example #3
Source Project: VideoOS-Android-SDK Author: VideoOS File: LexState.java License: GNU General Public License v3.0 | 6 votes |
void close_func() { FuncState fs = this.fs; Prototype f = fs.f; fs.ret(0, 0); /* return */ fs.leaveblock(); f.code = LuaC.realloc(f.code, fs.pc); f.lineinfo = LuaC.realloc(f.lineinfo, fs.pc); f.k = LuaC.realloc(f.k, fs.nk); f.p = LuaC.realloc(f.p, fs.np); f.locvars = LuaC.realloc(f.locvars, fs.nlocvars); f.upvalues = LuaC.realloc(f.upvalues, fs.nups); LuaC._assert(fs.bl == null); this.fs = fs.prev; // last token read was anchored in defunct function; must reanchor it // ls.anchor_token(); }
Example #4
Source Project: VideoOS-Android-SDK Author: VideoOS File: DumpState.java License: GNU General Public License v3.0 | 6 votes |
void dumpDebug( Prototype f) throws IOException { int i, n; if (strip) dumpInt(0); else dumpString(f.source); n = strip ? 0 : f.lineinfo.length; dumpInt(n); for (i = 0; i < n; i++) dumpInt(f.lineinfo[i]); n = strip ? 0 : f.locvars.length; dumpInt(n); for (i = 0; i < n; i++) { LocVars lvi = f.locvars[i]; dumpString(lvi.varname); dumpInt(lvi.startpc); dumpInt(lvi.endpc); } n = strip ? 0 : f.upvalues.length; dumpInt(n); for (i = 0; i < n; i++) dumpString(f.upvalues[i].name); }
Example #5
Source Project: VideoOS-Android-SDK Author: VideoOS File: LuaC.java License: GNU General Public License v3.0 | 6 votes |
/** * Parse the input */ private Prototype luaY_parser(InputStream z, String name, boolean standardSyntax) throws IOException { LexState lexstate = new LexState(this, z, standardSyntax); FuncState funcstate = new FuncState(); // lexstate.buff = buff; lexstate.fs = funcstate; lexstate.setinput(this, z.read(), z, (LuaString) LuaValue.valueOf(name)); /* main func. is always vararg */ funcstate.f = new Prototype(); funcstate.f.source = (LuaString) LuaValue.valueOf(name); lexstate.mainfunc(funcstate); LuaC._assert(funcstate.prev == null); /* all scopes should be correctly finished */ LuaC._assert(lexstate.dyd == null || (lexstate.dyd.n_actvar == 0 && lexstate.dyd.n_gt == 0 && lexstate.dyd.n_label == 0)); return funcstate.f; }
Example #6
Source Project: XPrivacyLua Author: M66B File: DebugLib.java License: GNU General Public License v3.0 | 6 votes |
public void funcinfo(LuaFunction f) { if (f.isclosure()) { Prototype p = f.checkclosure().p; this.source = p.source != null ? p.source.tojstring() : "=?"; this.linedefined = p.linedefined; this.lastlinedefined = p.lastlinedefined; this.what = (this.linedefined == 0) ? "main" : "Lua"; this.short_src = p.shortsource(); } else { this.source = "=[Java]"; this.linedefined = -1; this.lastlinedefined = -1; this.what = "Java"; this.short_src = f.name(); } }
Example #7
Source Project: XPrivacyLua Author: M66B File: LexState.java License: GNU General Public License v3.0 | 6 votes |
void close_func() { FuncState fs = this.fs; Prototype f = fs.f; fs.ret(0, 0); /* final return */ fs.leaveblock(); f.code = realloc(f.code, fs.pc); f.lineinfo = realloc(f.lineinfo, fs.pc); f.k = realloc(f.k, fs.nk); f.p = realloc(f.p, fs.np); f.locvars = realloc(f.locvars, fs.nlocvars); f.upvalues = realloc(f.upvalues, fs.nups); _assert (fs.bl == null); this.fs = fs.prev; // last token read was anchored in defunct function; must reanchor it // ls.anchor_token(); }
Example #8
Source Project: XPrivacyLua Author: M66B File: DumpState.java License: GNU General Public License v3.0 | 6 votes |
void dumpDebug(final Prototype f) throws IOException { int i, n; if (strip) dumpInt(0); else dumpString(f.source); n = strip ? 0 : f.lineinfo.length; dumpInt(n); for (i = 0; i < n; i++) dumpInt(f.lineinfo[i]); n = strip ? 0 : f.locvars.length; dumpInt(n); for (i = 0; i < n; i++) { LocVars lvi = f.locvars[i]; dumpString(lvi.varname); dumpInt(lvi.startpc); dumpInt(lvi.endpc); } n = strip ? 0 : f.upvalues.length; dumpInt(n); for (i = 0; i < n; i++) dumpString(f.upvalues[i].name); }
Example #9
Source Project: XPrivacyLua Author: M66B File: DumpState.java License: GNU General Public License v3.0 | 6 votes |
/** * * @param f the function to dump * @param w the output stream to dump to * @param stripDebug true to strip debugging info, false otherwise * @param numberFormat one of NUMBER_FORMAT_FLOATS_OR_DOUBLES, NUMBER_FORMAT_INTS_ONLY, NUMBER_FORMAT_NUM_PATCH_INT32 * @param littleendian true to use little endian for numbers, false for big endian * @return 0 if dump succeeds * @throws IOException * @throws IllegalArgumentException if the number format it not supported */ public static int dump(Prototype f, OutputStream w, boolean stripDebug, int numberFormat, boolean littleendian) throws IOException { switch ( numberFormat ) { case NUMBER_FORMAT_FLOATS_OR_DOUBLES: case NUMBER_FORMAT_INTS_ONLY: case NUMBER_FORMAT_NUM_PATCH_INT32: break; default: throw new IllegalArgumentException("number format not supported: "+numberFormat); } DumpState D = new DumpState(w,stripDebug); D.IS_LITTLE_ENDIAN = littleendian; D.NUMBER_FORMAT = numberFormat; D.SIZEOF_LUA_NUMBER = (numberFormat==NUMBER_FORMAT_INTS_ONLY? 4: 8); D.dumpHeader(); D.dumpFunction(f); return D.status; }
Example #10
Source Project: XPrivacyLua Author: M66B File: LuaC.java License: GNU General Public License v3.0 | 6 votes |
/** Parse the input */ private Prototype luaY_parser(InputStream z, String name) throws IOException{ LexState lexstate = new LexState(this, z); FuncState funcstate = new FuncState(); // lexstate.buff = buff; lexstate.fs = funcstate; lexstate.setinput(this, z.read(), z, (LuaString) LuaValue.valueOf(name) ); /* main func. is always vararg */ funcstate.f = new Prototype(); funcstate.f.source = (LuaString) LuaValue.valueOf(name); lexstate.mainfunc(funcstate); LuaC._assert (funcstate.prev == null); /* all scopes should be correctly finished */ LuaC._assert (lexstate.dyd == null || (lexstate.dyd.n_actvar == 0 && lexstate.dyd.n_gt == 0 && lexstate.dyd.n_label == 0)); return funcstate.f; }
Example #11
Source Project: HtmlNative Author: hsllany File: ProtoInfo.java License: Apache License 2.0 | 6 votes |
private ProtoInfo(Prototype p, String name, UpvalInfo[] u) { this.name = name; this.prototype = p; this.upvals = u != null? u: new UpvalInfo[] { new UpvalInfo(this) }; this.subprotos = p.p!=null&&p.p.length>0? new ProtoInfo[p.p.length]: null; // find basic blocks this.blocks = BasicBlock.findBasicBlocks(p); this.blocklist = BasicBlock.findLiveBlocks(blocks); // params are inputs to first block this.params = new VarInfo[p.maxstacksize]; for ( int slot=0; slot<p.maxstacksize; slot++ ) { VarInfo v = VarInfo.PARAM(slot); params[slot] = v; } // find variables this.vars = findVariables(); replaceTrivialPhiVariables(); // find upvalues, create sub-prototypes this.openups = new UpvalInfo[p.maxstacksize][]; findUpvalues(); }
Example #12
Source Project: HtmlNative Author: hsllany File: ProtoInfo.java License: Apache License 2.0 | 6 votes |
private void findUpvalues() { int[] code = prototype.code; int n = code.length; // propogate to inner prototypes String[] names = findInnerprotoNames(); for ( int pc=0; pc<n; pc++ ) { if ( Lua.GET_OPCODE(code[pc]) == Lua.OP_CLOSURE ) { int bx = Lua.GETARG_Bx(code[pc]); Prototype newp = prototype.p[bx]; UpvalInfo[] newu = new UpvalInfo[newp.upvalues.length]; String newname = name + "$" + names[bx]; for ( int j=0; j<newp.upvalues.length; ++j ) { Upvaldesc u = newp.upvalues[j]; newu[j] = u.instack? findOpenUp(pc,u.idx) : upvals[u.idx]; } subprotos[bx] = new ProtoInfo(newp, newname, newu); } } // mark all upvalues that are written locally as read/write for ( int pc=0; pc<n; pc++ ) { if ( Lua.GET_OPCODE(code[pc]) == Lua.OP_SETUPVAL ) upvals[Lua.GETARG_B(code[pc])].rw = true; } }
Example #13
Source Project: HtmlNative Author: hsllany File: DebugLib.java License: Apache License 2.0 | 6 votes |
public void funcinfo(LuaFunction f) { if (f.isclosure()) { Prototype p = f.checkclosure().p; this.source = p.source != null ? p.source.tojstring() : "=?"; this.linedefined = p.linedefined; this.lastlinedefined = p.lastlinedefined; this.what = (this.linedefined == 0) ? "main" : "Lua"; this.short_src = p.shortsource(); } else { this.source = "=[Java]"; this.linedefined = -1; this.lastlinedefined = -1; this.what = "Java"; this.short_src = f.name(); } }
Example #14
Source Project: HtmlNative Author: hsllany File: DumpState.java License: Apache License 2.0 | 6 votes |
void dumpDebug(final Prototype f) throws IOException { int i, n; if (strip) dumpInt(0); else dumpString(f.source); n = strip ? 0 : f.lineinfo.length; dumpInt(n); for (i = 0; i < n; i++) dumpInt(f.lineinfo[i]); n = strip ? 0 : f.locvars.length; dumpInt(n); for (i = 0; i < n; i++) { LocVars lvi = f.locvars[i]; dumpString(lvi.varname); dumpInt(lvi.startpc); dumpInt(lvi.endpc); } n = strip ? 0 : f.upvalues.length; dumpInt(n); for (i = 0; i < n; i++) dumpString(f.upvalues[i].name); }
Example #15
Source Project: HtmlNative Author: hsllany File: DumpState.java License: Apache License 2.0 | 6 votes |
/** * * @param f the function to dump * @param w the output stream to dump to * @param stripDebug true to strip debugging info, false otherwise * @param numberFormat one of NUMBER_FORMAT_FLOATS_OR_DOUBLES, NUMBER_FORMAT_INTS_ONLY, NUMBER_FORMAT_NUM_PATCH_INT32 * @param littleendian true to use little endian for numbers, false for big endian * @return 0 if dump succeeds * @throws IOException * @throws IllegalArgumentException if the number format it not supported */ public static int dump(Prototype f, OutputStream w, boolean stripDebug, int numberFormat, boolean littleendian) throws IOException { switch ( numberFormat ) { case NUMBER_FORMAT_FLOATS_OR_DOUBLES: case NUMBER_FORMAT_INTS_ONLY: case NUMBER_FORMAT_NUM_PATCH_INT32: break; default: throw new IllegalArgumentException("number format not supported: "+numberFormat); } DumpState D = new DumpState(w,stripDebug); D.IS_LITTLE_ENDIAN = littleendian; D.NUMBER_FORMAT = numberFormat; D.SIZEOF_LUA_NUMBER = (numberFormat==NUMBER_FORMAT_INTS_ONLY? 4: 8); D.dumpHeader(); D.dumpFunction(f); return D.status; }
Example #16
Source Project: HtmlNative Author: hsllany File: LuaC.java License: Apache License 2.0 | 6 votes |
/** Parse the input */ private Prototype luaY_parser(InputStream z, String name) throws IOException{ LexState lexstate = new LexState(this, z); FuncState funcstate = new FuncState(); // lexstate.buff = buff; lexstate.fs = funcstate; lexstate.setinput(this, z.read(), z, (LuaString) LuaValue.valueOf(name) ); /* main func. is always vararg */ funcstate.f = new Prototype(); funcstate.f.source = (LuaString) LuaValue.valueOf(name); lexstate.mainfunc(funcstate); LuaC._assert (funcstate.prev == null); /* all scopes should be correctly finished */ LuaC._assert (lexstate.dyd == null || (lexstate.dyd.n_actvar == 0 && lexstate.dyd.n_gt == 0 && lexstate.dyd.n_label == 0)); return funcstate.f; }
Example #17
Source Project: VideoOS-Android-SDK Author: VideoOS File: LuaPrint.java License: GNU General Public License v3.0 | 5 votes |
/** * Print the code in a prototype * * @param f the {@link Prototype} */ void buildCode(Prototype f) { int[] code = f.code; int pc, n = code.length; for (pc = 0; pc < n; pc++) { buildOpCode(f, pc); ps.append("\n"); } }
Example #18
Source Project: VideoOS-Android-SDK Author: VideoOS File: LuaPrint.java License: GNU General Public License v3.0 | 5 votes |
void buildConstants(Prototype f) { int i, n = f.k.length; ps.append("constants (" + n + ") for " + id(f) + ":\n"); for (i = 0; i < n; i++) { ps.append(" " + (i + 1) + " "); buildValue(ps, f.k[i]); ps.append("\n"); } }
Example #19
Source Project: VideoOS-Android-SDK Author: VideoOS File: LuaPrint.java License: GNU General Public License v3.0 | 5 votes |
void buildLocals(Prototype f) { int i, n = f.locvars.length; ps.append("locals (" + n + ") for " + id(f) + ":\n"); for (i = 0; i < n; i++) { ps.append(" " + i + " " + f.locvars[i].varname + " " + (f.locvars[i].startpc + 1) + " " + (f.locvars[i].endpc + 1)); } }
Example #20
Source Project: VideoOS-Android-SDK Author: VideoOS File: LuaPrint.java License: GNU General Public License v3.0 | 5 votes |
void buildUpValues(Prototype f) { int i, n = f.upvalues.length; ps.append("upvalues (" + n + ") for " + id(f) + ":\n"); for (i = 0; i < n; i++) { ps.append(" " + i + " " + f.upvalues[i] + "\n"); } }
Example #21
Source Project: VideoOS-Android-SDK Author: VideoOS File: LuaPrint.java License: GNU General Public License v3.0 | 5 votes |
/** * Pretty-prints contents of a Prototype in short or long form. * * @param prototype Prototype to print. * @param full true to print all fields, false to print short form. */ void buildFunction(Prototype prototype, boolean full) { int i, n = prototype.p.length; buildHeader(prototype); buildCode(prototype); if (full) { buildConstants(prototype); buildLocals(prototype); buildUpValues(prototype); } for (i = 0; i < n; i++) buildFunction(prototype.p[i], full); }
Example #22
Source Project: VideoOS-Android-SDK Author: VideoOS File: LexState.java License: GNU General Public License v3.0 | 5 votes |
int registerlocalvar(LuaString varname) { FuncState fs = this.fs; Prototype f = fs.f; if (f.locvars == null || fs.nlocvars + 1 > f.locvars.length) f.locvars = LuaC.realloc(f.locvars, fs.nlocvars * 2 + 1); f.locvars[fs.nlocvars] = new LocVars(varname, 0, 0); return fs.nlocvars++; }
Example #23
Source Project: VideoOS-Android-SDK Author: VideoOS File: LexState.java License: GNU General Public License v3.0 | 5 votes |
Prototype addprototype() { Prototype clp; Prototype f = fs.f; /* prototype of current function */ if (f.p == null || fs.np >= f.p.length) { f.p = LuaC.realloc(f.p, Math.max(1, fs.np * 2)); } f.p[fs.np++] = clp = new Prototype(); return clp; }
Example #24
Source Project: VideoOS-Android-SDK Author: VideoOS File: LexState.java License: GNU General Public License v3.0 | 5 votes |
void parlist() { /* parlist -> [ param { `,' param } ] */ FuncState fs = this.fs; Prototype f = fs.f; int nparams = 0; f.is_vararg = 0; if (this.t.token != ')') { /* is `parlist' not empty? */ do { switch (this.t.token) { case TK_NAME: { /* param . NAME */ this.new_localvar(this.str_checkname()); ++nparams; break; } case TK_DOTS: { /* param . `...' */ this.next(); f.is_vararg = 1; break; } default: this.syntaxerror("<name> or " + LUA_QL("...") + " expected"); } } while ((f.is_vararg == 0) && this.testnext(',')); } this.adjustlocalvars(nparams); f.numparams = fs.nactvar; fs.reserveregs(fs.nactvar); /* reserve register for parameters */ }
Example #25
Source Project: VideoOS-Android-SDK Author: VideoOS File: FuncState.java License: GNU General Public License v3.0 | 5 votes |
int addk(LuaValue v) { if (this.h == null) { this.h = new Hashtable(); } else if (this.h.containsKey(v)) { return ((Integer) h.get(v)).intValue(); } int idx = this.nk; this.h.put(v, new Integer(idx)); Prototype f = this.f; if (f.k == null || nk + 1 >= f.k.length) f.k = realloc( f.k, nk*2 + 1 ); f.k[this.nk++] = v; return idx; }
Example #26
Source Project: VideoOS-Android-SDK Author: VideoOS File: FuncState.java License: GNU General Public License v3.0 | 5 votes |
int code(int instruction, int line) { Prototype f = this.f; this.dischargejpc(); /* `pc' will change */ /* put new instruction in code array */ if (f.code == null || this.pc + 1 > f.code.length) f.code = LuaC.realloc(f.code, this.pc * 2 + 1); f.code[this.pc] = instruction; /* save corresponding line information */ if (f.lineinfo == null || this.pc + 1 > f.lineinfo.length) f.lineinfo = LuaC.realloc(f.lineinfo, this.pc * 2 + 1); f.lineinfo[this.pc] = line; return this.pc++; }
Example #27
Source Project: VideoOS-Android-SDK Author: VideoOS File: DumpState.java License: GNU General Public License v3.0 | 5 votes |
void dumpCode( final Prototype f ) throws IOException { int[] code = f.code; int n = code.length; dumpInt( n ); for ( int i=0; i<n; i++ ) dumpInt( code[i] ); }
Example #28
Source Project: VideoOS-Android-SDK Author: VideoOS File: DumpState.java License: GNU General Public License v3.0 | 5 votes |
void dumpUpvalues( Prototype f) throws IOException { int n = f.upvalues.length; dumpInt(n); for (int i = 0; i < n; i++) { writer.writeByte(f.upvalues[i].instack ? 1 : 0); writer.writeByte(f.upvalues[i].idx); } }
Example #29
Source Project: VideoOS-Android-SDK Author: VideoOS File: DumpState.java License: GNU General Public License v3.0 | 5 votes |
void dumpFunction( Prototype f) throws IOException { dumpInt(f.linedefined); dumpInt(f.lastlinedefined); dumpChar(f.numparams); dumpChar(f.is_vararg); dumpChar(f.maxstacksize); dumpCode(f); dumpConstants(f); dumpUpvalues(f); dumpDebug(f); }
Example #30
Source Project: VideoOS-Android-SDK Author: VideoOS File: ScriptBundleLoadDelegate.java License: GNU General Public License v3.0 | 5 votes |
/** * load a prototype * * @param scriptFile * @return */ private Prototype loadPrototype( ScriptFile scriptFile) { if (LoadState.instance != null && scriptFile != null) { try { return LoadState.instance.undump(new BufferedInputStream(new ByteArrayInputStream(scriptFile.scriptData)), scriptFile.getFilePath());//TODO 低端机性能上可以进一步优化 } catch (LuaError error) { } catch (Exception e) { } } return null; }