org.luaj.vm2.compiler.FuncState.BlockCnt Java Examples

The following examples show how to use org.luaj.vm2.compiler.FuncState.BlockCnt. 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 File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
void open_func(FuncState fs, BlockCnt bl) {
    fs.prev = this.fs;  /* linked list of funcstates */
    fs.ls = this;
    this.fs = fs;
    fs.pc = 0;
    fs.lasttarget = -1;
    fs.jpc = new IntPtr(NO_JUMP);
    fs.freereg = 0;
    fs.nk = 0;
    fs.np = 0;
    fs.nups = 0;
    fs.nlocvars = 0;
    fs.nactvar = 0;
    fs.firstlocal = dyd.n_actvar;
    fs.bl = null;
    fs.f.source = this.source;
    fs.f.maxstacksize = 2;  /* registers 0/1 are always valid */
    fs.enterblock(bl, false);
}
 
Example #2
Source File: LexState.java    From luaj with MIT License 6 votes vote down vote up
void forstat(int line) {
	/* forstat -> FOR (fornum | forlist) END */
	FuncState fs = this.fs;
	LuaString varname;
	BlockCnt bl = new BlockCnt();
	fs.enterblock(bl, true); /* scope for loop and control variables */
	this.next(); /* skip `for' */
	varname = this.str_checkname(); /* first variable name */
	switch (this.t.token) {
	case '=':
		this.fornum(varname, line);
		break;
	case ',':
	case TK_IN:
		this.forlist(varname);
		break;
	default:
		this.syntaxerror(LUA_QL("=") + " or " + LUA_QL("in") + " expected");
	}
	this.check_match(TK_END, TK_FOR, line);
	fs.leaveblock(); /* loop scope (`break' jumps to this point) */
}
 
Example #3
Source File: LexState.java    From luaj with 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 #4
Source File: LexState.java    From luaj with MIT License 6 votes vote down vote up
void repeatstat(int line) {
	/* repeatstat -> REPEAT block UNTIL cond */
	int condexit;
	FuncState fs = this.fs;
	int repeat_init = fs.getlabel();
	BlockCnt bl1 = new BlockCnt();
	BlockCnt bl2 = new BlockCnt();
	fs.enterblock(bl1, true); /* loop block */
	fs.enterblock(bl2, false); /* scope block */
	this.next(); /* skip REPEAT */
	this.statlist();
	this.check_match(TK_UNTIL, TK_REPEAT, line);
	condexit = this.cond(); /* read condition (inside scope block) */
	if (bl2.upval) { /* upvalues? */
	    fs.patchclose(condexit, bl2.nactvar);
	}
	fs.leaveblock(); /* finish scope */
	fs.patchlist(condexit, repeat_init); /* close the loop */
	fs.leaveblock(); /* finish loop */
}
 
Example #5
Source File: LexState.java    From luaj with MIT License 6 votes vote down vote up
void whilestat (int line) {
	/* whilestat -> WHILE cond DO block END */
	FuncState fs = this.fs;
	int whileinit;
	int condexit;
	BlockCnt bl = new BlockCnt();
	this.next();  /* skip WHILE */
	whileinit = fs.getlabel();
	condexit = this.cond();
	fs.enterblock(bl, true);
	this.checknext(TK_DO);
	this.block();
	fs.patchlist(fs.jump(), whileinit);
	this.check_match(TK_END, TK_WHILE, line);
	fs.leaveblock();
	fs.patchtohere(condexit);  /* false conditions finish the loop */
}
 
Example #6
Source File: LexState.java    From luaj with MIT License 6 votes vote down vote up
void body(expdesc e, boolean needself, int line) {
	/* body -> `(' parlist `)' chunk END */
	FuncState new_fs = new FuncState();
	BlockCnt bl = new BlockCnt();
	new_fs.f = addprototype();
	new_fs.f.linedefined = line;
	open_func(new_fs, bl);
	this.checknext('(');
	if (needself) {
		new_localvarliteral("self");
		adjustlocalvars(1);
	}
	this.parlist();
	this.checknext(')');
	this.statlist();
	new_fs.f.lastlinedefined = this.linenumber;
	this.check_match(TK_END, TK_FUNCTION, line);
	this.codeclosure(e);
	this.close_func();
}
 
Example #7
Source File: LexState.java    From luaj with MIT License 6 votes vote down vote up
void open_func (FuncState fs, BlockCnt bl) {
	  fs.prev = this.fs;  /* linked list of funcstates */
	  fs.ls = this;
	  this.fs = fs;
	  fs.pc = 0;
	  fs.lasttarget = -1;
	  fs.jpc = new IntPtr( NO_JUMP );
	  fs.freereg = 0;
	  fs.nk = 0;
	  fs.np = 0;
	  fs.nups = 0;
	  fs.nlocvars = 0;
	  fs.nactvar = 0;
	  fs.firstlocal = dyd.n_actvar;
	  fs.bl = null;
	  fs.f.source = this.source;
	  fs.f.maxstacksize = 2;  /* registers 0/1 are always valid */
	  fs.enterblock(bl,  false);
}
 
Example #8
Source File: LexState.java    From luaj with MIT License 6 votes vote down vote up
boolean findlabel (int g) {
	int i;
	BlockCnt bl = fs.bl;
	Dyndata dyd = this.dyd;
	Labeldesc gt = dyd.gt[g];
	/* check labels in current block for a match */
	for (i = bl.firstlabel; i < dyd.n_label; i++) {
		Labeldesc lb = dyd.label[i];
		if (lb.name.eq_b(gt.name)) {  /* correct label? */
			if (gt.nactvar > lb.nactvar &&
					(bl.upval || dyd.n_label > bl.firstlabel))
				fs.patchclose(gt.pc, lb.nactvar);
			closegoto(g, lb);  /* close it */
			return true;
		}
	}
	return false;  /* label not found; cannot close goto */
}
 
Example #9
Source File: LexState.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
void forstat(int line) {
	/* forstat -> FOR (fornum | forlist) END */
	FuncState fs = this.fs;
	LuaString varname;
	BlockCnt bl = new BlockCnt();
	fs.enterblock(bl, true); /* scope for loop and control variables */
	this.next(); /* skip `for' */
	varname = this.str_checkname(); /* first variable name */
	switch (this.t.token) {
	case '=':
		this.fornum(varname, line);
		break;
	case ',':
	case TK_IN:
		this.forlist(varname);
		break;
	default:
		this.syntaxerror(LUA_QL("=") + " or " + LUA_QL("in") + " expected");
	}
	this.check_match(TK_END, TK_FOR, line);
	fs.leaveblock(); /* loop scope (`break' jumps to this point) */
}
 
Example #10
Source File: LexState.java    From HtmlNative with 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 #11
Source File: LexState.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
void repeatstat(int line) {
	/* repeatstat -> REPEAT block UNTIL cond */
	int condexit;
	FuncState fs = this.fs;
	int repeat_init = fs.getlabel();
	BlockCnt bl1 = new BlockCnt();
	BlockCnt bl2 = new BlockCnt();
	fs.enterblock(bl1, true); /* loop block */
	fs.enterblock(bl2, false); /* scope block */
	this.next(); /* skip REPEAT */
	this.statlist();
	this.check_match(TK_UNTIL, TK_REPEAT, line);
	condexit = this.cond(); /* read condition (inside scope block) */
	if (bl2.upval) { /* upvalues? */
	    fs.patchclose(condexit, bl2.nactvar);
	}
	fs.leaveblock(); /* finish scope */
	fs.patchlist(condexit, repeat_init); /* close the loop */
	fs.leaveblock(); /* finish loop */
}
 
Example #12
Source File: LexState.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
void whilestat (int line) {
	/* whilestat -> WHILE cond DO block END */
	FuncState fs = this.fs;
	int whileinit;
	int condexit;
	BlockCnt bl = new BlockCnt();
	this.next();  /* skip WHILE */
	whileinit = fs.getlabel();
	condexit = this.cond();
	fs.enterblock(bl, true);
	this.checknext(TK_DO);
	this.block();
	fs.patchlist(fs.jump(), whileinit);
	this.check_match(TK_END, TK_WHILE, line);
	fs.leaveblock();
	fs.patchtohere(condexit);  /* false conditions finish the loop */
}
 
Example #13
Source File: LexState.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
void body(expdesc e, boolean needself, int line) {
	/* body -> `(' parlist `)' chunk END */
	FuncState new_fs = new FuncState();
	BlockCnt bl = new BlockCnt();
	new_fs.f = addprototype();
	new_fs.f.linedefined = line;
	open_func(new_fs, bl);
	this.checknext('(');
	if (needself) {
		new_localvarliteral("self");
		adjustlocalvars(1);
	}
	this.parlist();
	this.checknext(')');
	this.statlist();
	new_fs.f.lastlinedefined = this.linenumber;
	this.check_match(TK_END, TK_FUNCTION, line);
	this.codeclosure(e);
	this.close_func();
}
 
Example #14
Source File: LexState.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
void open_func (FuncState fs, BlockCnt bl) {
	  fs.prev = this.fs;  /* linked list of funcstates */
	  fs.ls = this;
	  this.fs = fs;
	  fs.pc = 0;
	  fs.lasttarget = -1;
	  fs.jpc = new IntPtr( NO_JUMP );
	  fs.freereg = 0;
	  fs.nk = 0;
	  fs.np = 0;
	  fs.nups = 0;
	  fs.nlocvars = 0;
	  fs.nactvar = 0;
	  fs.firstlocal = dyd.n_actvar;
	  fs.bl = null;
	  fs.f.source = this.source;
	  fs.f.maxstacksize = 2;  /* registers 0/1 are always valid */
	  fs.enterblock(bl,  false);
}
 
Example #15
Source File: LexState.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
boolean findlabel (int g) {
	int i;
	BlockCnt bl = fs.bl;
	Dyndata dyd = this.dyd;
	Labeldesc gt = dyd.gt[g];
	/* check labels in current block for a match */
	for (i = bl.firstlabel; i < dyd.n_label; i++) {
		Labeldesc lb = dyd.label[i];
		if (lb.name.eq_b(gt.name)) {  /* correct label? */
			if (gt.nactvar > lb.nactvar &&
					(bl.upval || dyd.n_label > bl.firstlabel))
				fs.patchclose(gt.pc, lb.nactvar);
			closegoto(g, lb);  /* close it */
			return true;
		}
	}
	return false;  /* label not found; cannot close goto */
}
 
Example #16
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
void forstat(int line) {
	/* forstat -> FOR (fornum | forlist) END */
	FuncState fs = this.fs;
	LuaString varname;
	BlockCnt bl = new BlockCnt();
	fs.enterblock(bl, true); /* scope for loop and control variables */
	this.next(); /* skip `for' */
	varname = this.str_checkname(); /* first variable name */
	switch (this.t.token) {
	case '=':
		this.fornum(varname, line);
		break;
	case ',':
	case TK_IN:
		this.forlist(varname);
		break;
	default:
		this.syntaxerror(LUA_QL("=") + " or " + LUA_QL("in") + " expected");
	}
	this.check_match(TK_END, TK_FOR, line);
	fs.leaveblock(); /* loop scope (`break' jumps to this point) */
}
 
Example #17
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
void repeatstat(int line) {
	/* repeatstat -> REPEAT block UNTIL cond */
	int condexit;
	FuncState fs = this.fs;
	int repeat_init = fs.getlabel();
	BlockCnt bl1 = new BlockCnt();
	BlockCnt bl2 = new BlockCnt();
	fs.enterblock(bl1, true); /* loop block */
	fs.enterblock(bl2, false); /* scope block */
	this.next(); /* skip REPEAT */
	this.statlist();
	this.check_match(TK_UNTIL, TK_REPEAT, line);
	condexit = this.cond(); /* read condition (inside scope block) */
	if (bl2.upval) { /* upvalues? */
	    fs.patchclose(condexit, bl2.nactvar);
	}
	fs.leaveblock(); /* finish scope */
	fs.patchlist(condexit, repeat_init); /* close the loop */
	fs.leaveblock(); /* finish loop */
}
 
Example #18
Source File: LexState.java    From XPrivacyLua with 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 #19
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
void whilestat (int line) {
	/* whilestat -> WHILE cond DO block END */
	FuncState fs = this.fs;
	int whileinit;
	int condexit;
	BlockCnt bl = new BlockCnt();
	this.next();  /* skip WHILE */
	whileinit = fs.getlabel();
	condexit = this.cond();
	fs.enterblock(bl, true);
	this.checknext(TK_DO);
	this.block();
	fs.patchlist(fs.jump(), whileinit);
	this.check_match(TK_END, TK_WHILE, line);
	fs.leaveblock();
	fs.patchtohere(condexit);  /* false conditions finish the loop */
}
 
Example #20
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
boolean findlabel(int g) {
      int i;
      BlockCnt bl = fs.bl;
      Dyndata dyd = this.dyd;
      Labeldesc gt = dyd.gt[g];
/* check labels in current block for a match */
      for (i = bl.firstlabel; i < dyd.n_label; i++) {
          Labeldesc lb = dyd.label[i];
          if (lb.name.eq_b(gt.name)) {  /* correct label? */
              if (gt.nactvar > lb.nactvar &&
                      (bl.upval || dyd.n_label > bl.firstlabel))
                  fs.patchclose(gt.pc, lb.nactvar);
              closegoto(g, lb);  /* close it */
              return true;
          }
      }
      return false;  /* label not found; cannot close goto */
  }
 
Example #21
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
void body(expdesc e, boolean needself, int line) {
	/* body -> `(' parlist `)' chunk END */
	FuncState new_fs = new FuncState();
	BlockCnt bl = new BlockCnt();
	new_fs.f = addprototype();
	new_fs.f.linedefined = line;
	open_func(new_fs, bl);
	this.checknext('(');
	if (needself) {
		new_localvarliteral("self");
		adjustlocalvars(1);
	}
	this.parlist();
	this.checknext(')');
	this.statlist();
	new_fs.f.lastlinedefined = this.linenumber;
	this.check_match(TK_END, TK_FUNCTION, line);
	this.codeclosure(e);
	this.close_func();
}
 
Example #22
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
void body(expdesc e, boolean needself, int line) {
/* body -> `(' parlist `)' chunk END */
      FuncState new_fs = new FuncState();
      BlockCnt bl = new BlockCnt();
      new_fs.f = addprototype();
      new_fs.f.linedefined = line;
      open_func(new_fs, bl);
      this.checknext('(');
      if (needself) {
          new_localvarliteral("self");
          adjustlocalvars(1);
      }
      this.parlist();
      this.checknext(')');
      this.statlist();
      new_fs.f.lastlinedefined = this.linenumber;
      this.check_match(TK_END, TK_FUNCTION, line);
      this.codeclosure(e);
      this.close_func();
  }
 
Example #23
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
void open_func (FuncState fs, BlockCnt bl) {
	  fs.prev = this.fs;  /* linked list of funcstates */
	  fs.ls = this;
	  this.fs = fs;
	  fs.pc = 0;
	  fs.lasttarget = -1;
	  fs.jpc = new IntPtr( NO_JUMP );
	  fs.freereg = 0;
	  fs.nk = 0;
	  fs.np = 0;
	  fs.nups = 0;
	  fs.nlocvars = 0;
	  fs.nactvar = 0;
	  fs.firstlocal = dyd.n_actvar;
	  fs.bl = null;
	  fs.f.source = this.source;
	  fs.f.maxstacksize = 2;  /* registers 0/1 are always valid */
	  fs.enterblock(bl,  false);
}
 
Example #24
Source File: LexState.java    From XPrivacyLua with GNU General Public License v3.0 6 votes vote down vote up
boolean findlabel (int g) {
	int i;
	BlockCnt bl = fs.bl;
	Dyndata dyd = this.dyd;
	Labeldesc gt = dyd.gt[g];
	/* check labels in current block for a match */
	for (i = bl.firstlabel; i < dyd.n_label; i++) {
		Labeldesc lb = dyd.label[i];
		if (lb.name.eq_b(gt.name)) {  /* correct label? */
			if (gt.nactvar > lb.nactvar &&
					(bl.upval || dyd.n_label > bl.firstlabel))
				fs.patchclose(gt.pc, lb.nactvar);
			closegoto(g, lb);  /* close it */
			return true;
		}
	}
	return false;  /* label not found; cannot close goto */
}
 
Example #25
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
void whilestat(int line) {
/* whilestat -> WHILE cond DO block END */
      FuncState fs = this.fs;
      int whileinit;
      int condexit;
      BlockCnt bl = new BlockCnt();
      this.next();  /* skip WHILE */
      whileinit = fs.getlabel();
      condexit = this.cond();
      fs.enterblock(bl, true);
      this.checknext(TK_DO);
      this.block();
      fs.patchlist(fs.jump(), whileinit);
      this.check_match(TK_END, TK_WHILE, line);
      fs.leaveblock();
      fs.patchtohere(condexit);  /* false conditions finish the loop */
  }
 
Example #26
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
void repeatstat(int line) {
/* repeatstat -> REPEAT block UNTIL cond */
      int condexit;
      FuncState fs = this.fs;
      int repeat_init = fs.getlabel();
      BlockCnt bl1 = new BlockCnt();
      BlockCnt bl2 = new BlockCnt();
      fs.enterblock(bl1, true); /* loop block */
      fs.enterblock(bl2, false); /* scope block */
      this.next(); /* skip REPEAT */
      this.statlist();
      this.check_match(TK_UNTIL, TK_REPEAT, line);
      condexit = this.cond(); /* read condition (inside scope block) */
      if (bl2.upval) { /* upvalues? */
          fs.patchclose(condexit, bl2.nactvar);
      }
      fs.leaveblock(); /* finish scope */
      fs.patchlist(condexit, repeat_init); /* close the loop */
      fs.leaveblock(); /* finish loop */
  }
 
Example #27
Source File: LexState.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
void forstat(int line) {
/* forstat -> FOR (fornum | forlist) END */
      FuncState fs = this.fs;
      LuaString varname;
      BlockCnt bl = new BlockCnt();
      fs.enterblock(bl, true); /* scope for loop and control variables */
      this.next(); /* skip `for' */
      varname = this.str_checkname(); /* first variable name */
      switch (this.t.token) {
          case '=':
              this.fornum(varname, line);
              break;
          case ',':
          case TK_IN:
              this.forlist(varname);
              break;
          default:
              this.syntaxerror(LUA_QL("=") + " or " + LUA_QL("in") + " expected");
      }
      this.check_match(TK_END, TK_FOR, line);
      fs.leaveblock(); /* loop scope (`break' jumps to this point) */
  }
 
Example #28
Source File: LexState.java    From VideoOS-Android-SDK with 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 #29
Source File: LexState.java    From luaj with MIT License 5 votes vote down vote up
public void mainfunc(FuncState funcstate) {
	  BlockCnt bl = new BlockCnt();
	  open_func(funcstate, bl);
	  fs.f.is_vararg = 1;  /* main function is always vararg */
	  expdesc v = new expdesc();
	  v.init(VLOCAL, 0);  /* create and... */
	  fs.newupvalue(envn, v);  /* ...set environment upvalue */
	  next();  /* read first token */
	  statlist();  /* parse main body */
	  check(TK_EOS);
	  close_func();
}
 
Example #30
Source File: LexState.java    From luaj with MIT License 5 votes vote down vote up
void test_then_block(IntPtr escapelist) {
	/* test_then_block -> [IF | ELSEIF] cond THEN block */
	expdesc v = new expdesc();
	BlockCnt bl = new BlockCnt();
	int jf;  /* instruction to skip 'then' code (if condition is false) */
	this.next(); /* skip IF or ELSEIF */
	expr(v);  /* read expression */
	this.checknext(TK_THEN);
	if (t.token == TK_GOTO || t.token == TK_BREAK) {
		fs.goiffalse(v); /* will jump to label if condition is true */
		fs.enterblock(bl, false); /* must enter block before 'goto' */
		gotostat(v.t.i); /* handle goto/break */
		skipnoopstat(); /* skip other no-op statements */
		if (block_follow(false)) { /* 'goto' is the entire block? */
			fs.leaveblock();
			return; /* and that is it */
		} else
			/* must skip over 'then' part if condition is false */
			jf = fs.jump();
	} else { /* regular case (not goto/break) */
		fs.goiftrue(v); /* skip over block if condition is false */
		fs.enterblock(bl, false);
		jf = v.f.i;
	}
	statlist(); /* `then' part */
	fs.leaveblock();
	if (t.token == TK_ELSE || t.token == TK_ELSEIF)
		fs.concat(escapelist, fs.jump()); /* must jump over it */
	fs.patchtohere(jf);
}