static void LoadDebug(LoadState* S, Proto* f) { int i,n; n=LoadInt(S); f->lineinfo=luaM_newvector(S->L,n,int); f->sizelineinfo=n; LoadVector(S,f->lineinfo,n,sizeof(int)); n=LoadInt(S); f->locvars=luaM_newvector(S->L,n,LocVar); f->sizelocvars=n; for (i=0; i<n; i++) f->locvars[i].varname=NULL; for (i=0; i<n; i++) { f->locvars[i].varname=LoadString(S); #if LUA_REFCOUNT luarc_addrefstring(f->locvars[i].varname); #endif /* LUA_REFCOUNT */ f->locvars[i].startpc=LoadInt(S); f->locvars[i].endpc=LoadInt(S); } n=LoadInt(S); f->upvalues=luaM_newvector(S->L,n,TString*); f->sizeupvalues=n; for (i=0; i<n; i++) f->upvalues[i]=NULL; #if LUA_REFCOUNT for (i=0; i<n; i++) { f->upvalues[i]=LoadString(S); luarc_addrefstring(f->upvalues[i]); } #else for (i=0; i<n; i++) f->upvalues[i]=LoadString(S); #endif /* LUA_REFCOUNT */ }
static void LoadCode(LoadState* S, Proto* f) { int n=LoadInt(S); f->code=luaM_newvector(S->L,n,Instruction); f->sizecode=n; LoadVector(S,f->code,n,sizeof(Instruction)); }
static Proto* combine(lua_State* L, int n) { if (n==1) { const Closure* c=(const Closure*)lua_topointer(L,-1); return c->l.p; } else { int i,pc=0; Proto* f=luaF_newproto(L); f->source=luaS_newliteral(L,"=(none)"); f->maxstacksize=1; f->p=luaM_newvector(L,n,Proto*); f->sizep=n; f->sizecode=2*n+1; f->code=luaM_newvector(L,f->sizecode,Instruction); for (i=0; i<n; i++) { const Closure* c=(const Closure*)lua_topointer(L,i-n); f->p[i]=c->l.p; f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i); f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1); } f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0); return f; } }
static const Proto* combine(lua_State* L, int n) { if (n==1) return toproto(L,-1); else { int i,pc; Proto* f=luaF_newproto(L); setptvalue2s(L,L->top,f); incr_top(L); f->source=luaS_newliteral(L,"=(" PROGNAME ")"); f->maxstacksize=1; pc=2*n+1; f->code=luaM_newvector(L,pc,Instruction); f->sizecode=pc; f->p=luaM_newvector(L,n,Proto*); f->sizep=n; pc=0; for (i=0; i<n; i++) { f->p[i]=toproto(L,i-n-1); f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i); f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1); } f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0); return f; } }
static void LoadCode (LoadState* S, Proto* f) { int size=LoadInt(S); f->code=luaM_newvector(S->L,size,Instruction); f->sizecode=size; LoadVector(S,f->code,size,sizeof(*f->code)); }
void luaD_init (lua_State *L, int stacksize) { L->stack = luaM_newvector(L, stacksize+EXTRA_STACK, TObject); L->nblocks += stacksize*sizeof(TObject); L->stack_last = L->stack+(stacksize-1); L->stacksize = stacksize; L->Cbase = L->top = L->stack; }
static void LoadConstants (LoadState* S, Proto* f) { int i,n; n=LoadInt(S); f->k=luaM_newvector(S->L,n,TObject); f->sizek=n; for (i=0; i<n; i++) { TObject* o=&f->k[i]; int t=LoadByte(S); switch (t) { case LUA_TNUMBER: setnvalue(o,LoadNumber(S)); break; case LUA_TSTRING: setsvalue2n(o,LoadString(S)); break; case LUA_TNIL: setnilvalue(o); break; default: luaG_runerror(S->L,"bad constant type (%d) in %s",t,S->name); break; } } n=LoadInt(S); f->p=luaM_newvector(S->L,n,Proto*); f->sizep=n; for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source); }
static void LoadConstants (LoadState *S, Proto *f) { int i; int n = LoadInt(S); f->k = luaM_newvector(S->L, n, TValue); f->sp->sizek = n; for (i = 0; i < n; i++) setnilvalue(&f->k[i]); for (i = 0; i < n; i++) { TValue *o = &f->k[i]; int t = LoadByte(S); switch (t) { case LUA_TNIL: setnilvalue(o); break; case LUA_TBOOLEAN: setbvalue(o, LoadByte(S)); break; case LUA_TNUMFLT: setfltvalue(o, LoadNumber(S)); break; case LUA_TNUMINT: setivalue(o, LoadInteger(S)); break; case LUA_TSHRSTR: case LUA_TLNGSTR: setsvalue2n(S->L, o, LoadString(S)); break; default: lua_assert(0); } } }
static void LoadConstants(LoadState* S, Proto* f) { int i,n; n=LoadInt(S); f->k=luaM_newvector(S->L,n,TValue); f->sizek=n; for (i=0; i<n; i++) setnilvalue(&f->k[i]); for (i=0; i<n; i++) { TValue* o=&f->k[i]; int t=LoadChar(S); switch (t) { case LUA_TNIL: setnilvalue(o); break; case LUA_TBOOLEAN: setbvalue(o,LoadChar(S)); break; case LUA_TNUMBER: setnvalue(o,LoadNumber(S)); break; case LUA_TSTRING: setsvalue2n(S->L,o,LoadString(S)); break; } } n=LoadInt(S); f->p=luaM_newvector(S->L,n,Proto*); f->sizep=n; for (i=0; i<n; i++) f->p[i]=NULL; for (i=0; i<n; i++) f->p[i]=LoadFunction(S); }
static void LoadDebug(LoadState * S, Proto * f) { int i,n; n=LoadInt(S); f->lineinfo=luaM_newvector(S->L,n,int); f->sizelineinfo=n; LoadVector(S,f->lineinfo,n,sizeof(int)); n=LoadInt(S); f->locvars=luaM_newvector(S->L,n,LocVar); f->sizelocvars=n; for(i=0; i<n; i++) f->locvars[i].varname=NULL; for(i=0; i<n; i++) { f->locvars[i].varname=LoadString(S); f->locvars[i].startpc=LoadInt(S); f->locvars[i].endpc=LoadInt(S); } n=LoadInt(S); f->upvalues=luaM_newvector(S->L,n,TString*); f->sizeupvalues=n; for(i=0; i<n; i++) f->upvalues[i]=NULL; for(i=0; i<n; i++) f->upvalues[i]=LoadString(S); }
static int lua_combine( lua_State* L) { int n = lua_gettop( L); /* Number of functions to combine */ if( 1 == n) { return 1; /* Only one function, nothing to combine */ } else { int i, pc = 3*n + 1; Proto* f = luaF_newproto( L); setptvalue2s( L,L->top,f); incr_top( L); f->source = luaS_newliteral( L,"=(combiner)"); f->maxstacksize = 2; f->is_vararg = VARARG_ISVARARG; f->code = luaM_newvector(L, pc, Instruction); f->sizecode = pc; f->p = luaM_newvector( L, n, Proto*); f->sizep = n; for( i = pc = 0; i < n; i ++) { int proto_idx = i-n-1; Proto *p = clvalue( L->top + proto_idx)->l.p; f->p[i] = p; f->code[pc++] = CREATE_ABx( OP_CLOSURE, 0, i); f->code[pc++] = CREATE_ABx( OP_VARARG, 1, 0); f->code[pc++] = CREATE_ABC( OP_CALL, 0, 0, 1); } f->code[pc++] = CREATE_ABC( OP_RETURN, 0, 1, 0); return 1; } }
/* ** Alloc a vector node */ static Node *hashnodecreate (int nhash) { Node *v = luaM_newvector(nhash, Node); int i; for (i=0; i<nhash; i++) ttype(ref(&v[i])) = LUA_T_NIL; return v; }
static void LoadCode (lua_State* L, Proto* tf, ZIO* Z, int swap) { int size=LoadInt(L,Z,swap); tf->code=luaM_newvector(L,size,Instruction); LoadVector(L,tf->code,size,sizeof(*tf->code),Z,swap); if (tf->code[size-1]!=OP_END) luaO_verror(L,"bad code in `%.99s'",ZNAME(Z)); luaF_protook(L,tf,size); }
static void stack_init (lua_State *L1, lua_State *L) { /* initialize CallInfo array */ L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); L1->ci = L1->base_ci; L1->size_ci = BASIC_CI_SIZE; L1->end_ci = L1->base_ci + L1->size_ci - 1; /* initialize stack array */ L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; L1->top = L1->stack; L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; /* initialize first ci */ L1->ci->func = L1->top; setnilvalue(L1->top++); /* `function' entry for this `ci' */ L1->base = L1->ci->base = L1->top; L1->ci->top = L1->top + LUA_MINSTACK; }
void SexeLoadCode(LoadState* S, Proto* f, sexe_stack_t *stack) { f->code=luaM_newvector(S->L, stack->size, Instruction); f->sizecode = stack->size; LoadBlock(S, f->code, stack->size * sizeof(Instruction)); VERBOSE("[CODE] x%d instrs @ %lu bytes each <%lu bytes>\n", stack->size, sizeof(Instruction), sizeof(sexe_stack_t) + (stack->size * sizeof(Instruction))); }
void luaS_init (void) { int i; L->string_root = luaM_newvector(NUM_HASHS, stringtable); for (i=0; i<NUM_HASHS; i++) { L->string_root[i].size = 0; L->string_root[i].nuse = 0; L->string_root[i].hash = NULL; } }
static void LoadCode(LoadState* S, Proto* f) { int n=LoadInt(S); int i=0; f->code=luaM_newvector(S->L,n,Instruction); f->sizecode=n; LoadVector(S,f->code,n,sizeof(Instruction)); if (!S->flip) return; for (i=0; i<n; ++i) f->code[i] = Swap32(f->code[i]); }
static void LoadLocals (lua_State* L, Proto* tf, ZIO* Z, int swap) { int i,n; tf->nlocvars=n=LoadInt(L,Z,swap); tf->locvars=luaM_newvector(L,n,LocVar); for (i=0; i<n; i++) { tf->locvars[i].varname=LoadString(L,Z,swap); tf->locvars[i].startpc=LoadInt(L,Z,swap); tf->locvars[i].endpc=LoadInt(L,Z,swap); } }
static void LoadUpvalues (LoadState *S, Proto *f) { int i, n; n = LoadInt(S); f->upvalues = luaM_newvector(S->L, n, Upvaldesc); f->sizeupvalues = n; for (i = 0; i < n; i++) f->upvalues[i].name = NULL; for (i = 0; i < n; i++) { f->upvalues[i].instack = LoadByte(S); f->upvalues[i].idx = LoadByte(S); } }
static void LoadLocals (LoadState* S, Proto* f) { int i,n; n=LoadInt(S); f->locvars=luaM_newvector(S->L,n,LocVar); f->sizelocvars=n; for (i=0; i<n; i++) { f->locvars[i].varname=LoadString(S); f->locvars[i].startpc=LoadInt(S); f->locvars[i].endpc=LoadInt(S); } }
static void setnodevector (lua_State *L, Hash *t, lint32 size) { int i; if (size > MAX_INT) lua_error(L, "table overflow"); t->node = luaM_newvector(L, size, Node); for (i=0; i<(int)size; i++) { ttype(&t->node[i].key) = ttype(&t->node[i].val) = LUA_TNIL; t->node[i].next = NULL; } L->nblocks += gcsize(L, size) - gcsize(L, t->size); t->size = size; t->firstfree = &t->node[size-1]; /* first free position to be used */ }
static void LoadCode(LoadState* S, Proto* f) { int n=LoadInt(S); Align4(S); if (!luaZ_direct_mode(S->Z)) { f->code=luaM_newvector(S->L,n,Instruction); LoadVector(S,f->code,n,sizeof(Instruction)); } else { f->code=(Instruction*)luaZ_get_crt_address(S->Z); LoadVector(S,NULL,n,sizeof(Instruction)); } f->sizecode=n; }
static void LoadConstants(LoadState* S, Proto* f) { int i,n; #if LUA_REFCOUNT lua_State *L = S->L; #endif /* LUA_REFCOUNT */ n=LoadInt(S); f->k=luaM_newvector(S->L,n,TValue); f->sizek=n; #if LUA_REFCOUNT for (i=0; i<n; i++) setnilvalue2n(L, &f->k[i]); #else for (i=0; i<n; i++) setnilvalue(&f->k[i]); #endif /* LUA_REFCOUNT */ for (i=0; i<n; i++) { TValue* o=&f->k[i]; int t=LoadChar(S); switch (t) { case LUA_TNIL: setnilvalue(o); break; case LUA_TBOOLEAN: setbvalue(o,LoadChar(S)!=0); break; case LUA_TNUMBER: setnvalue(o,LoadNumber(S)); break; case LUA_TSTRING: setsvalue2n(S->L,o,LoadString(S)); break; default: error(S,"bad constant"); break; } } n=LoadInt(S); f->p=luaM_newvector(S->L,n,Proto*); f->sizep=n; for (i=0; i<n; i++) f->p[i]=NULL; #if LUA_REFCOUNT for (i=0; i<n; i++) { f->p[i]=LoadFunction(S,f->source); luarc_addrefproto(f->p[i]); } #else for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source); #endif /* LUA_REFCOUNT */ }
static void stack_init (lua_State *L1, lua_State *L) { #if LUA_REFCOUNT StkId i; #endif LUA_REFCOUNT luaM_setname(L, "Lua_Stack"); L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TObject); L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; L1->top = L1->stack; L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; #if LUA_REFCOUNT for (i = L1->stack; i != L1->stack_last; ++i) setnilvalue2n(i); #endif LUA_REFCOUNT luaM_setname(L, "Lua_CallInfo"); L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); L1->ci = L1->base_ci; L1->ci->state = CI_C; /* not a Lua function */ setnilvalue2n(L1->top++); /* `function' entry for this `ci' */ L1->base = L1->ci->base = L1->top; L1->ci->top = L1->top + LUA_MINSTACK; L1->size_ci = BASIC_CI_SIZE; L1->end_ci = L1->base_ci + L1->size_ci; }
static void LoadConstants (lua_State* L, Proto* tf, ZIO* Z, int swap) { int i,n; tf->nkstr=n=LoadInt(L,Z,swap); tf->kstr=luaM_newvector(L,n,TString*); for (i=0; i<n; i++) tf->kstr[i]=LoadString(L,Z,swap); tf->nknum=n=LoadInt(L,Z,swap); tf->knum=luaM_newvector(L,n,Number); LoadVector(L,tf->knum,n,sizeof(*tf->knum),Z,swap); tf->nkproto=n=LoadInt(L,Z,swap); tf->kproto=luaM_newvector(L,n,Proto*); for (i=0; i<n; i++) tf->kproto[i]=LoadFunction(L,Z,swap); }
static void stack_init (lua_State *L1, lua_State *L) { #if LUA_MEMORY_STATS luaM_setname(L, "lua.callinfo"); #endif /* LUA_MEMORY_STATS */ /* initialize CallInfo array */ L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); L1->ci = L1->base_ci; L1->size_ci = BASIC_CI_SIZE; L1->end_ci = L1->base_ci + L1->size_ci - 1; /* initialize stack array */ #if LUA_MEMORY_STATS luaM_setname(L, "lua.stack"); #endif /* LUA_MEMORY_STATS */ L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue); L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK; L1->top = L1->stack; L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1; #if LUA_REFCOUNT luarc_newarray(L1->stack, L1->stack + L1->stacksize); #endif /* LUA_REFCOUNT */ /* initialize first ci */ L1->ci->func = L1->top; #if LUA_REFCOUNT setnilvalue2n(L1, L1->top++); /* `function' entry for this `ci' */ #else setnilvalue(L1->top++); /* `function' entry for this `ci' */ #endif /* LUA_REFCOUNT */ L1->base = L1->ci->base = L1->top; L1->ci->top = L1->top + LUA_MINSTACK; #if LUA_EXT_RESUMABLEVM L1->ci->errfunc = 0; #endif /* LUA_EXT_RESUMABLEVM */ #if LUA_MEMORY_STATS luaM_setname(L, 0); #endif /* LUA_MEMORY_STATS */ }
static Proto *makefakeproto(lua_State *L, lu_byte nups) { Proto *p = luaF_newproto(L); p->sizelineinfo = 1; p->lineinfo = luaM_newvector(L, 1, int); p->lineinfo[0] = 1; p->sizecode = 1; p->code = luaM_newvector(L, 1, Instruction); p->code[0] = CREATE_ABC(OP_RETURN, 0, 1, 0); p->source = luaS_newlstr(L, "", 0); p->maxstacksize = 2; p->nups = nups; p->sizek = 0; p->sizep = 0; return p; }
static void stack_init (lua_State *L1, lua_State *L) { int i; CallInfo *ci; /* initialize stack array */ L1->stack = luaM_newvector(L, BASIC_STACK_SIZE, TValue); L1->stacksize = BASIC_STACK_SIZE; for (i = 0; i < BASIC_STACK_SIZE; i++) setnilvalue(L1->stack + i); /* erase new stack */ L1->top = L1->stack; L1->stack_last = L1->stack + L1->stacksize; /* initialize first ci */ ci = &L1->base_ci; ci->next = ci->previous = NULL; ci->callstatus = 0; ci->func = L1->top; setnilvalue(L1->top++); /* 'function' entry for this 'ci' */ ci->top = L1->top + LUA_MINSTACK; L1->ci = ci; }
static void LoadConstants(LoadState* S, Proto* f) { int i,n; n=LoadInt(S); f->k=luaM_newvector(S->L,n,TValue); f->sizek=n; for (i=0; i<n; i++) setnilvalue(&f->k[i]); for (i=0; i<n; i++) { TValue* o=&f->k[i]; int t=LoadChar(S); switch (t) { case LUA_TNIL: setnilvalue(o); break; case LUA_TBOOLEAN: setbvalue(o,LoadChar(S)!=0); break; case LUA_TNUMBER: setnvalue(o,LoadNumber(S)); break; #ifdef LUA_TINT case LUA_TINT: /* Integer type saved in bytecode (see lcode.c) */ setivalue(o,LoadInteger(S)); break; #endif case LUA_TSTRING: setsvalue2n(S->L,o,LoadString(S)); break; default: error(S,"bad constant"); break; } } n=LoadInt(S); f->p=luaM_newvector(S->L,n,Proto*); f->sizep=n; for (i=0; i<n; i++) f->p[i]=NULL; for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source); }
static Proto* combine(lua_State* L, int n) { if (n==1) { int i; Proto* f = toproto(L,-1); if (LDS2) { Inject(f,0); for (i=0; i<f->sizep; i++) { Inject(f->p[i],i+1); } } return f; } else { int i,pc=0; Proto* f=luaF_newproto(L); f->source=luaS_newliteral(L,"=(" PROGNAME ")"); f->maxstacksize=1; f->p=luaM_newvector(L,n,Proto*); f->sizep=n; f->sizecode=2*n+1; f->code=luaM_newvector(L,f->sizecode,Instruction); for (i=0; i<n; i++) { f->p[i]=toproto(L,i-n); f->code[pc++]=CREATE_ABx(HKS_OPCODE_CLOSURE,0,i); f->code[pc++]=CREATE_ABC(HKS_OPCODE_CALL,0,1,1); } f->code[pc++]=CREATE_ABC(HKS_OPCODE_RETURN,0,1,0); if (LDS2) { Inject(f,0); for (i=0; i<n; i++) { Inject(f->p[i],i+1); } } return f; } }