Fix instruction selections for closures.
authorRoberto Raggi <roberto.raggi@nokia.com>
Wed, 9 May 2012 11:51:44 +0000 (13:51 +0200)
committerRoberto Raggi <roberto.raggi@nokia.com>
Wed, 9 May 2012 11:51:44 +0000 (13:51 +0200)
qmljs_runtime.cpp
qmljs_runtime.h
qv4isel.cpp

index 0b8eca8..b9811af 100644 (file)
@@ -15,6 +15,11 @@ Value Value::string(Context *ctx, const QString &s)
 
 extern "C" {
 
+void __qmljs_init_closure(Context *ctx, Value *result, IR::Function *clos)
+{
+    __qmljs_init_object(ctx, result, new ScriptFunction(clos));
+}
+
 void __qmljs_string_literal_undefined(Context *ctx, Value *result)
 {
     __qmljs_init_string(ctx, result, String::get(ctx, QLatin1String("undefined")));
index d2e72bc..7e815a7 100644 (file)
@@ -57,6 +57,7 @@ void __qmljs_init_boolean(Context *ctx, Value *result, bool value);
 void __qmljs_init_number(Context *ctx, Value *result, double number);
 void __qmljs_init_string(Context *ctx, Value *result, String *string);
 void __qmljs_init_object(Context *ctx, Value *result, Object *object);
+void __qmljs_init_closure(Context *, Value *result, IR::Function *clos);
 
 bool __qmljs_is_function(Context *ctx, const Value *value);
 
index e574392..16d278d 100644 (file)
@@ -23,6 +23,10 @@ using namespace QQmlJS;
 using namespace QQmlJS::x86_64;
 using namespace QQmlJS::VM;
 
+namespace {
+QTextStream qout(stdout, QIODevice::WriteOnly);
+}
+
 static inline void
 amd64_patch (unsigned char* code, gpointer target)
 {
@@ -136,6 +140,7 @@ void InstructionSelection::operator()(IR::Function *function)
 #ifndef NO_UDIS86
     static bool showCode = !qgetenv("SHOW_CODE").isNull();
     if (showCode) {
+        printf("code size: %ld bytes\n", (_codePtr - _code));
         ud_t ud_obj;
 
         ud_init(&ud_obj);
@@ -418,6 +423,12 @@ void InstructionSelection::visitMove(IR::Move *s)
                 amd64_mov_reg_imm(_codePtr, AMD64_RDX, new String(*str->value));
                 amd64_call_code(_codePtr, __qmljs_init_string);
                 return;
+            } else if (IR::Closure *clos = s->source->asClosure()) {
+                amd64_mov_reg_reg(_codePtr, AMD64_RDI, AMD64_R14, 8);
+                loadTempAddress(AMD64_RSI, t);
+                amd64_mov_reg_imm(_codePtr, AMD64_RDX, clos->value);
+                amd64_call_code(_codePtr, __qmljs_init_closure);
+                return;
             } else if (IR::New *ctor = s->source->asNew()) {
                 constructActivationProperty(ctor, t);
                 return;
@@ -584,7 +595,10 @@ void InstructionSelection::visitMove(IR::Move *s)
     } else {
         // inplace assignment, e.g. x += 1, ++x, ...
     }
+
     Q_UNIMPLEMENTED();
+    s->dump(qout, IR::Stmt::MIR);
+    qout << endl;
     assert(!"TODO");
 }