Esempio n. 1
0
static void leaveblock(ktap_funcstate *fs)
{
	ktap_blockcnt *bl = fs->bl;
	ktap_lexstate *ls = fs->ls;
	if (bl->previous && bl->upval) {
		/* create a 'jump to here' to close upvalues */
		int j = codegen_jump(fs);

		codegen_patchclose(fs, j, bl->nactvar);
		codegen_patchtohere(fs, j);
	}

	if (bl->isloop)
		breaklabel(ls);  /* close pending breaks */

	fs->bl = bl->previous;
	removevars(fs, bl->nactvar);
	ktap_assert(bl->nactvar == fs->nactvar);
	fs->freereg = fs->nactvar;  /* free registers */
	ls->dyd->label.n = bl->firstlabel;  /* remove local labels */
	if (bl->previous)  /* inner block? */
		movegotosout(fs, bl);  /* update pending gotos to outer block */
	else if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */
		undefgoto(ls, &ls->dyd->gt.arr[bl->firstgoto]);  /* error */
}
Esempio n. 2
0
File: code.c Progetto: WeiY/ktap
void codegen_patchlist(FuncState *fs, int list, int target)
{
	if (target == fs->pc)
		codegen_patchtohere(fs, list);
	else {
		ktap_assert(target < fs->pc);
		patchlistaux(fs, list, target, NO_REG, target);
	}
}
Esempio n. 3
0
File: code.c Progetto: WeiY/ktap
static void exp2reg(FuncState *fs, expdesc *e, int reg)
{
	discharge2reg(fs, e, reg);
	if (e->k == VJMP)
		codegen_concat(fs, &e->t, e->u.info);  /* put this jump in `t' list */
	if (hasjumps(e)) {
		int final;  /* position after whole expression */
		int p_f = NO_JUMP;  /* position of an eventual LOAD false */
		int p_t = NO_JUMP;  /* position of an eventual LOAD true */

		if (need_value(fs, e->t) || need_value(fs, e->f)) {
			int fj = (e->k == VJMP) ? NO_JUMP : codegen_jump(fs);

			p_f = code_label(fs, reg, 0, 1);
			p_t = code_label(fs, reg, 1, 0);
			codegen_patchtohere(fs, fj);
		}
		final = codegen_getlabel(fs);
		patchlistaux(fs, e->f, final, reg, p_f);
		patchlistaux(fs, e->t, final, reg, p_t);
	}