Ejemplo n.º 1
0
static void DumpStrings(FILE* D)
{
 int i;
 for (i=0; i<lua_ntable; i++)
 {
  if (VarLoc(i)!=0)
  {
   fputc(ID_VAR,D);
   DumpWord(VarLoc(i),D);
   DumpString(VarStr(i),D);
  }
  VarLoc(i)=i;
 }
 for (i=0; i<lua_nconstant; i++)
 {
  if (StrLoc(i)!=0)
  {
   fputc(ID_STR,D);
   DumpWord(StrLoc(i),D);
   DumpString(StrStr(i),D);
  }
  StrLoc(i)=i;
 }
}
Ejemplo n.º 2
0
bool SumAggrLit::match(Grounder *grounder)
{
	try
	{
		if(lower_.get()) lowerBound_ = lower_->val(grounder).number();
		else lowerBound_ = std::numeric_limits<int32_t>::min();
		if(upper_.get()) upperBound_ = upper_->val(grounder).number();
		else upperBound_ = std::numeric_limits<int32_t>::max();
		if(assign_) upperBound_ = lowerBound_;
	}
	catch(const Val *val)
	{
		std::ostringstream oss;
		oss << "cannot convert ";
		val->print(grounder, oss);
		oss << " to integer";
		std::string str(oss.str());
		oss.str("");
		print(grounder, oss);
		throw TypeException(str, StrLoc(grounder, loc()), oss.str());
	}
	fact_     = false;
	factOnly_ = true;
	valLower_ = valUpper_ = fixed_ = 0;
	checkUpperBound_ = (set() && upper_.get());
	if(set()) uniques_.clear();
	foreach(CondLit &lit, conds_) lit.ground(grounder);
	lowerBound_ = lower_.get() ? std::max(lowerBound_ - fixed_, valLower_) : valLower_;
	upperBound_ = upper_.get() || assign_ ? std::min(upperBound_ - fixed_, valUpper_) : valUpper_;

	if(head() && !factOnly_) return true;
	if(lowerBound_ > upperBound_) return (fact_ = sign_) || head();
	if(valLower_ >= lowerBound_ && valUpper_ <= upperBound_) return (fact_ = !sign_) || head();
	if(valUpper_ < lowerBound_ || valLower_  > upperBound_) return (fact_ = sign_) || head();
	return true;
}
Ejemplo n.º 3
0
static void ThreadCode(Byte* code, Byte* end)
{
 Byte* p;
 int i;
 for (i=0; i<lua_ntable; i++) VarLoc(i)=0;
 for (i=0; i<lua_nconstant; i++) StrLoc(i)=0;
 for (p=code; p!=end;)
 {
	OpCode op=(OpCode)*p;
	int at=p-code+1;
	switch (op)
	{
	case PUSHNIL:
	case PUSH0:
	case PUSH1:
	case PUSH2:
	case PUSHLOCAL0:
	case PUSHLOCAL1:
	case PUSHLOCAL2:
	case PUSHLOCAL3:
	case PUSHLOCAL4:
	case PUSHLOCAL5:
	case PUSHLOCAL6:
	case PUSHLOCAL7:
	case PUSHLOCAL8:
	case PUSHLOCAL9:
	case PUSHINDEXED:
	case STORELOCAL0:
	case STORELOCAL1:
	case STORELOCAL2:
	case STORELOCAL3:
	case STORELOCAL4:
	case STORELOCAL5:
	case STORELOCAL6:
	case STORELOCAL7:
	case STORELOCAL8:
	case STORELOCAL9:
	case STOREINDEXED0:
	case ADJUST0:
	case EQOP:
	case LTOP:
	case LEOP:
	case GTOP:
	case GEOP:
	case ADDOP:
	case SUBOP:
	case MULTOP:
	case DIVOP:
	case POWOP:
	case CONCOP:
	case MINUSOP:
	case NOTOP:
	case POP:
	case RETCODE0:
		p++;
		break;
	case PUSHBYTE:
	case PUSHLOCAL:
	case STORELOCAL:
	case STOREINDEXED:
	case STORELIST0:
	case ADJUST:
	case RETCODE:
		p+=2;
		break;
	case PUSHWORD:
	case CREATEARRAY:
	case ONTJMP:
	case ONFJMP:
	case JMP:
	case UPJMP:
	case IFFJMP:
	case IFFUPJMP:
	case SETLINE:
	case STORELIST:
	case CALLFUNC:
		p+=3;
		break;
	case PUSHFLOAT:
		p+=5;			/* assumes sizeof(float)==4 */
		break;
	case PUSHSELF:
	case PUSHSTRING:
	{
		Word w;
		p++;
		get_word(w,p);
		w=SawStr(w,at);
		memcpy(p-2,&w,sizeof(w));
		break;
	}
	case PUSHFUNCTION:
	{
		TFunc* tf;
		p++;
		get_code(tf,p);
		tf->marked=at;
		tf->next=NULL;		/* TODO: remove? */
		lastF=lastF->next=tf;
		break;
	}
	case PUSHGLOBAL:
	case STOREGLOBAL:
	{
		Word w;
		p++;
		get_word(w,p);
		w=SawVar(w,at);
		memcpy(p-2,&w,sizeof(w));
		break;
	}
	case STORERECORD:
	{
		int n=*++p;
		p++;
		while (n--)
		{
			Word w;
			at=p-code;
			get_word(w,p);
			w=SawStr(w,at);
			memcpy(p-2,&w,sizeof(w));
		}
		break;
	}
	default:
		fprintf(stderr,"luac: cannot happen:  opcode=%d",*p);
		exit(1);
		break;
	}
 }
}
Ejemplo n.º 4
0
static int SawStr(int i, int at)
{
 int old=StrLoc(i);
 StrLoc(i)=at;
 return old;
}