Java Code Examples for org.luaj.vm2.Lua

The following examples show how to use org.luaj.vm2.Lua. These examples are extracted from open source projects. 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   Source File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void recfield(ConsControl cc) {
/* recfield -> (NAME | `['exp1`]') = exp1 */
      FuncState fs = this.fs;
      int reg = this.fs.freereg;
      expdesc key = new expdesc();
      expdesc val = new expdesc();
      int rkkey;
      if (this.t.token == TK_NAME) {
          fs.checklimit(cc.nh, MAX_INT, "items in a constructor");
          this.checkname(key);
      } else
	/* this.t.token == '[' */
          this.yindex(key);
      cc.nh++;
      this.checknext('=');
      rkkey = fs.exp2RK(key);
      this.expr(val);
      fs.codeABC(Lua.OP_SETTABLE, cc.t.u.info, rkkey, fs.exp2RK(val));
      fs.freereg = (short) reg; /* free registers */
  }
 
Example 2
Source Project: VideoOS-Android-SDK   Source File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void check_conflict(LHS_assign lh, expdesc v) {
    FuncState fs = this.fs;
    short extra = (short) fs.freereg;  /* eventual position to save local variable */
    boolean conflict = false;
    for (; lh != null; lh = lh.prev) {
        if (lh.v.k == VINDEXED) {
/* table is the upvalue/local being assigned now? */
            if (lh.v.u.ind_vt == v.k && lh.v.u.ind_t == v.u.info) {
                conflict = true;
                lh.v.u.ind_vt = VLOCAL;
                lh.v.u.ind_t = extra;  /* previous assignment will use safe copy */
            }
/* index is the local being assigned? (index cannot be upvalue) */
            if (v.k == VLOCAL && lh.v.u.ind_idx == v.u.info) {
                conflict = true;
                lh.v.u.ind_idx = extra;  /* previous assignment will use safe copy */
            }
        }
    }
    if (conflict) {
  /* copy upvalue/local value to a temporary (in position 'extra') */
        int op = (v.k == VLOCAL) ? Lua.OP_MOVE : Lua.OP_GETUPVAL;
        fs.codeABC(op, extra, v.u.info, 0);
        fs.reserveregs(1);
    }
}
 
Example 3
Source Project: VideoOS-Android-SDK   Source File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void forbody(int base, int line, int nvars, boolean isnum) {
/* forbody -> DO block */
      BlockCnt bl = new BlockCnt();
      FuncState fs = this.fs;
      int prep, endfor;
      this.adjustlocalvars(3); /* control variables */
      this.checknext(TK_DO);
      prep = isnum ? fs.codeAsBx(Lua.OP_FORPREP, base, NO_JUMP) : fs.jump();
      fs.enterblock(bl, false); /* scope for declared variables */
      this.adjustlocalvars(nvars);
      fs.reserveregs(nvars);
      this.block();
      fs.leaveblock(); /* end of scope for declared variables */
      fs.patchtohere(prep);
      if (isnum)  /* numeric for? */
          endfor = fs.codeAsBx(Lua.OP_FORLOOP, base, NO_JUMP);
      else {  /* generic for */
          fs.codeABC(Lua.OP_TFORCALL, base, 0, nvars);
          fs.fixline(line);
          endfor = fs.codeAsBx(Lua.OP_TFORLOOP, base + 2, NO_JUMP);
      }
      fs.patchlist(endfor, prep + 1);
      fs.fixline(line);
  }
 
Example 4
Source Project: VideoOS-Android-SDK   Source File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void fornum(LuaString varname, int line) {
/* fornum -> NAME = exp1,exp1[,exp1] forbody */
      FuncState fs = this.fs;
      int base = fs.freereg;
      this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_INDEX);
      this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_LIMIT);
      this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_STEP);
      this.new_localvar(varname);
      this.checknext('=');
      this.exp1(); /* initial value */
      this.checknext(',');
      this.exp1(); /* limit */
      if (this.testnext(','))
          this.exp1(); /* optional step */
      else { /* default step = 1 */
          fs.codeABx(Lua.OP_LOADK, fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
          fs.reserveregs(1);
      }
      this.forbody(base, line, 1, true);
  }
 
Example 5
Source Project: XPrivacyLua   Source File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void recfield(ConsControl cc) {
	/* recfield -> (NAME | `['exp1`]') = exp1 */
	FuncState fs = this.fs;
	int reg = this.fs.freereg;
	expdesc key = new expdesc();
	expdesc val = new expdesc();
	int rkkey;
	if (this.t.token == TK_NAME) {
		fs.checklimit(cc.nh, MAX_INT, "items in a constructor");
		this.checkname(key);
	} else
		/* this.t.token == '[' */
		this.yindex(key);
	cc.nh++;
	this.checknext('=');
	rkkey = fs.exp2RK(key);
	this.expr(val);
	fs.codeABC(Lua.OP_SETTABLE, cc.t.u.info, rkkey, fs.exp2RK(val));
	fs.freereg = (short)reg; /* free registers */
}
 
Example 6
Source Project: XPrivacyLua   Source File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void check_conflict (LHS_assign lh, expdesc v) {
	FuncState fs = this.fs;
	short extra = (short) fs.freereg;  /* eventual position to save local variable */
	boolean conflict = false;
	for (; lh!=null; lh = lh.prev) {
		if (lh.v.k == VINDEXED) {
			/* table is the upvalue/local being assigned now? */
			if (lh.v.u.ind_vt == v.k && lh.v.u.ind_t == v.u.info) {
				conflict = true;
				lh.v.u.ind_vt = VLOCAL;
				lh.v.u.ind_t = extra;  /* previous assignment will use safe copy */
			}
			/* index is the local being assigned? (index cannot be upvalue) */
			if (v.k == VLOCAL && lh.v.u.ind_idx == v.u.info) {
				conflict = true;
				lh.v.u.ind_idx = extra;  /* previous assignment will use safe copy */
			}
		}
	}
	if (conflict) {
	    /* copy upvalue/local value to a temporary (in position 'extra') */
	    int op = (v.k == VLOCAL) ? Lua.OP_MOVE : Lua.OP_GETUPVAL;
	    fs.codeABC(op, extra, v.u.info, 0);
	    fs.reserveregs(1);
	}
}
 
Example 7
Source Project: XPrivacyLua   Source File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void forbody(int base, int line, int nvars, boolean isnum) {
	/* forbody -> DO block */
	BlockCnt bl = new BlockCnt();
	FuncState fs = this.fs;
	int prep, endfor;
	this.adjustlocalvars(3); /* control variables */
	this.checknext(TK_DO);
	prep = isnum ? fs.codeAsBx(Lua.OP_FORPREP, base, NO_JUMP) : fs.jump();
	fs.enterblock(bl, false); /* scope for declared variables */
	this.adjustlocalvars(nvars);
	fs.reserveregs(nvars);
	this.block();
	fs.leaveblock(); /* end of scope for declared variables */
	fs.patchtohere(prep);
	if (isnum)  /* numeric for? */
		endfor = fs.codeAsBx(Lua.OP_FORLOOP, base, NO_JUMP);
	else {  /* generic for */
		fs.codeABC(Lua.OP_TFORCALL, base, 0, nvars);
		fs.fixline(line);
		endfor = fs.codeAsBx(Lua.OP_TFORLOOP, base + 2, NO_JUMP);
	}
	fs.patchlist(endfor, prep + 1);
	fs.fixline(line);
}
 
Example 8
Source Project: XPrivacyLua   Source File: LexState.java    License: GNU General Public License v3.0 6 votes vote down vote up
void fornum(LuaString varname, int line) {
	/* fornum -> NAME = exp1,exp1[,exp1] forbody */
	FuncState fs = this.fs;
	int base = fs.freereg;
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_INDEX);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_LIMIT);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_STEP);
	this.new_localvar(varname);
	this.checknext('=');
	this.exp1(); /* initial value */
	this.checknext(',');
	this.exp1(); /* limit */
	if (this.testnext(','))
		this.exp1(); /* optional step */
	else { /* default step = 1 */
		fs.codeABx(Lua.OP_LOADK, fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
		fs.reserveregs(1);
	}
	this.forbody(base, line, 1, true);
}
 
Example 9
Source Project: HtmlNative   Source File: ProtoInfo.java    License: Apache License 2.0 6 votes vote down vote up
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 10
Source Project: HtmlNative   Source File: LexState.java    License: Apache License 2.0 6 votes vote down vote up
void recfield(ConsControl cc) {
	/* recfield -> (NAME | `['exp1`]') = exp1 */
	FuncState fs = this.fs;
	int reg = this.fs.freereg;
	expdesc key = new expdesc();
	expdesc val = new expdesc();
	int rkkey;
	if (this.t.token == TK_NAME) {
		fs.checklimit(cc.nh, MAX_INT, "items in a constructor");
		this.checkname(key);
	} else
		/* this.t.token == '[' */
		this.yindex(key);
	cc.nh++;
	this.checknext('=');
	rkkey = fs.exp2RK(key);
	this.expr(val);
	fs.codeABC(Lua.OP_SETTABLE, cc.t.u.info, rkkey, fs.exp2RK(val));
	fs.freereg = (short)reg; /* free registers */
}
 
Example 11
Source Project: HtmlNative   Source File: LexState.java    License: Apache License 2.0 6 votes vote down vote up
void check_conflict (LHS_assign lh, expdesc v) {
	FuncState fs = this.fs;
	short extra = (short) fs.freereg;  /* eventual position to save local variable */
	boolean conflict = false;
	for (; lh!=null; lh = lh.prev) {
		if (lh.v.k == VINDEXED) {
			/* table is the upvalue/local being assigned now? */
			if (lh.v.u.ind_vt == v.k && lh.v.u.ind_t == v.u.info) {
				conflict = true;
				lh.v.u.ind_vt = VLOCAL;
				lh.v.u.ind_t = extra;  /* previous assignment will use safe copy */
			}
			/* index is the local being assigned? (index cannot be upvalue) */
			if (v.k == VLOCAL && lh.v.u.ind_idx == v.u.info) {
				conflict = true;
				lh.v.u.ind_idx = extra;  /* previous assignment will use safe copy */
			}
		}
	}
	if (conflict) {
	    /* copy upvalue/local value to a temporary (in position 'extra') */
	    int op = (v.k == VLOCAL) ? Lua.OP_MOVE : Lua.OP_GETUPVAL;
	    fs.codeABC(op, extra, v.u.info, 0);
	    fs.reserveregs(1);
	}
}
 
Example 12
Source Project: HtmlNative   Source File: LexState.java    License: Apache License 2.0 6 votes vote down vote up
void forbody(int base, int line, int nvars, boolean isnum) {
	/* forbody -> DO block */
	BlockCnt bl = new BlockCnt();
	FuncState fs = this.fs;
	int prep, endfor;
	this.adjustlocalvars(3); /* control variables */
	this.checknext(TK_DO);
	prep = isnum ? fs.codeAsBx(Lua.OP_FORPREP, base, NO_JUMP) : fs.jump();
	fs.enterblock(bl, false); /* scope for declared variables */
	this.adjustlocalvars(nvars);
	fs.reserveregs(nvars);
	this.block();
	fs.leaveblock(); /* end of scope for declared variables */
	fs.patchtohere(prep);
	if (isnum)  /* numeric for? */
		endfor = fs.codeAsBx(Lua.OP_FORLOOP, base, NO_JUMP);
	else {  /* generic for */
		fs.codeABC(Lua.OP_TFORCALL, base, 0, nvars);
		fs.fixline(line);
		endfor = fs.codeAsBx(Lua.OP_TFORLOOP, base + 2, NO_JUMP);
	}
	fs.patchlist(endfor, prep + 1);
	fs.fixline(line);
}
 
Example 13
Source Project: HtmlNative   Source File: LexState.java    License: Apache License 2.0 6 votes vote down vote up
void fornum(LuaString varname, int line) {
	/* fornum -> NAME = exp1,exp1[,exp1] forbody */
	FuncState fs = this.fs;
	int base = fs.freereg;
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_INDEX);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_LIMIT);
	this.new_localvarliteral(RESERVED_LOCAL_VAR_FOR_STEP);
	this.new_localvar(varname);
	this.checknext('=');
	this.exp1(); /* initial value */
	this.checknext(',');
	this.exp1(); /* limit */
	if (this.testnext(','))
		this.exp1(); /* optional step */
	else { /* default step = 1 */
		fs.codeABx(Lua.OP_LOADK, fs.freereg, fs.numberK(LuaInteger.valueOf(1)));
		fs.reserveregs(1);
	}
	this.forbody(base, line, 1, true);
}
 
Example 14
Source Project: luaj   Source File: ProtoInfo.java    License: MIT License 6 votes vote down vote up
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 15
Source Project: luaj   Source File: LexState.java    License: MIT License 6 votes vote down vote up
void recfield(ConsControl cc) {
	/* recfield -> (NAME | `['exp1`]') = exp1 */
	FuncState fs = this.fs;
	int reg = this.fs.freereg;
	expdesc key = new expdesc();
	expdesc val = new expdesc();
	int rkkey;
	if (this.t.token == TK_NAME) {
		fs.checklimit(cc.nh, MAX_INT, "items in a constructor");
		this.checkname(key);
	} else
		/* this.t.token == '[' */
		this.yindex(key);
	cc.nh++;
	this.checknext('=');
	rkkey = fs.exp2RK(key);
	this.expr(val);
	fs.codeABC(Lua.OP_SETTABLE, cc.t.u.info, rkkey, fs.exp2RK(val));
	fs.freereg = (short)reg; /* free registers */
}
 
Example 16
Source Project: luaj   Source File: LexState.java    License: MIT License 6 votes vote down vote up
void check_conflict (LHS_assign lh, expdesc v) {
	FuncState fs = this.fs;
	short extra = (short) fs.freereg;  /* eventual position to save local variable */
	boolean conflict = false;
	for (; lh!=null; lh = lh.prev) {
		if (lh.v.k == VINDEXED) {
			/* table is the upvalue/local being assigned now? */
			if (lh.v.u.ind_vt == v.k && lh.v.u.ind_t == v.u.info) {
				conflict = true;
				lh.v.u.ind_vt = VLOCAL;
				lh.v.u.ind_t = extra;  /* previous assignment will use safe copy */
			}
			/* index is the local being assigned? (index cannot be upvalue) */
			if (v.k == VLOCAL && lh.v.u.ind_idx == v.u.info) {
				conflict = true;
				lh.v.u.ind_idx = extra;  /* previous assignment will use safe copy */
			}
		}
	}
	if (conflict) {
	    /* copy upvalue/local value to a temporary (in position 'extra') */
	    int op = (v.k == VLOCAL) ? Lua.OP_MOVE : Lua.OP_GETUPVAL;
	    fs.codeABC(op, extra, v.u.info, 0);
	    fs.reserveregs(1);
	}
}
 
Example 17
Source Project: luaj   Source File: LexState.java    License: MIT License 6 votes vote down vote up
void forbody(int base, int line, int nvars, boolean isnum) {
	/* forbody -> DO block */
	BlockCnt bl = new BlockCnt();
	FuncState fs = this.fs;
	int prep, endfor;
	this.adjustlocalvars(3); /* control variables */
	this.checknext(TK_DO);
	prep = isnum ? fs.codeAsBx(Lua.OP_FORPREP, base, NO_JUMP) : fs.jump();
	fs.enterblock(bl, false); /* scope for declared variables */
	this.adjustlocalvars(nvars);
	fs.reserveregs(nvars);
	this.block();
	fs.leaveblock(); /* end of scope for declared variables */
	fs.patchtohere(prep);
	if (isnum)  /* numeric for? */
		endfor = fs.codeAsBx(Lua.OP_FORLOOP, base, NO_JUMP);
	else {  /* generic for */
		fs.codeABC(Lua.OP_TFORCALL, base, 0, nvars);
		fs.fixline(line);
		endfor = fs.codeAsBx(Lua.OP_TFORLOOP, base + 2, NO_JUMP);
	}
	fs.patchlist(endfor, prep + 1);
	fs.fixline(line);
}
 
Example 18
public int Unop() throws ParseException {
    switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case 83:
            jj_consume_token(83);
        {
            if (true) return Lua.OP_UNM;
        }
        break;
        case NOT:
            jj_consume_token(NOT);
        {
            if (true) return Lua.OP_NOT;
        }
        break;
        case 69:
            jj_consume_token(69);
        {
            if (true) return Lua.OP_LEN;
        }
        break;
        default:
            jj_la1[33] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    throw new Error("Missing return statement in function");
}
 
Example 19
Source Project: VideoOS-Android-SDK   Source File: Exp.java    License: GNU General Public License v3.0 5 votes vote down vote up
static boolean isrightassoc(int op) {
    switch (op) {
        case Lua.OP_CONCAT:
        case Lua.OP_POW:
            return true;
        default:
            return false;
    }
}
 
Example 20
Source Project: VideoOS-Android-SDK   Source File: Exp.java    License: GNU General Public License v3.0 5 votes vote down vote up
static int precedence(int op) {
    switch (op) {
        case Lua.OP_OR:
            return 0;
        case Lua.OP_AND:
            return 1;
        case Lua.OP_LT:
        case Lua.OP_GT:
        case Lua.OP_LE:
        case Lua.OP_GE:
        case Lua.OP_NEQ:
        case Lua.OP_EQ:
            return 2;
        case Lua.OP_CONCAT:
            return 3;
        case Lua.OP_ADD:
        case Lua.OP_SUB:
            return 4;
        case Lua.OP_MUL:
        case Lua.OP_DIV:
        case Lua.OP_MOD:
            return 5;
        case Lua.OP_NOT:
        case Lua.OP_UNM:
        case Lua.OP_LEN:
            return 6;
        case Lua.OP_POW:
            return 7;
        default:
            throw new IllegalStateException("precedence of bad op " + op);
    }
}
 
Example 21
Source Project: VideoOS-Android-SDK   Source File: BaseLib.java    License: GNU General Public License v3.0 5 votes vote down vote up
public LuaValue call(LuaValue modname, LuaValue env) {
        globals = env.checkglobals();
//        globals.finder = this;// finder 由Globals自行设置
        globals.baselib = this;
        env.set("_G", env);
        env.set("_VERSION", Lua._VERSION);
        env.set("assert", new _assert());
        env.set("collectgarbage", new collectgarbage());
//        env.set("dofile", new dofile());//TODO 裁剪掉for LuaView
        env.set("error", new error());
        env.set("getmetatable", new getmetatable());
        env.set("load", new load());
        env.set("loadfile", new loadfile());
        env.set("pcall", new pcall());
        env.set("print", new print(this));
        env.set("rawequal", new rawequal());
        env.set("rawget", new rawget());
        env.set("rawlen", new rawlen());
        env.set("rawset", new rawset());
        env.set("select", new select());
        env.set("setmetatable", new setmetatable());
        env.set("tonumber", new tonumber());
        env.set("tostring", new tostring());
        env.set("type", new type());
        env.set("xpcall", new xpcall());

        //extend for luaview
        new com.taobao.luaview.vm.extend.BaseLib(this, globals).extend(env);

        next next;
        env.set("next", next = new next());
        env.set("pairs", new pairs(next));
        env.set("ipairs", new ipairs());

        return env;
    }
 
Example 22
Source Project: VideoOS-Android-SDK   Source File: LexState.java    License: GNU General Public License v3.0 5 votes vote down vote up
void lexerror(String msg, int token) {
        String cid = Lua.chunkid(source.tojstring());
        L.pushfstring(cid + ":" + linenumber + ": " + msg);
        if (token != 0)
            L.pushfstring("syntax error: " + msg + " near " + txtToken(token));
//		throw new LuaError(cid+":"+linenumber+": "+msg);
        throw new LuaError(cid + ":" + linenumber + ": " + msg + " near " + txtToken(token));//modified by song
    }
 
Example 23
Source Project: VideoOS-Android-SDK   Source File: LexState.java    License: GNU General Public License v3.0 5 votes vote down vote up
void retstat() {
/* stat -> RETURN explist */
      FuncState fs = this.fs;
      expdesc e = new expdesc();
      int first, nret; /* registers with returned values */
      if (block_follow(true) || this.t.token == ';')
          first = nret = 0; /* return no values */
      else {
          nret = this.explist(e); /* optional return values */
          if (hasmultret(e.k)) {
              fs.setmultret(e);
              if (e.k == VCALL && nret == 1) { /* tail call? */
                  LuaC.SET_OPCODE(fs.getcodePtr(e), Lua.OP_TAILCALL);
                  LuaC._assert(Lua.GETARG_A(fs.getcode(e)) == fs.nactvar);
              }
              first = fs.nactvar;
              nret = Lua.LUA_MULTRET; /* return all values */
          } else {
              if (nret == 1) /* only one single value? */
                  first = fs.exp2anyreg(e);
              else {
                  fs.exp2nextreg(e); /* values must go to the `stack' */
                  first = fs.nactvar; /* return all `active' values */
                  LuaC._assert(nret == fs.freereg - first);
              }
          }
      }
      fs.ret(first, nret);
      testnext(';');  /* skip optional semicolon */
  }
 
Example 24
boolean patchtestreg(int node, int reg) {
	InstructionPtr i = this.getjumpcontrol(node);
	if (GET_OPCODE(i.get()) != OP_TESTSET)
		/* cannot patch other instructions */
		return false;
	if (reg != NO_REG && reg != GETARG_B(i.get()))
		SETARG_A(i, reg);
	else
		/* no register to put value or register already has the value */
		i.set(CREATE_ABC(OP_TEST, GETARG_B(i.get()), 0, Lua.GETARG_C(i.get())));

	return true;
}
 
Example 25
void invertjump(expdesc e) {
	InstructionPtr pc = this.getjumpcontrol(e.u.info);
	_assert (testTMode(GET_OPCODE(pc.get()))
			&& GET_OPCODE(pc.get()) != OP_TESTSET && Lua
			.GET_OPCODE(pc.get()) != OP_TEST);
	// SETARG_A(pc, !(GETARG_A(pc.get())));
	int a = GETARG_A(pc.get());
	int nota = (a!=0? 0: 1);
	SETARG_A(pc, nota);
}
 
Example 26
Source Project: XPrivacyLua   Source File: DebugLib.java    License: GNU General Public License v3.0 5 votes vote down vote up
static NameWhat getfuncname(DebugLib.CallFrame frame) {
	if (!frame.f.isclosure())
		return new NameWhat(frame.f.classnamestub(), "Java");
	Prototype p = frame.f.checkclosure().p;
	int pc = frame.pc;
	int i = p.code[pc]; /* calling instruction */
	LuaString tm;
	switch (Lua.GET_OPCODE(i)) {
		case Lua.OP_CALL:
		case Lua.OP_TAILCALL: /* get function name */
			return getobjname(p, pc, Lua.GETARG_A(i));
		case Lua.OP_TFORCALL: /* for iterator */
	    	return new NameWhat("(for iterator)", "(for iterator");
	    /* all other instructions can call only through metamethods */
	    case Lua.OP_SELF:
	    case Lua.OP_GETTABUP:
	    case Lua.OP_GETTABLE: tm = LuaValue.INDEX; break;
	    case Lua.OP_SETTABUP:
	    case Lua.OP_SETTABLE: tm = LuaValue.NEWINDEX; break;
	    case Lua.OP_EQ: tm = LuaValue.EQ; break;
	    case Lua.OP_ADD: tm = LuaValue.ADD; break;
	    case Lua.OP_SUB: tm = LuaValue.SUB; break;
	    case Lua.OP_MUL: tm = LuaValue.MUL; break;
	    case Lua.OP_DIV: tm = LuaValue.DIV; break;
	    case Lua.OP_MOD: tm = LuaValue.MOD; break;
	    case Lua.OP_POW: tm = LuaValue.POW; break;
	    case Lua.OP_UNM: tm = LuaValue.UNM; break;
	    case Lua.OP_LEN: tm = LuaValue.LEN; break;
	    case Lua.OP_LT: tm = LuaValue.LT; break;
	    case Lua.OP_LE: tm = LuaValue.LE; break;
	    case Lua.OP_CONCAT: tm = LuaValue.CONCAT; break;
	    default:
	      return null;  /* else no useful name can be found */
	}
	return new NameWhat( tm.tojstring(), "metamethod" );
}
 
Example 27
Source Project: XPrivacyLua   Source File: BaseLib.java    License: GNU General Public License v3.0 5 votes vote down vote up
/** Perform one-time initialization on the library by adding base functions
 * to the supplied environment, and returning it as the return value.
 * @param modname the module name supplied if this is loaded via 'require'.
 * @param env the environment to load into, which must be a Globals instance.
 */
public LuaValue call(LuaValue modname, LuaValue env) {
	globals = env.checkglobals();
	globals.finder = this;
	globals.baselib = this;
	env.set( "_G", env );
	env.set( "_VERSION", Lua._VERSION );
	env.set("assert", new _assert());
	env.set("collectgarbage", new collectgarbage());
	env.set("dofile", new dofile());
	env.set("error", new error());
	env.set("getmetatable", new getmetatable());
	env.set("load", new load());
	env.set("loadfile", new loadfile());
	env.set("pcall", new pcall());
	env.set("print", new print(this));
	env.set("rawequal", new rawequal());
	env.set("rawget", new rawget());
	env.set("rawlen", new rawlen());
	env.set("rawset", new rawset());
	env.set("select", new select());
	env.set("setmetatable", new setmetatable());
	env.set("tonumber", new tonumber());
	env.set("tostring", new tostring());
	env.set("type", new type());
	env.set("xpcall", new xpcall());

	next next;
	env.set("next", next = new next());
	env.set("pairs", new pairs(next));
	env.set("ipairs", new ipairs());
	
	return env;
}
 
Example 28
Source Project: XPrivacyLua   Source File: LexState.java    License: GNU General Public License v3.0 5 votes vote down vote up
void lexerror( String msg, int token ) {
	String cid = Lua.chunkid( source.tojstring() );
	L.pushfstring( cid+":"+linenumber+": "+msg );
	if ( token != 0 )
		L.pushfstring( "syntax error: "+msg+" near "+txtToken(token) );
	throw new LuaError(cid+":"+linenumber+": "+msg);
}
 
Example 29
Source Project: XPrivacyLua   Source File: LexState.java    License: GNU General Public License v3.0 5 votes vote down vote up
void retstat() {
	/* stat -> RETURN explist */
	FuncState fs = this.fs;
	expdesc e = new expdesc();
	int first, nret; /* registers with returned values */
	if (block_follow(true) || this.t.token == ';')
		first = nret = 0; /* return no values */
	else {
		nret = this.explist(e); /* optional return values */
		if (hasmultret(e.k)) {
			fs.setmultret(e);
			if (e.k == VCALL && nret == 1) { /* tail call? */
				SET_OPCODE(fs.getcodePtr(e), Lua.OP_TAILCALL);
				_assert (Lua.GETARG_A(fs.getcode(e)) == fs.nactvar);
			}
			first = fs.nactvar;
			nret = Lua.LUA_MULTRET; /* return all values */
		} else {
			if (nret == 1) /* only one single value? */
				first = fs.exp2anyreg(e);
			else {
				fs.exp2nextreg(e); /* values must go to the `stack' */
				first = fs.nactvar; /* return all `active' values */
				_assert (nret == fs.freereg - first);
			}
		}
	}
	fs.ret(first, nret);
	testnext(';');  /* skip optional semicolon */
}
 
Example 30
Source Project: XPrivacyLua   Source File: FuncState.java    License: GNU General Public License v3.0 5 votes vote down vote up
boolean patchtestreg(int node, int reg) {
	InstructionPtr i = this.getjumpcontrol(node);
	if (GET_OPCODE(i.get()) != OP_TESTSET)
		/* cannot patch other instructions */
		return false;
	if (reg != NO_REG && reg != GETARG_B(i.get()))
		SETARG_A(i, reg);
	else
		/* no register to put value or register already has the value */
		i.set(CREATE_ABC(OP_TEST, GETARG_B(i.get()), 0, Lua.GETARG_C(i.get())));

	return true;
}