Esempio n. 1
0
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 */
}
Esempio n. 2
0
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));
}
Esempio n. 3
0
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;
	}
}
Esempio n. 4
0
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;
 }
}
Esempio n. 5
0
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));
}
Esempio n. 6
0
File: ldo.c Progetto: Djent-/GBALua
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;
}
Esempio n. 7
0
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);
}
Esempio n. 8
0
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);
    }
  }
}
Esempio n. 9
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);
}
Esempio n. 10
0
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);
}
Esempio n. 11
0
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;
    }
}
Esempio n. 12
0
/*
** 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;
}
Esempio n. 13
0
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);
}
Esempio n. 14
0
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;
}
Esempio n. 15
0
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)));

}
Esempio n. 16
0
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;
  }
}
Esempio n. 17
0
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]);
}
Esempio n. 18
0
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);
 }
}
Esempio n. 19
0
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);
  }
}
Esempio n. 20
0
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);
 }
}
Esempio n. 21
0
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 */
}
Esempio n. 22
0
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;
}
Esempio n. 23
0
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 */
}
Esempio n. 24
0
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;
}
Esempio n. 25
0
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);
}
Esempio n. 26
0
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 */
}
Esempio n. 27
0
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;
}
Esempio n. 28
0
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;
}
Esempio n. 29
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)!=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);
}
Esempio n. 30
0
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;
 }
}