Exemplo n.º 1
0
static int registerlocalvar (LexState *ls, TString *varname) {
  FuncState *fs = ls->fs;
  Proto *f = fs->f;
  int oldsize = f->sizelocvars;
  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
                  LocVar, SHRT_MAX, "too many local variables");
  while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
  f->locvars[fs->nlocvars].varname = varname;
  luaC_objbarrier(ls->L, f, varname);
  return fs->nlocvars++;
}
Exemplo n.º 2
0
Arquivo: lcode.cpp Projeto: swizl/lua
/*static*/ int FuncState::luaK_code (/*FuncState *fs,*/ Instruction i) {
	//Proto *f = fs->f;
	dischargejpc();  /* 'pc' will change */
	/* put new instruction in code array */
	luaM_growvector(ls->L, f->code, pc, f->sizecode, Instruction, MAX_INT, "opcodes");
	f->code[pc] = i;
	/* save corresponding line information */
	luaM_growvector(ls->L, f->lineinfo, pc, f->sizelineinfo, int, MAX_INT, "opcodes");
	f->lineinfo[pc] = ls->lastline;
	return pc++;
}
Exemplo n.º 3
0
Arquivo: lparser.c Projeto: bcrist/lua
static int newlabelentry (LexState *ls, Labellist *l, TString *name,
                          int line, int pc) {
  int n = l->n;
  luaM_growvector(ls->L, l->arr, n, l->size,
                  Labeldesc, SHRT_MAX, "labels/gotos");
  l->arr[n].name = name;
  l->arr[n].line = line;
  l->arr[n].nactvar = ls->fs->nactvar;
  l->arr[n].pc = pc;
  l->n = n + 1;
  return n;
}
Exemplo n.º 4
0
static void new_localvar(LexState *ls, TString *name)
{
    FuncState *fs  = ls->fs;
    Dyndata   *dyd = ls->dyd;
    int       reg  = registerlocalvar(ls, name);

    checklimit(fs, dyd->actvar.n + 1 - fs->firstlocal,
               MAXVARS, "local variables");
    luaM_growvector(ls->L, dyd->actvar.arr, dyd->actvar.n + 1,
                    dyd->actvar.size, Vardesc, MAX_INT, "local variables");
    dyd->actvar.arr[dyd->actvar.n++].idx = cast(short, reg);
}
Exemplo n.º 5
0
static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
  Proto *f = fs->f;
  int oldsize = f->sizeupvalues;
  checklimit(fs, fs->nups + 1, MAXUPVAL, "upvalues");
  luaM_growvector(fs->ls->L, f->upvalues, fs->nups, f->sizeupvalues,
                  Upvaldesc, MAXUPVAL, "upvalues");
  while (oldsize < f->sizeupvalues) f->upvalues[oldsize++].name = NULL;
  f->upvalues[fs->nups].instack = (v->k == VLOCAL);
  f->upvalues[fs->nups].idx = cast_byte(v->u.info);
  f->upvalues[fs->nups].name = name;
  luaC_objbarrier(fs->ls->L, f, name);
  return fs->nups++;
}
Exemplo n.º 6
0
/*
** Emit instruction 'i', checking for array sizes and saving also its
** line information. Return 'i' position.
*/
static int luaK_code (FuncState *fs, Instruction i) {
  Proto *f = fs->f;
  dischargejpc(fs);  /* 'pc' will change */
  /* put new instruction in code array */
  luaM_growvector(fs->ls->L, f->code, fs->pc, f->sizecode, Instruction,
                  MAX_INT, "opcodes");
  f->code[fs->pc] = i;
  /* save corresponding line information */
  luaM_growvector(fs->ls->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
                  MAX_INT, "opcodes");
  f->lineinfo[fs->pc] = fs->ls->lastline;
  return fs->pc++;
}
Exemplo n.º 7
0
static int number_constant (FuncState *fs, Number r) {
  /* check whether `r' has appeared within the last LOOKBACKNUMS entries */
  Proto *f = fs->f;
  int c = f->nknum;
  int lim = c < LOOKBACKNUMS ? 0 : c-LOOKBACKNUMS;
  while (--c >= lim)
    if (f->knum[c] == r) return c;
  /* not found; create a new entry */
  luaM_growvector(fs->L, f->knum, f->nknum, 1, Number,
                  "constant table overflow", MAXARG_U);
  c = f->nknum++;
  f->knum[c] = r;
  return c;
}
Exemplo n.º 8
0
static int addk (FuncState *fs, TValue *k, TValue *v) {
    lua_State *L = fs->L;
    TValue *idx = luaH_set(L, fs->h, k);
    Proto *f = fs->f;
    int oldsize = f->sizek;
    if (ttisnumber(idx)) {
        lua_assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v));
        return cast_int(nvalue(idx));
    } else { /* constant not found; create a new entry */
        setnvalue(idx, cast_num(fs->nk));
        luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
                        MAXARG_Bx, "constant table overflow");
        while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
        setobj(L, &f->k[fs->nk], v);
        luaC_barrier(L, f, v);
        return fs->nk++;
    }
}
Exemplo n.º 9
0
static int addk (FuncState *fs, TValue *k, TValue *v) {
  lua_State *L = fs->L;
  TValue *idx = luaH_set(L, fs->h, k);
#ifdef LUA_TINT
  /* Note: Integer-valued LUA_TNUMBER's are handled as in unpatched Lua (below)
  */
  if (ttype(idx)==LUA_TINT) {
    int i;
# ifdef LNUM_INT64
    lua_assert( (int)ivalue(idx) == ivalue(idx) );  /* make sure no data is lost in the casting */
# endif
    i= (int)ivalue(idx);
    lua_assert(luaO_rawequalObj(&fs->f->k[i], v));
    return i;
  }
  else if (ttype(idx)==LUA_TNUMBER) {
#else
  if (ttisnumber(idx)) {
#endif
    int i= cast_int(nvalue_fast(idx));
    lua_assert(luaO_rawequalObj(&fs->f->k[i], v));
    return i;
  }
  else {  /* constant not found; create a new entry */
    Proto *f = fs->f;
    int oldsize = f->sizek;
    setivalue(idx, fs->nk);
    luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
                    MAXARG_Bx, "constant table overflow");
    while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
    setobj(L, &f->k[fs->nk], v);
    luaC_barrier(L, f, v);
    return fs->nk++;
  }
}


int luaK_stringK (FuncState *fs, TString *s) {
  TValue o;
  setsvalue(fs->L, &o, s);
  return addk(fs, &o, &o);
}
Exemplo n.º 10
0
static int registerlocalvar (LexState *ls, TString *varname) {
  FuncState *fs = ls->fs;
  Proto *f = fs->f;
  int oldsize = f->sizelocvars;
#if LUA_MEMORY_STATS
  luaM_setname(ls->L, "lua.parser.locals");
#endif /* LUA_MEMORY_STATS */
  luaM_growvector(ls->L, f->locvars, fs->nlocvars, f->sizelocvars,
                  LocVar, SHRT_MAX, "too many local variables");
#if LUA_MEMORY_STATS
  luaM_setname(ls->L, 0);
#endif /* LUA_MEMORY_STATS */
  while (oldsize < f->sizelocvars) f->locvars[oldsize++].varname = NULL;
  f->locvars[fs->nlocvars].varname = varname;
  luaC_objbarrier(ls->L, f, varname);
#if LUA_REFCOUNT
  luarc_addrefstring(varname);
#endif /* LUA_REFCOUNT */
  return fs->nlocvars++;
}
Exemplo n.º 11
0
static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
  int i;
  Proto *f = fs->f;
  int oldsize = f->sizeupvalues;
  for (i=0; i<f->nups; i++) {
    if (fs->upvalues[i].k == v->k && fs->upvalues[i].info == v->u.s.info) {
      lua_assert(f->upvalues[i] == name);
      return i;
    }
  }
  /* new one */
  luaY_checklimit(fs, f->nups + 1, LUAI_MAXUPVALUES, "upvalues");
  luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, MAX_INT, "");
  while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL;
  f->upvalues[f->nups] = name;
  luaC_objbarrier(fs->L, f, name);
  lua_assert(v->k == VLOCAL || v->k == VUPVAL);
  fs->upvalues[f->nups].k = cast_byte(v->k);
  fs->upvalues[f->nups].info = cast_byte(v->u.s.info);
  return f->nups++;
}
Exemplo n.º 12
0
static int addk (FuncState *fs, TValue *k, TValue *v) {
  lua_State *L = fs->L;
  TValue *idx = luaH_set(L, fs->h, k);
  Proto *f = fs->f;
  int oldsize = f->sizek;
  if (ttype(idx)==LUA_TNUMBER) {
    luai_normalize(idx);
    lua_assert( ttype(idx)==LUA_TINT );     /* had no fraction */
  }
  if (ttisint(idx)) {
    lua_assert(luaO_rawequalObj(&fs->f->k[ivalue(idx)], v));
    return cast_int(ivalue(idx));
  }
  else {  /* constant not found; create a new entry */
    setivalue(idx, fs->nk);
    luaM_growvector(L, f->k, fs->nk, f->sizek, TValue,
                    MAXARG_Bx, "constant table overflow");
    while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
    setobj(L, &f->k[fs->nk], v);
    luaC_barrier(L, f, v);
    return fs->nk++;
  }
}
Exemplo n.º 13
0
static int addk (FuncState *fs, TValue *key, TValue *v) {
  lua_State *L = fs->L;
  TValue *idx = luaH_set(L, fs->h, key);
  Proto *f = fs->f;
  int k, oldsize;
  if (ttisnumber(idx)) {
    lua_Number n = nvalue(idx);
    lua_number2int(k, n);
    if (luaO_rawequalObj(&f->k[k], v))
      return k;
    /* else may be a collision (e.g., between 0.0 and "\0\0\0\0\0\0\0\0");
       go through and create a new entry for this value */
  }
  /* constant not found; create a new entry */
  oldsize = f->sizek;
  k = fs->nk;
  setnvalue(idx, cast_num(k));
  luaM_growvector(L, f->k, k, f->sizek, TValue, MAXARG_Ax, "constants");
  while (oldsize < f->sizek) setnilvalue(&f->k[oldsize++]);
  setobj(L, &f->k[k], v);
  fs->nk++;
  luaC_barrier(L, f, v);
  return k;
}
Exemplo n.º 14
0
static void check_pc (FuncState *fs, int n) {
  luaM_growvector(fs->f->code, fs->pc, n, Byte, codeEM, MAX_INT);
}
Exemplo n.º 15
0
//Increase by one the const list count
int increase_const_list(TProtoFunc* func) {
	return luaM_growvector(&func->consts, func->nconsts, TObject,
                                    constantEM, MAX_WORD);
}
Exemplo n.º 16
0
static void check_pc (FuncState *fs, int32 n) {
  if (fs->pc+n > fs->maxcode)
    fs->maxcode = luaM_growvector(&fs->f->code, fs->maxcode,
                                  Byte, codeEM, MAX_INT);
}