Adapt get/set_element to new calling convention

Change-Id: I5e2bca8ee2435bf678dbf9eb15172ed59c80b52e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Lars Knoll 2013-02-14 20:58:10 +01:00 committed by Simon Hausmann
parent 61b941f717
commit e2ebdffd15
12 changed files with 47 additions and 33 deletions

View 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)

View 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);

View 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);

View 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)

View 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) {

View 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);

View 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);

View 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);

View 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)

View 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);

View 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;
}
}

View 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;