Adapt get/set_element to new calling convention
authorLars Knoll <lars.knoll@digia.com>
Thu, 14 Feb 2013 19:58:10 +0000 (20:58 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 14 Feb 2013 21:23:26 +0000 (22:23 +0100)
Change-Id: I5e2bca8ee2435bf678dbf9eb15172ed59c80b52e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
12 files changed:
src/v4/llvm_runtime.cpp
src/v4/moth/qv4isel_moth.cpp
src/v4/moth/qv4isel_moth_p.h
src/v4/moth/qv4vme_moth.cpp
src/v4/qmljs_runtime.cpp
src/v4/qmljs_runtime.h
src/v4/qv4isel_llvm.cpp
src/v4/qv4isel_llvm_p.h
src/v4/qv4isel_masm.cpp
src/v4/qv4isel_masm_p.h
src/v4/qv4isel_p.cpp
src/v4/qv4isel_p.h

index 85cb816..2946b4e 100644 (file)
@@ -445,7 +445,7 @@ void __qmljs_llvm_construct_property(ExecutionContext *context, Value *result, c
 
 void __qmljs_llvm_get_element(ExecutionContext *ctx, Value *result, Value *object, Value *index)
 {
-    *result = __qmljs_get_element(ctx, *object, *index);
+    __qmljs_get_element(ctx, result, *object, *index);
 }
 
 void __qmljs_llvm_set_element(ExecutionContext *ctx, Value *object, Value *index, Value *value)
index fccd750..bd9fc24 100644 (file)
@@ -463,7 +463,7 @@ void InstructionSelection::getElement(IR::Temp *base, IR::Temp *index, IR::Temp
     addInstruction(load);
 }
 
-void InstructionSelection::setElement(IR::Expr *source, IR::Temp *targetBase, IR::Temp *targetIndex)
+void InstructionSelection::setElement(IR::Temp *source, IR::Temp *targetBase, IR::Temp *targetIndex)
 {
     Instruction::StoreElement store;
     store.base = getParam(targetBase);
index 8a859d1..04f8b9d 100644 (file)
@@ -71,7 +71,7 @@ protected:
     virtual void getProperty(IR::Temp *base, const QString &name, IR::Temp *target);
     virtual void setProperty(IR::Temp *source, IR::Temp *targetBase, const QString &targetName);
     virtual void getElement(IR::Temp *base, IR::Temp *index, IR::Temp *target);
-    virtual void setElement(IR::Expr *source, IR::Temp *targetBase, IR::Temp *targetIndex);
+    virtual void setElement(IR::Temp *source, IR::Temp *targetBase, IR::Temp *targetIndex);
     virtual void copyValue(IR::Temp *sourceTemp, IR::Temp *targetTemp);
     virtual void unop(IR::AluOp oper, IR::Temp *sourceTemp, IR::Temp *targetTemp);
     virtual void binop(IR::AluOp oper, IR::Temp *leftSource, IR::Temp *rightSource, IR::Temp *target);
index 3850955..4fea463 100644 (file)
@@ -186,7 +186,7 @@ VM::Value VME::operator()(QQmlJS::VM::ExecutionContext *context, const uchar *co
     MOTH_END_INSTR(StoreName)
 
     MOTH_BEGIN_INSTR(LoadElement)
-        VALUE(instr.result) = __qmljs_get_element(context, VALUE(instr.base), VALUE(instr.index));
+         __qmljs_get_element(context, VALUEPTR(instr.result), VALUE(instr.base), VALUE(instr.index));
     MOTH_END_INSTR(LoadElement)
 
     MOTH_BEGIN_INSTR(StoreElement)
index f41208b..8b9e4f6 100644 (file)
@@ -581,43 +581,52 @@ void __qmljs_set_property(ExecutionContext *ctx, const Value &object, String *na
     o->__put__(ctx, name, value);
 }
 
-Value __qmljs_get_element(ExecutionContext *ctx, Value object, Value index)
+void __qmljs_get_element(ExecutionContext *ctx, Value *result, const Value &object, const Value &index)
 {
     uint type = object.type();
     uint idx = index.asArrayIndex();
 
-    if (type != Value::Object_Type) {
+    Object *o = object.asObject();
+    if (!o) {
         if (type == Value::String_Type && idx < UINT_MAX) {
             String *str = object.stringValue();
-            if (idx >= (uint)str->toQString().length())
-                return Value::undefinedValue();
+            if (idx >= (uint)str->toQString().length()) {
+                if (result)
+                    *result = Value::undefinedValue();
+                return;
+            }
             const QString s = str->toQString().mid(idx, 1);
-            return Value::fromString(ctx, s);
+            if (result)
+                *result = Value::fromString(ctx, s);
+            return;
         }
 
-        object = __qmljs_to_object(object, ctx);
+        o = __qmljs_to_object(object, ctx).objectValue();
     }
 
-    Object *o = object.objectValue();
-
     if (idx < UINT_MAX) {
         const PropertyDescriptor *p = o->nonSparseArrayAt(idx);
-        if (p && p->type == PropertyDescriptor::Data)
-            return p->value;
+        if (p && p->type == PropertyDescriptor::Data) {
+            if (result)
+                *result = p->value;
+            return;
+        }
 
-        return o->__get__(ctx, idx);
+        Value res = o->__get__(ctx, idx);
+        if (result)
+            *result = res;
+        return;
     }
 
     String *name = index.toString(ctx);
-    return o->__get__(ctx, name);
+    Value res = o->__get__(ctx, name);
+    if (result)
+        *result = res;
 }
 
-void __qmljs_set_element(ExecutionContext *ctx, Value object, Value index, Value value)
+void __qmljs_set_element(ExecutionContext *ctx, const Value &object, const Value &index, const Value &value)
 {
-    if (!object.isObject())
-        object = __qmljs_to_object(object, ctx);
-
-    Object *o = object.objectValue();
+    Object *o = __qmljs_to_object(object, ctx).objectValue();
 
     uint idx = index.asArrayIndex();
     if (idx < UINT_MAX) {
index 39699d9..7c4e438 100644 (file)
@@ -174,8 +174,8 @@ void __qmljs_get_property_lookup(ExecutionContext *ctx, Value *result, const Val
 void __qmljs_set_property_lookup(ExecutionContext *ctx, const Value &object, int lookupIndex, const Value &value);
 
 
-Value __qmljs_get_element(ExecutionContext *ctx, Value object, Value index);
-void __qmljs_set_element(ExecutionContext *ctx, Value object, Value index, Value value);
+void __qmljs_get_element(ExecutionContext *ctx, Value *retval, const Value &object, const Value &index);
+void __qmljs_set_element(ExecutionContext *ctx, const Value &object, const Value &index, const Value &value);
 
 // For each
 Value __qmljs_foreach_iterator_object(Value in, ExecutionContext *ctx);
@@ -428,6 +428,9 @@ inline Value __qmljs_to_string(const Value &value, ExecutionContext *ctx)
 
 inline Value __qmljs_to_object(const Value &value, ExecutionContext *ctx)
 {
+    if (value.isObject())
+        return value;
+
     switch (value.type()) {
     case Value::Undefined_Type:
     case Value::Null_Type:
@@ -440,7 +443,7 @@ inline Value __qmljs_to_object(const Value &value, ExecutionContext *ctx)
         return __qmljs_new_string_object(ctx, value.stringValue());
         break;
     case Value::Object_Type:
-        return value;
+        Q_UNREACHABLE();
         break;
     case Value::Integer_Type:
         return __qmljs_new_number_object(ctx, value.int_32);
index 26411d8..a10328b 100644 (file)
@@ -647,7 +647,7 @@ void InstructionSelection::getElement(IR::Temp *sourceBase, IR::Temp *sourceInde
                 _llvmFunction->arg_begin(), t, base, index);
 }
 
-void InstructionSelection::setElement(IR::Expr *source, IR::Temp *targetBase, IR::Temp *targetIndex)
+void InstructionSelection::setElement(IR::Temp *source, IR::Temp *targetBase, IR::Temp *targetIndex)
 {
     llvm::Value *base = getLLVMTempReference(targetBase);
     llvm::Value *index = getLLVMTempReference(targetIndex);
index 3f6dc47..9b4aa36 100644 (file)
@@ -115,7 +115,7 @@ public: // methods from InstructionSelection:
     virtual void getProperty(IR::Temp *sourceBase, const QString &sourceName, IR::Temp *target);
     virtual void setProperty(IR::Temp *source, IR::Temp *targetBase, const QString &targetName);
     virtual void getElement(IR::Temp *sourceBase, IR::Temp *sourceIndex, IR::Temp *target);
-    virtual void setElement(IR::Expr *source, IR::Temp *targetBase, IR::Temp *targetIndex);
+    virtual void setElement(IR::Temp *source, IR::Temp *targetBase, IR::Temp *targetIndex);
     virtual void copyValue(IR::Temp *sourceTemp, IR::Temp *targetTemp);
     virtual void unop(IR::AluOp oper, IR::Temp *sourceTemp, IR::Temp *targetTemp);
     virtual void binop(IR::AluOp oper, IR::Temp *leftSource, IR::Temp *rightSource, IR::Temp *target);
index 591de83..7dfd8ed 100644 (file)
@@ -721,12 +721,14 @@ void InstructionSelection::setProperty(IR::Temp *source, IR::Temp *targetBase, c
 
 void InstructionSelection::getElement(IR::Temp *base, IR::Temp *index, IR::Temp *target)
 {
-    generateFunctionCall(target, __qmljs_get_element, Assembler::ContextRegister, base, index);
+    generateFunctionCall(Assembler::Void, __qmljs_get_element, Assembler::ContextRegister,
+                         Assembler::PointerToValue(target), Assembler::PointerToValue(base), Assembler::PointerToValue(index));
 }
 
-void InstructionSelection::setElement(IR::Expr *source, IR::Temp *targetBase, IR::Temp *targetIndex)
+void InstructionSelection::setElement(IR::Temp *source, IR::Temp *targetBase, IR::Temp *targetIndex)
 {
-    generateFunctionCall(Assembler::Void, __qmljs_set_element, Assembler::ContextRegister, targetBase, targetIndex, source);
+    generateFunctionCall(Assembler::Void, __qmljs_set_element, Assembler::ContextRegister,
+                         Assembler::PointerToValue(targetBase), Assembler::PointerToValue(targetIndex), Assembler::PointerToValue(source));
 }
 
 void InstructionSelection::copyValue(IR::Temp *sourceTemp, IR::Temp *targetTemp)
index 77d1ce9..08ab7ea 100644 (file)
@@ -721,7 +721,7 @@ protected:
     virtual void getProperty(IR::Temp *base, const QString &name, IR::Temp *target);
     virtual void setProperty(IR::Temp *source, IR::Temp *targetBase, const QString &targetName);
     virtual void getElement(IR::Temp *base, IR::Temp *index, IR::Temp *target);
-    virtual void setElement(IR::Expr *source, IR::Temp *targetBase, IR::Temp *targetIndex);
+    virtual void setElement(IR::Temp *source, IR::Temp *targetBase, IR::Temp *targetIndex);
     virtual void copyValue(IR::Temp *sourceTemp, IR::Temp *targetTemp);
     virtual void unop(IR::AluOp oper, IR::Temp *sourceTemp, IR::Temp *targetTemp);
     virtual void binop(IR::AluOp oper, IR::Temp *leftSource, IR::Temp *rightSource, IR::Temp *target);
index eed2d0b..56f4ce7 100644 (file)
@@ -151,8 +151,8 @@ void InstructionSelection::visitMove(IR::Move *s)
                 }
             }
         } else if (IR::Subscript *ss = s->target->asSubscript()) {
-            if (s->source->asTemp() || s->source->asConst()) {
-                setElement(s->source, ss->base->asTemp(), ss->index->asTemp());
+            if (s->source->asTemp()) {
+                setElement(s->source->asTemp(), ss->base->asTemp(), ss->index->asTemp());
                 return;
             }
         }
index d41bd78..b336e3a 100644 (file)
@@ -131,7 +131,7 @@ public: // to implement by subclasses:
     virtual void getProperty(IR::Temp *base, const QString &name, IR::Temp *target) = 0;
     virtual void setProperty(IR::Temp *source, IR::Temp *targetBase, const QString &targetName) = 0;
     virtual void getElement(IR::Temp *base, IR::Temp *index, IR::Temp *target) = 0;
-    virtual void setElement(IR::Expr *source, IR::Temp *targetBase, IR::Temp *targetIndex) = 0;
+    virtual void setElement(IR::Temp *source, IR::Temp *targetBase, IR::Temp *targetIndex) = 0;
     virtual void copyValue(IR::Temp *sourceTemp, IR::Temp *targetTemp) = 0;
     virtual void unop(IR::AluOp oper, IR::Temp *sourceTemp, IR::Temp *targetTemp) = 0;
     virtual void binop(IR::AluOp oper, IR::Temp *leftSource, IR::Temp *rightSource, IR::Temp *target) = 0;