From: Roberto Raggi Date: Wed, 9 May 2012 09:28:57 +0000 (+0200) Subject: Some progress on closures. X-Git-Tag: upstream/5.2.1~669^2~659^2~1220 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=80af77292ef8ee1ae7be8e543edacfe17ae3f96f;p=platform%2Fupstream%2Fqtdeclarative.git Some progress on closures. --- diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index 8dfcb82..bdc4d98 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -192,6 +192,13 @@ void __qmljs_set_property_string(Context *ctx, Value *object, String *name, Stri object->objectValue->put(name, value, /*flag*/ 0); } +void __qmljs_set_property_closure(Context *ctx, Value *object, String *name, IR::Function *function) +{ + Value value; + __qmljs_init_object(ctx, &value, new VM::ScriptFunction(function)); + object->objectValue->put(name, value, /*flag*/ 0); +} + void __qmljs_set_activation_property(Context *ctx, String *name, Value *value) { __qmljs_set_property(ctx, &ctx->activation, name, value); @@ -217,6 +224,11 @@ void __qmljs_set_activation_property_string(Context *ctx, String *name, String * __qmljs_set_property_string(ctx, &ctx->activation, name, value); } +void __qmljs_set_activation_property_closure(Context *ctx, String *name, IR::Function *value) +{ + __qmljs_set_property_closure(ctx, &ctx->activation, name, value); +} + void __qmljs_get_property(Context *ctx, Value *result, Value *object, String *name) { if (object->type == OBJECT_TYPE) { diff --git a/qmljs_runtime.h b/qmljs_runtime.h index 61aa230..70a5782 100644 --- a/qmljs_runtime.h +++ b/qmljs_runtime.h @@ -6,6 +6,11 @@ #include namespace QQmlJS { + +namespace IR { +struct Function; +} + namespace VM { enum ValueType { @@ -83,10 +88,12 @@ void __qmljs_set_property(Context *ctx, Value *object, String *name, Value *valu void __qmljs_set_property_boolean(Context *ctx, Value *object, String *name, bool value); void __qmljs_set_property_number(Context *ctx, Value *object, String *name, double value); void __qmljs_set_property_string(Context *ctx, Value *object, String *name, String *value); +void __qmljs_set_property_closure(Context *ctx, Value *object, String *name, IR::Function *function); void __qmljs_set_activation_property(Context *ctx, String *name, Value *value); void __qmljs_set_activation_property_boolean(Context *ctx, String *name, bool value); void __qmljs_set_activation_property_number(Context *ctx, String *name, double value); void __qmljs_set_activation_property_string(Context *ctx, String *name, String *value); +void __qmljs_set_activation_property_closure(Context *ctx, String *name, IR::Function *function); void __qmljs_get_property(Context *ctx, Value *result, Value *object, String *name); void __qmljs_get_activation_property(Context *ctx, Value *result, String *name); void __qmljs_copy_activation_property(Context *ctx, String *name, String *other); diff --git a/qv4isel.cpp b/qv4isel.cpp index 4fb6ca0..72a4bdb 100644 --- a/qv4isel.cpp +++ b/qv4isel.cpp @@ -308,6 +308,12 @@ void InstructionSelection::visitMove(IR::Move *s) amd64_mov_reg_imm(_codePtr, AMD64_RDX, identifier(*other->id)); amd64_call_code(_codePtr, __qmljs_copy_activation_property); return; + } else if (IR::Closure *clos = s->source->asClosure()) { + amd64_mov_reg_reg(_codePtr, AMD64_RDI, AMD64_R14, 8); + amd64_mov_reg_imm(_codePtr, AMD64_RSI, propertyName); + amd64_mov_reg_imm(_codePtr, AMD64_RDX, clos->value); + amd64_call_code(_codePtr, __qmljs_set_activation_property_closure); + return; } } else if (IR::Temp *t = s->target->asTemp()) { if (IR::Name *n = s->source->asName()) { @@ -502,6 +508,13 @@ void InstructionSelection::visitMove(IR::Move *s) amd64_mov_reg_imm(_codePtr, AMD64_RCX, VM::String::get(0, *str->value)); amd64_call_code(_codePtr, __qmljs_set_property_string); return; + } else if (IR::Closure *clos = s->source->asClosure()) { + amd64_mov_reg_reg(_codePtr, AMD64_RDI, AMD64_R14, 8); + loadTempAddress(AMD64_RSI, base); + amd64_mov_reg_imm(_codePtr, AMD64_RDX, identifier(*m->name)); + amd64_mov_reg_imm(_codePtr, AMD64_RCX, clos->value); + amd64_call_code(_codePtr, __qmljs_set_property_closure); + return; } } } diff --git a/tests/fun.1.js b/tests/fun.1.js new file mode 100644 index 0000000..9d73cad --- /dev/null +++ b/tests/fun.1.js @@ -0,0 +1,7 @@ + +function foo(a,b) { print(a, b) } +var foo2 = foo +var foo3 = function(a,b) { print(a, b); } +foo(1,2) +foo2(1,2) +foo3(1, 2)