Skip to content

Commit

Permalink
Fixed subtract_do
Browse files Browse the repository at this point in the history
  • Loading branch information
alexp-sssup committed Oct 26, 2009
1 parent 0a0b294 commit 02f3ab2
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 122 deletions.
82 changes: 31 additions & 51 deletions abc.cpp
Expand Up @@ -129,7 +129,7 @@ void ABCVm::registerClasses()
Global.setVariableByQName("InteractiveObject","flash.display",new ASObject),
Global.setVariableByQName("DisplayObjectContainer","flash.display",Class<DisplayObjectContainer>::getClass());
Global.setVariableByQName("Sprite","flash.display",Class<Sprite>::getClass());
Global.setVariableByQName("Shape","flash.display",Class<IInterface>::getClass("Shape"));
Global.setVariableByQName("Shape","flash.display",Class<Shape>::getClass());

Global.setVariableByQName("TextField","flash.text",new ASObject);
Global.setVariableByQName("TextFormat","flash.text",new ASObject);
Expand All @@ -148,6 +148,7 @@ void ABCVm::registerClasses()

Global.setVariableByQName("Rectangle","flash.geom",new ASObject);
Global.setVariableByQName("Matrix","flash.geom",Class<IInterface>::getClass("Matrix"));
Global.setVariableByQName("Point","flash.geom",Class<IInterface>::getClass("Point"));

Global.setVariableByQName("EventDispatcher","flash.events",Class<EventDispatcher>::getClass());
Global.setVariableByQName("Event","flash.events",Class<Event>::getClass());
Expand Down Expand Up @@ -871,8 +872,7 @@ void ABCContext::buildClassAndInjectBase(const string& s, IInterface* base,argum
if(derived_class_tmp->class_index!=-1)
{
LOG(CALLS,"Building instance traits");
for(int i=0;i<instances[derived_class_tmp->class_index].trait_count;i++)
buildTrait(obj,&instances[derived_class_tmp->class_index].traits[i]);
buildClassTraits(obj, derived_class_tmp->class_index);

LOG(CALLS,"Calling Instance init on " << s);
//args->incRef();
Expand Down Expand Up @@ -1283,6 +1283,12 @@ tiny_string ABCContext::getString(unsigned int s) const
return "";
}

inline void ABCContext::buildClassTraits(ASObject* obj, int class_index)
{
for(int i=0;i<instances[class_index].trait_count;i++)
buildTrait(obj,&instances[class_index].traits[i]);
}

void ABCContext::buildTrait(ASObject* obj, const traits_info* t, IFunction* deferred_initialization)
{
const multiname* mname=getMultiname(t->name,NULL);
Expand Down Expand Up @@ -1317,68 +1323,42 @@ void ABCContext::buildTrait(ASObject* obj, const traits_info* t, IFunction* defe
case traits_info::Getter:
{
LOG(CALLS,"Getter trait: " << ns << "::" << name << " #" << t->method);
IFunction* f=NULL;
/*//Hack, try to find this on the most derived variables
obj_var* var=obj->findObjVar(name,ns,false);
if(var && var->getter) //Ok, it seems that we have been overridden, set this in our map
{
LOG(CALLS,"HACK: overridden getter");
f=static_cast<IFunction*>(var->getter->clone());
f->bind(obj->mostDerived);
}
if(f==NULL)*/
{
//syntetize method and create a new LLVM function object
method_info* m=&methods[t->method];
f=new SyntheticFunction(m);
}
//syntetize method and create a new LLVM function object
method_info* m=&methods[t->method];
IFunction* f=new SyntheticFunction(m);

obj->setGetterByQName(name,ns,f);
//We should inherit the setter from the hierarchy
obj_var* var=obj->Variables.findObjVar(name,ns,obj->max_level-1,false);
if(var && var->setter) //Ok, also set the inherited setter
obj->setSetterByQName(name,ns,var->setter);

LOG(CALLS,"End Getter trait: " << ns << "::" << name);
break;
}
case traits_info::Setter:
{
LOG(CALLS,"Setter trait: " << ns << "::" << name << " #" << t->method);
IFunction* f=NULL;
/*//Hack, try to find this on the most derived variables
obj_var* var=obj->findObjVar(name,ns,false);
if(var && var->getter) //Ok, it seems that we have been overridden, set this in our map
{
LOG(CALLS,"HACK: overridden getter");
f=static_cast<IFunction*>(var->getter->clone());
f->bind(obj->mostDerived);
}
if(f==NULL)*/
{
//syntetize method and create a new LLVM function object
method_info* m=&methods[t->method];
f=new SyntheticFunction(m);
}
//syntetize method and create a new LLVM function object
method_info* m=&methods[t->method];
IFunction* f=new SyntheticFunction(m);

obj->setSetterByQName(name,ns,f);
//We should inherit the setter from the hierarchy
obj_var* var=obj->Variables.findObjVar(name,ns,obj->max_level-1,false);
if(var && var->getter) //Ok, also set the inherited setter
obj->setGetterByQName(name,ns,var->getter);

LOG(CALLS,"End Setter trait: " << ns << "::" << name);
break;
}
case traits_info::Method:
{
LOG(CALLS,"Method trait: " << ns << "::" << name << " #" << t->method);
IFunction* f=NULL;
/*//Hack, try to find this on the most derived variables
obj_var* var=obj->findObjVar(name,ns,false);
if(var && var->getter) //Ok, it seems that we have been overridden, set this in our map
{
LOG(CALLS,"HACK: overridden getter");
f=static_cast<IFunction*>(var->getter->clone());
f->bind(obj->mostDerived);
}
if(f==NULL)*/
{
//syntetize method and create a new LLVM function object
method_info* m=&methods[t->method];
f=new SyntheticFunction(m);
}
//syntetize method and create a new LLVM function object
method_info* m=&methods[t->method];
IFunction* f=new SyntheticFunction(m);

obj->setVariableByQName(name,ns,f);
LOG(CALLS,"End Method trait: " << ns << "::" << name);
break;
Expand Down
1 change: 1 addition & 0 deletions abc.h
Expand Up @@ -372,6 +372,7 @@ friend class method_info;
tiny_string getString(unsigned int s) const;
//Qname getQname(unsigned int m, call_context* th=NULL) const;
void buildTrait(ASObject* obj, const traits_info* t, IFunction* deferred_initialization=NULL);
void buildClassTraits(ASObject* obj, int class_index);
void buildClassAndInjectBase(const std::string& n, IInterface*, arguments* a);
multiname* getMultiname(unsigned int m, call_context* th);
static multiname* s_getMultiname(call_context*, ASObject*, int m);
Expand Down
2 changes: 1 addition & 1 deletion abc_codesynt.cpp
Expand Up @@ -176,7 +176,7 @@ typed_opcode_handler ABCVm::opcode_table_number_t[]={
{"subtract",(void*)&ABCVm::subtract,ARGS_OBJ_OBJ},
{"subtract_oi",(void*)&ABCVm::subtract_oi,ARGS_OBJ_INT},
{"subtract_io",(void*)&ABCVm::subtract_io,ARGS_INT_OBJ},
{"subtract_do",(void*)&ABCVm::subtract_io,ARGS_NUMBER_OBJ}
{"subtract_do",(void*)&ABCVm::subtract_do,ARGS_NUMBER_OBJ}
};

typed_opcode_handler ABCVm::opcode_table_void[]={
Expand Down
73 changes: 51 additions & 22 deletions abc_opcodes.cpp
Expand Up @@ -337,7 +337,6 @@ ASObject* ABCVm::getProperty(ASObject* obj, multiname* name)
if(owner==NULL)
{
LOG(NOT_IMPLEMENTED,"Property not found " << *name);
//abort();
ret=new Undefined;
}
else
Expand Down Expand Up @@ -469,7 +468,7 @@ number_t ABCVm::multiply_oi(ASObject* val2, intptr_t val1)
double num1=val1;
double num2=val2->toNumber();
val2->decRef();
LOG(CALLS,"multiply " << num1 << '*' << num2);
LOG(CALLS,"multiply_oi " << num1 << '*' << num2);
return num1*num2;
}

Expand Down Expand Up @@ -682,6 +681,12 @@ number_t ABCVm::subtract_oi(ASObject* val2, intptr_t val1)

number_t ABCVm::subtract_do(number_t val2, ASObject* val1)
{
if(val1->getObjectType()==T_UNDEFINED)
{
//HACK
LOG(NOT_IMPLEMENTED,"subtract: HACK");
return 0;
}
number_t num2=val2;
number_t num1=val1->toNumber();

Expand All @@ -702,6 +707,13 @@ number_t ABCVm::subtract_io(intptr_t val2, ASObject* val1)

number_t ABCVm::subtract(ASObject* val2, ASObject* val1)
{
if(val1->getObjectType()==T_UNDEFINED ||
val2->getObjectType()==T_UNDEFINED)
{
//HACK
LOG(NOT_IMPLEMENTED,"subtract: HACK");
return 0;
}
int num2=val2->toInt();
int num1=val1->toInt();

Expand Down Expand Up @@ -1302,17 +1314,11 @@ ASObject* ABCVm::lessEquals(ASObject* obj1, ASObject* obj2)

void ABCVm::initProperty(call_context* th, int n)
{
static int count=0;
ASObject* value=th->runtime_stack_pop();
multiname* name=th->context->getMultiname(n,th);
LOG(CALLS, "initProperty " << *name );
if(name->name_s=="container")
count++;

ASObject* obj=th->runtime_stack_pop();
// if(count==2)
// abort();


obj->setVariableByMultiname(*name,value);
obj->decRef();
Expand All @@ -1327,16 +1333,23 @@ void ABCVm::callSuper(call_context* th, int n, int m)
multiname* name=th->context->getMultiname(n,th);
LOG(NOT_IMPLEMENTED,"callSuper " << *name << ' ' << m);

ASObject* receiver=th->runtime_stack_pop();
abort();
/*ASObject* obj;
if(receiver->super)
obj=receiver->super;
else
obj=receiver;
ASObject* obj=th->runtime_stack_pop();
//HACK (nice) set the max level to the current actual prototype before looking up the member
assert(obj->actualPrototype);
int oldlevel=obj->max_level;
obj->max_level=obj->actualPrototype->max_level-1;
//Store the old prototype
Class_base* old_prototype=obj->actualPrototype;

//Move the object protoype and level up
obj->actualPrototype=old_prototype->super;

ASObject* owner;
ASObject* o=obj->getVariableByMultiname(*name,owner);

//Set back the original max_level
obj->max_level=oldlevel;

if(owner)
{
//If o is already a function call it, otherwise find the Call method
Expand All @@ -1351,7 +1364,7 @@ void ABCVm::callSuper(call_context* th, int n, int m)
LOG(NOT_IMPLEMENTED,"We got a Undefined function");
th->runtime_stack_push(new Undefined);
}
else if(o->getObjectType()==T_DEFINABLE)
/* else if(o->getObjectType()==T_DEFINABLE)
{
LOG(CALLS,"We got a function not yet valid");
Definable* d=static_cast<Definable*>(o);
Expand Down Expand Up @@ -1382,16 +1395,23 @@ void ABCVm::callSuper(call_context* th, int n, int m)
// LOG(NOT_IMPLEMENTED,"No such function, returning Undefined");
// th->runtime_stack_push(new Undefined);
//}
}
}*/
else
abort();
}
else
{
LOG(NOT_IMPLEMENTED,"Calling an undefined function");
th->runtime_stack_push(new Undefined);
}
LOG(CALLS,"End of calling " << name);
receiver->decRef();
delete[] args;*/
LOG(CALLS,"End of calling " << *name);

//Reset prototype to its previous value
assert(obj->actualPrototype==old_prototype->super);
obj->actualPrototype=old_prototype;

obj->decRef();
delete[] args;
}

void ABCVm::callSuperVoid(call_context* th, int n, int m)
Expand Down Expand Up @@ -1475,13 +1495,22 @@ void ABCVm::callSuperVoid(call_context* th, int n, int m)

void ABCVm::isTypelate(call_context* th)
{
LOG(NOT_IMPLEMENTED,"isTypelate: returing true");
LOG(NOT_IMPLEMENTED,"isTypelate");
ASObject* type=th->runtime_stack_pop();
ASObject* obj=th->runtime_stack_pop();
if(obj->getObjectType()==T_UNDEFINED)
{
th->runtime_stack_push(new Boolean(false));
cout << "false" << endl;
}
else
{
cout << "true" << endl;
th->runtime_stack_push(new Boolean(true));
}
// cout << "Name " << type->class_name << " type " << type->getObjectType() << endl;
// cout << "Name " << obj->class_name << " type " << obj->getObjectType() << endl;
// if(type->class_name==obj->class_name)
th->runtime_stack_push(new Boolean(true));
// else
// th->runtime_stack_push(new Boolean(false));
}
Expand Down
12 changes: 7 additions & 5 deletions asobjects.cpp
Expand Up @@ -969,7 +969,10 @@ ASObject* SyntheticFunction::call(ASObject* obj, arguments* args)
int i=0;
if(args)
{
for(i;i<args->size();i++)
int args_len=min(args->size(),mi->numArgs());
if(args_len>mi->numArgs())
assert(mi->needsRest());
for(i;i<args_len;i++)
{
cc->locals[i+1]=args->at(i);
cc->locals[i+1]->incRef();
Expand All @@ -983,10 +986,9 @@ ASObject* SyntheticFunction::call(ASObject* obj, arguments* args)

if(mi->needsRest()) //TODO
{
abort();
/* ASArray* rest=new ASArray();
rest->_constructor(rest,NULL);
cc->locals[mi->numArgs()+1]=rest;*/
Array* rest=Class<Array>::getInstanceS();
rest->_constructor(rest->obj,NULL);
cc->locals[mi->numArgs()+1]=rest->obj;
/*llvm::Value* rest=Builder.CreateCall(ex->FindFunctionNamed("createRest"));
constant = llvm::ConstantInt::get(int_type, param_count+1);
t=Builder.CreateGEP(locals,constant);
Expand Down
23 changes: 19 additions & 4 deletions flashdisplay.cpp
Expand Up @@ -42,6 +42,7 @@ REGISTER_CLASS_NAME(DisplayObject);
REGISTER_CLASS_NAME(DisplayObjectContainer);
REGISTER_CLASS_NAME(Sprite);
REGISTER_CLASS_NAME(Loader);
REGISTER_CLASS_NAME(Shape);

void LoaderInfo::sinit(Class_base* c)
{
Expand Down Expand Up @@ -348,6 +349,7 @@ void MovieClip::sinit(Class_base* c)
{
assert(c->constructor==NULL);
c->constructor=new Function(_constructor);
c->super=Class<Sprite>::getClass();
}

MovieClip::MovieClip():_framesloaded(0),_totalframes(1),cur_frame(&dynamicDisplayList),initialized(false)
Expand Down Expand Up @@ -568,9 +570,7 @@ void MovieClip::initialize()

DisplayObject::DisplayObject():height(100),width(100),loaderInfo(NULL)
{
/* setVariableByQName("Call","",new Function(_call));
setGetterByQName("width","",new Function(_getWidth));
setGetterByQName("height","",new Function(_getHeight));*/
// setVariableByQName("Call","",new Function(_call));
}

void DisplayObject::sinit(Class_base* c)
Expand All @@ -590,7 +590,8 @@ ASFUNCTIONBODY(DisplayObject,_constructor)
obj->setVariableByQName("loaderInfo","",th->loaderInfo->obj);
}

//This should come from DisplayObject
obj->setGetterByQName("width","",new Function(_getWidth));
obj->setGetterByQName("height","",new Function(_getHeight));
//setVariableByQName("getBounds","",new Function(getBounds));
//setVariableByQName("root","",this);
//setVariableByQName("stage","",this);
Expand All @@ -612,6 +613,7 @@ void DisplayObjectContainer::sinit(Class_base* c)
{
assert(c->constructor==NULL);
c->constructor=new Function(_constructor);
c->super=Class<DisplayObject>::getClass();
}

DisplayObjectContainer::DisplayObjectContainer()
Expand All @@ -628,3 +630,16 @@ ASFUNCTIONBODY(DisplayObjectContainer,_getNumChildren)
{
return new Integer(0);;
}

void Shape::sinit(Class_base* c)
{
assert(c->constructor==NULL);
c->constructor=new Function(_constructor);
c->super=Class<DisplayObject>::getClass();
}

ASFUNCTIONBODY(Shape,_constructor)
{
DisplayObject::_constructor(obj,NULL);
}

0 comments on commit 02f3ab2

Please sign in to comment.