Ejemplo n.º 1
0
static void close_func (LexState *ls) {
  lua_State *L = ls->L;
  FuncState *fs = ls->fs;
  Proto *f = fs->f;
  removevars(ls, 0);
  luaK_codeABC(fs, OP_RETURN, 0, 1, 0);  /* final return */
  luaM_setname(L, "Lua_parser_code");
  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
  f->sizecode = fs->pc;
  luaM_setname(L, "Lua_parser_lineinfo");
  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
  f->sizelineinfo = fs->pc;
  luaM_setname(L, "Lua_parser_constants");
  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject);
  f->sizek = fs->nk;
  luaM_setname(L, "Lua_parser_proto");
  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
  f->sizep = fs->np;
  luaM_setname(L, "Lua_parser_locals");
  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
  f->sizelocvars = fs->nlocvars;
  luaM_setname(L, "Lua_parser_upvalues");
  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);
  f->sizeupvalues = f->nups;
  lua_assert(luaG_checkcode(f));
  lua_assert(fs->bl == NULL);
  ls->fs = fs->prev;
#if LUA_REFCOUNT
  __ReleaseDirect(L, (GCObject*)fs->h);
#endif LUA_REFCOUNT
}
Ejemplo n.º 2
0
static void close_func (LexState *ls) {
  lua_State *L = ls->L;
  FuncState *fs = ls->fs;
  Proto *f = fs->f;
  removevars(ls, 0);
  luaK_ret(fs, 0, 0);  /* final return */
  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
  f->sizecode = fs->pc;
  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
  f->sizelineinfo = fs->pc;
  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
  f->sizek = fs->nk;
  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
  f->sizep = fs->np;
  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
  f->sizelocvars = fs->nlocvars;
  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);
  f->sizeupvalues = f->nups;
  lua_assert(luaG_checkcode(f));
  lua_assert(fs->bl == NULL);
  ls->fs = fs->prev;
  L->top -= 2;  /* remove table and prototype from the stack */
  /* last token read was anchored in defunct function; must reanchor it */
  if (fs) anchor_token(ls);
}
Ejemplo n.º 3
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 */
}
Ejemplo n.º 4
0
static void leaveblock (FuncState *fs) {
  BlockCnt *bl = fs->bl;
  fs->bl = bl->previous;
  removevars(fs->ls, bl->nactvar);
  if (bl->upval)
    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
  lua_assert(bl->nactvar == fs->nactvar);
  fs->freereg = fs->nactvar;  /* free registers */
  luaK_patchtohere(fs, bl->breaklist);
}
Ejemplo n.º 5
0
static void leaveblock (FuncState *fs) {
  BlockCnt *bl = fs->bl;
  fs->bl = bl->previous;
  removevars(fs->ls, bl->nactvar);
  if (bl->upval)
    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0);
  /* a block either controls scope or breaks (never both) */
  lua_assert(!bl->isbreakable || !bl->upval);
  lua_assert(bl->nactvar == fs->nactvar);
  fs->freereg = fs->nactvar;  /* free registers */
  luaK_patchtohere(fs, bl->breaklist);
}
Ejemplo n.º 6
0
static void close_func (LexState *ls) {
  lua_State *L = ls->L;
  FuncState *fs = ls->fs;
  Proto *f = fs->f;
  removevars(ls, 0);
  luaK_ret(fs, 0, 0);  /* final return */
#if LUA_MEMORY_STATS
  luaM_setname(L, "lua.parser.code");
#endif /* LUA_MEMORY_STATS */
  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
  f->sizecode = fs->pc;
#if LUA_MEMORY_STATS
  luaM_setname(L, "lua.parser.lineinfo");
#endif /* LUA_MEMORY_STATS */
  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
  f->sizelineinfo = fs->pc;
#if LUA_MEMORY_STATS
  luaM_setname(L, "lua.parser.constants");
#endif /* LUA_MEMORY_STATS */
  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TValue);
  f->sizek = fs->nk;
#if LUA_MEMORY_STATS
  luaM_setname(L, "lua.parser.proto");
#endif /* LUA_MEMORY_STATS */
  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
  f->sizep = fs->np;
#if LUA_MEMORY_STATS
  luaM_setname(L, "lua.parser.locals");
#endif /* LUA_MEMORY_STATS */
  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
  f->sizelocvars = fs->nlocvars;
#if LUA_MEMORY_STATS
  luaM_setname(L, "lua.parser.upvalues");
#endif /* LUA_MEMORY_STATS */
  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);
#if LUA_MEMORY_STATS
  luaM_setname(L, 0);
#endif /* LUA_MEMORY_STATS */
  f->sizeupvalues = f->nups;
  lua_assert(luaG_checkcode(f));
  lua_assert(fs->bl == NULL);
  ls->fs = fs->prev;
  L->top -= 2;  /* remove table and prototype from the stack */
  /* last token read was anchored in defunct function; must reanchor it */
  if (fs) anchor_token(ls);
#if LUA_REFCOUNT
  setnilvalue(L->top + 1);
  setnilvalue(L->top);
  luarc_releasetable(L, fs->h);
#endif /* LUA_REFCOUNT */
}
static void close_func (LexState *ls) {
  lua_State *L = ls->L;
  global_State *g = G(L);
  FuncState *fs = ls->fs;
  Proto *f = fs->f;
  removevars(ls, 0);
  luaK_ret(fs, 0, 0);  /* final return */
  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
  f->sizecode = fs->pc;
	if ( g->storedebug )	/* save memory when debugger will not be used */
	{
	  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
	  f->sizelineinfo = fs->pc;
	}
Ejemplo n.º 8
0
static void exprstat (LexState *ls) {
  /* stat -> func | assignment */
  FuncState *fs = ls->fs;
  struct LHS_assign v;
  primaryexp(ls, &v.v);
  if (v.v.k == VCALL)  /* stat -> func */
    SETARG_C(getcode(fs, &v.v), 1);  /* call statement uses no results */
  else {  /* stat -> assignment */
    lu_byte from_var;
    v.prev = NULL;
    if (assignment(ls, &v, 1, &from_var))
      removevars(ls, from_var);
  }
}
Ejemplo n.º 9
0
static void localstat (LexState *ls) {
  /* stat -> LOCAL NAME {`,' NAME} [ IN primaryexp | `=' explist1] */
  int nvars = 0;
  int nexps;
  expdesc e;
  do {
    new_localvar(ls, str_checkname(ls), nvars++);
  } while (testnext(ls, ','));
  
  if (testnext(ls, TK_IN)) {
    lu_byte from_var;
    int regs = ls->fs->freereg;
    int vars = ls->fs->nactvar;

    luaK_reserveregs(ls->fs, nvars);
    adjustlocalvars(ls, nvars);

    new_localvarliteral(ls, "(from)", 0);
    primaryexp(ls, &e);
    luaK_exp2nextreg(ls->fs, &e);
    from_var = ls->fs->nactvar;
    adjustlocalvars(ls, 1);
    luaK_setoneret(ls->fs, &e);  /* close last expression */

    for (nexps=0; nexps<nvars; nexps++) {
      expdesc v, key;
      init_exp(&e, VNONRELOC, ls->fs->freereg-1);
      codestring(ls, &key, getlocvar(ls->fs, vars+nexps).varname);
      luaK_indexed(ls->fs, &e, &key);
      init_exp(&v, VLOCAL, regs+nexps);
      luaK_storevar(ls->fs, &v, &e);
    }
    removevars(ls, from_var);
    return;
  }
  
  if (testnext(ls, '='))
    nexps = explist1(ls, &e);
  else {
    e.k = VVOID;
    nexps = 0;
  }
  adjust_assign(ls, nvars, nexps, &e);
  adjustlocalvars(ls, nvars);
}
Ejemplo n.º 10
0
/*static*/ void FuncState::leaveblock (/*FuncState *fs*/) {
	//BlockCnt *bl = fs->bl;
	//LexState *ls = fs->ls;
	if (bl->previous && bl->upval) {
		/* create a 'jump to here' to close upvalues */
		int j = luaK_jump();
		luaK_patchclose(j, bl->nactvar);
		luaK_patchtohere(j);
	}
	if (bl->isloop)
		ls->breaklabel();  /* close pending breaks */
	bl = bl->previous;
	removevars(bl->nactvar);
	lua_assert(bl->nactvar == nactvar);
	free_reg = nactvar;  /* free registers */
	ls->dyd->label.n = bl->firstlabel;  /* remove local labels */
	if (bl->previous)  /* inner block? */
		movegotosout(bl);  /* update pending gotos to outer block */
	else if (bl->firstgoto < ls->dyd->gt.n)  /* pending gotos in outer block? */
		ls->undefgoto(&ls->dyd->gt.arr[bl->firstgoto]);  /* error */
}
Ejemplo n.º 11
0
static void close_func (LexState *ls) {
  lua_State *L = ls->L;
  FuncState *fs = ls->fs;
  Proto *f = fs->f;
  removevars(ls, 0);
  luaK_codeABC(fs, OP_RETURN, 0, 1, 0);  /* final return */
  luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
  f->sizecode = fs->pc;
  luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc, int);
  f->sizelineinfo = fs->pc;
  luaM_reallocvector(L, f->k, f->sizek, fs->nk, TObject);
  f->sizek = fs->nk;
  luaM_reallocvector(L, f->p, f->sizep, fs->np, Proto *);
  f->sizep = fs->np;
  luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar);
  f->sizelocvars = fs->nlocvars;
  luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups, TString *);
  f->sizeupvalues = f->nups;
  lua_assert(luaG_checkcode(f));
  lua_assert(fs->bl == NULL);
  ls->fs = fs->prev;
}
Ejemplo n.º 12
0
static void leaveblock (FuncState *fs)
{
    BlockCnt *bl = (BlockCnt*)fs->blockList.GetFirst();

    // Remove the current block from visibility.
    fs->blockList.RemoveFirst();

    removevars(fs->ls, bl->nactvar);

    if ( bl->upval )
    {
        luaK_codeABC( fs, OP_CLOSE, bl->nactvar, 0, 0 );
    }

    /* a block either controls scope or breaks (never both) */
    lua_assert(!bl->isbreakable || !bl->upval);
    lua_assert(bl->nactvar == fs->nactvar);

    fs->freereg = fs->nactvar;  /* free registers */

    luaK_patchtohere(fs, bl->breaklist);
}
Ejemplo n.º 13
0
static void close_func (LexState *ls)
{
    lua_State *L = ls->L;
    FuncState *fs = (FuncState*)ls->fsList.GetFirst();
    Proto *f = fs->f;

    removevars(ls, 0);
    luaK_ret(fs, 0, 0);  /* final return */
    luaM_reallocvector(L, f->code, f->sizecode, fs->pc);
    f->sizecode = fs->pc;
    luaM_reallocvector(L, f->lineinfo, f->sizelineinfo, fs->pc);
    f->sizelineinfo = fs->pc;
    luaM_reallocvector(L, f->k, f->sizek, fs->nk);
    f->sizek = fs->nk;
    luaM_reallocvector(L, f->p, f->sizep, fs->np);
    f->sizep = fs->np;
    luaM_reallocvector(L, f->locvars, f->sizelocvars, fs->nlocvars);
    f->sizelocvars = fs->nlocvars;
    luaM_reallocvector(L, f->upvalues, f->sizeupvalues, f->nups);
    f->sizeupvalues = f->nups;
    lua_assert(luaG_checkcode(f) == true);
    lua_assert(fs->blockList.IsEmpty() == true);
    
    // Remove this function state from existence.
    ls->fsList.RemoveFirst();

    // Dereference the table again.
    // We keep the reference on the proto, because it is the result object.
    fs->h->DereferenceGC( L );

    /* last token read was anchored in defunct function; must reanchor it */
    if ( fs )
    {
        anchor_token(ls);
    }
}