Search in sources :

Example 1 with BlockCnt

use of org.luaj.vm2.compiler.FuncState.BlockCnt in project LuaViewSDK by alibaba.

the class LexState method forstat.

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) */
}
Also used : BlockCnt(org.luaj.vm2.compiler.FuncState.BlockCnt) LuaString(org.luaj.vm2.LuaString)

Example 2 with BlockCnt

use of org.luaj.vm2.compiler.FuncState.BlockCnt in project LuaViewSDK by alibaba.

the class LexState method whilestat.

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 */
}
Also used : BlockCnt(org.luaj.vm2.compiler.FuncState.BlockCnt)

Example 3 with BlockCnt

use of org.luaj.vm2.compiler.FuncState.BlockCnt in project LuaViewSDK by alibaba.

the class LexState method test_then_block.

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);
}
Also used : BlockCnt(org.luaj.vm2.compiler.FuncState.BlockCnt)

Example 4 with BlockCnt

use of org.luaj.vm2.compiler.FuncState.BlockCnt in project LuaViewSDK by alibaba.

the class LexState method forbody.

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);
}
Also used : BlockCnt(org.luaj.vm2.compiler.FuncState.BlockCnt)

Example 5 with BlockCnt

use of org.luaj.vm2.compiler.FuncState.BlockCnt in project LuaViewSDK by alibaba.

the class LexState method repeatstat.

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 */
}
Also used : BlockCnt(org.luaj.vm2.compiler.FuncState.BlockCnt)

Aggregations

BlockCnt (org.luaj.vm2.compiler.FuncState.BlockCnt)9 LuaString (org.luaj.vm2.LuaString)1