Added loading of "this" and renamed "ActivateProperty" to "StoreName".
authorErik Verbruggen <erik.verbruggen@digia.com>
Wed, 24 Oct 2012 11:45:43 +0000 (13:45 +0200)
committerLars Knoll <lars.knoll@digia.com>
Wed, 24 Oct 2012 12:04:30 +0000 (14:04 +0200)
Change-Id: I033abe53368a815a9e3d036021429732f5526ea2
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
moth/qv4instr_moth_p.h
moth/qv4isel_moth.cpp
moth/qv4vme_moth.cpp

index 1637963..bddf307 100644 (file)
     F(LoadTemp, loadTemp) \
     F(MoveTemp, moveTemp) \
     F(LoadName, loadName) \
+    F(StoreName, storeName) \
     F(Push, push) \
     F(Call, call) \
     F(Jump, jump) \
     F(CJump, jump) \
     F(Binop, binop) \
-    F(ActivateProperty, activateProperty)
+    F(LoadThis, loadThis)
 
 #if defined(Q_CC_GNU) && (!defined(Q_CC_INTEL) || __INTEL_COMPILER >= 1200)
 #  define MOTH_THREADED_INTERPRETER
@@ -83,7 +84,11 @@ union Instr
     };
     struct instr_loadName {
         MOTH_INSTR_HEADER
-        VM::String *value;
+        VM::String *name;
+    };
+    struct instr_storeName {
+        MOTH_INSTR_HEADER
+        VM::String *name;
     };
     struct instr_push {
         MOTH_INSTR_HEADER
@@ -104,9 +109,8 @@ union Instr
         int rhsTempIndex;
         VM::Value (*alu)(const VM::Value , const VM::Value, VM::Context *);
     };
-    struct instr_activateProperty {
+    struct instr_loadThis {
         MOTH_INSTR_HEADER
-        VM::String *propName;
     };
 
     instr_common common;
@@ -118,11 +122,12 @@ union Instr
     instr_loadString loadString;
     instr_loadClosure loadClosure;
     instr_loadName loadName;
+    instr_storeName storeName;
     instr_push push;
     instr_call call;
     instr_jump jump;
     instr_binop binop;
-    instr_activateProperty activateProperty;
+    instr_loadThis loadThis;
 
     static int size(Type type);
 };
index 6a3e70d..0ae5bcd 100644 (file)
@@ -58,7 +58,7 @@ void InstructionSelection::visitExp(IR::Exp *s)
         if (IR::Name *n = c->base->asName()) {
             if (n->builtin == IR::Name::builtin_invalid) {
                 Instruction::LoadName load;
-                load.value = _engine->newString(*n->id);
+                load.name = _engine->newString(*n->id);
                 addInstruction(load);
             } else {
                 Q_UNIMPLEMENTED();
@@ -206,21 +206,29 @@ void InstructionSelection::simpleMove(IR::Move *s)
         Q_UNUSED(n);
         // set activation property
         if (IR::Temp *t = s->source->asTemp()) {
+            // TODO: fold the next 2 instructions.
             Instruction::LoadTemp load;
             load.tempIndex = t->index;
             addInstruction(load);
 
-            Instruction::ActivateProperty activate;
-            activate.propName = _engine->newString(*n->id);
-            addInstruction(activate);
+            Instruction::StoreName store;
+            store.name = _engine->newString(*n->id);
+            addInstruction(store);
         } else {
             Q_UNREACHABLE();
         }
     } else if (IR::Temp *t = s->target->asTemp()) {
-
+        // Check what kind of load it is, and generate the instruction for that.
+        // The store to the temp (the target) is done afterwards.
         if (IR::Name *n = s->source->asName()) {
             Q_UNUSED(n);
-            qWarning("  NAME");
+            if (*n->id == QStringLiteral("this")) { // ### `this' should be a builtin.
+                addInstruction(Instruction::LoadThis());
+            } else {
+                Instruction::LoadName load;
+                load.name = _engine->newString(*n->id);
+                addInstruction(load);
+            }
         } else if (IR::Const *c = s->source->asConst()) {
             switch (c->type) {
             case IR::UndefinedType:
index a9d7c09..8c01768 100644 (file)
@@ -5,7 +5,7 @@ using namespace QQmlJS;
 using namespace QQmlJS::Moth;
 
 #ifdef DO_TRACE_INSTR
-#  define TRACE_INSTR(I) fprintf(stderr, "%s\n", #I);
+#  define TRACE_INSTR(I) fprintf(stderr, "executing a %s\n", #I);
 #  define TRACE(n, str, ...) { fprintf(stderr, "-- %s : ", #n); fprintf(stderr, str, __VA_ARGS__); fprintf(stderr, "\n"); }
 #else
 #  define TRACE_INSTR(I)
@@ -135,9 +135,15 @@ void VME::operator()(QQmlJS::VM::Context *context, const uchar *code
     MOTH_END_INSTR(LoadClosure)
 
     MOTH_BEGIN_INSTR(LoadName)
-        tempRegister = __qmljs_get_activation_property(context, instr.value);
+        TRACE(inline, "property name = %s", instr.name->toQString().toUtf8().constData());
+        tempRegister = __qmljs_get_activation_property(context, instr.name);
     MOTH_END_INSTR(LoadName)
 
+    MOTH_BEGIN_INSTR(StoreName)
+        TRACE(inline, "property name = %s", instr.name->toQString().toUtf8().constData());
+        __qmljs_set_activation_property(context, instr.name, tempRegister);
+    MOTH_END_INSTR(StoreName)
+
     MOTH_BEGIN_INSTR(Push)
         stack.resize(instr.value);
     MOTH_END_INSTR(Push)
@@ -165,10 +171,9 @@ void VME::operator()(QQmlJS::VM::Context *context, const uchar *code
         return;
     MOTH_END_INSTR(Ret)
 
-    MOTH_BEGIN_INSTR(ActivateProperty)
-        TRACE(inline, "property name = %s", instr.propName->toQString().toUtf8().constData());
-        __qmljs_set_activation_property(context, instr.propName, tempRegister);
-    MOTH_END_INSTR(ActivateProperty)
+    MOTH_BEGIN_INSTR(LoadThis)
+        tempRegister = __qmljs_get_thisObject(context);
+    MOTH_END_INSTR(LoadThis)
 
 #ifdef MOTH_THREADED_INTERPRETER
     // nothing to do