aboutsummaryrefslogtreecommitdiffstats
path: root/moth
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2012-11-27 12:17:19 +0100
committerLars Knoll <lars.knoll@digia.com>2012-11-27 12:21:01 +0100
commit3125086ab8e9fe139a9870c1d23b248f04dcb4a3 (patch)
treefd98ee1cf65a885bc8c38c93b3b73f445f38ec89 /moth
parentb32c10a8d36aef52c38ad8b51cef33c100c8df9e (diff)
Add more built-ins to the interpreter.
Change-Id: I6a1656a8a2042b0a02d6e3bb8e59c9db52f6fd5d Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'moth')
-rw-r--r--moth/qv4instr_moth_p.h11
-rw-r--r--moth/qv4isel_moth.cpp71
-rw-r--r--moth/qv4vme_moth.cpp17
3 files changed, 75 insertions, 24 deletions
diff --git a/moth/qv4instr_moth_p.h b/moth/qv4instr_moth_p.h
index 6fba81496e..c3be3a2a08 100644
--- a/moth/qv4instr_moth_p.h
+++ b/moth/qv4instr_moth_p.h
@@ -28,6 +28,7 @@
F(CallBuiltinDeleteSubscript, callBuiltinDeleteSubscript) \
F(CallBuiltinDeleteName, callBuiltinDeleteName) \
F(CallBuiltinDeleteValue, callBuiltinDeleteValue) \
+ F(CallBuiltinDeclareVar, callBuiltinDeclareVar) \
F(CreateValue, createValue) \
F(CreateProperty, createProperty) \
F(CreateActivationProperty, createActivationProperty) \
@@ -179,7 +180,9 @@ union Instr
builtin_delete_exception_handler,
builtin_get_exception,
builtin_foreach_iterator_object,
- builtin_foreach_next_property_name
+ builtin_foreach_next_property_name,
+ builtin_push_with,
+ builtin_pop_with
} builtin;
quint32 argc;
quint32 args;
@@ -207,6 +210,11 @@ union Instr
int tempIndex;
int targetTempIndex;
};
+ struct instr_callBuiltinDeclareVar {
+ MOTH_INSTR_HEADER
+ bool isDeletable;
+ VM::String *varName;
+ };
struct instr_createValue {
MOTH_INSTR_HEADER
int func;
@@ -305,6 +313,7 @@ union Instr
instr_callBuiltinDeleteSubscript callBuiltinDeleteSubscript;
instr_callBuiltinDeleteName callBuiltinDeleteName;
instr_callBuiltinDeleteValue callBuiltinDeleteValue;
+ instr_callBuiltinDeclareVar callBuiltinDeclareVar;
instr_createValue createValue;
instr_createProperty createProperty;
instr_createActivationProperty createActivationProperty;
diff --git a/moth/qv4isel_moth.cpp b/moth/qv4isel_moth.cpp
index 7f4344ba3c..df2f873298 100644
--- a/moth/qv4isel_moth.cpp
+++ b/moth/qv4isel_moth.cpp
@@ -264,6 +264,32 @@ void InstructionSelection::callActivationProperty(IR::Call *c, int targetTempInd
addInstruction(call);
} break;
+ case IR::Name::builtin_delete: {
+ if (IR::Member *m = c->args->expr->asMember()) {
+ Instruction::CallBuiltinDeleteMember call;
+ call.base = m->base->asTemp()->index;
+ call.member = _engine->newString(*m->name);
+ call.targetTempIndex = targetTempIndex;
+ addInstruction(call);
+ } else if (IR::Subscript *ss = c->args->expr->asSubscript()) {
+ Instruction::CallBuiltinDeleteSubscript call;
+ call.base = m->base->asTemp()->index;
+ call.index = ss->index->asTemp()->index;
+ call.targetTempIndex = targetTempIndex;
+ addInstruction(call);
+ } else if (IR::Name *n = c->args->expr->asName()) {
+ Instruction::CallBuiltinDeleteName call;
+ call.name = _engine->newString(*n->id);
+ call.targetTempIndex = targetTempIndex;
+ addInstruction(call);
+ } else {
+ Instruction::CallBuiltinDeleteValue call;
+ call.tempIndex = c->args->expr->asTemp()->index;
+ call.targetTempIndex = targetTempIndex;
+ addInstruction(call);
+ }
+ } break;
+
case IR::Name::builtin_throw: {
IR::Temp *arg = c->args->expr->asTemp();
assert(arg != 0);
@@ -312,29 +338,28 @@ void InstructionSelection::callActivationProperty(IR::Call *c, int targetTempInd
addInstruction(call);
} break;
- case IR::Name::builtin_delete: {
- if (IR::Member *m = c->args->expr->asMember()) {
- Instruction::CallBuiltinDeleteMember call;
- call.base = m->base->asTemp()->index;
- call.member = _engine->newString(*m->name);
- call.targetTempIndex = targetTempIndex;
- addInstruction(call);
- } else if (IR::Subscript *ss = c->args->expr->asSubscript()) {
- Instruction::CallBuiltinDeleteSubscript call;
- call.base = m->base->asTemp()->index;
- call.index = ss->index->asTemp()->index;
- call.targetTempIndex = targetTempIndex;
- addInstruction(call);
- } else if (IR::Name *n = c->args->expr->asName()) {
- Instruction::CallBuiltinDeleteName call;
- call.name = _engine->newString(*n->id);
- call.targetTempIndex = targetTempIndex;
- addInstruction(call);
- } else {
- Instruction::CallBuiltinDeleteValue call;
- call.tempIndex = c->args->expr->asTemp()->index;
- call.targetTempIndex = targetTempIndex;
- addInstruction(call);
+ case IR::Name::builtin_push_with: {
+ Instruction::CallBuiltin call;
+ call.builtin = Instruction::CallBuiltin::builtin_push_with;
+ prepareCallArgs(c->args, call.argc, call.args);
+ assert(call.argc == 1);
+ addInstruction(call);
+ } break;
+
+ case IR::Name::builtin_pop_with: {
+ Instruction::CallBuiltin call;
+ call.builtin = Instruction::CallBuiltin::builtin_pop_with;
+ addInstruction(call);
+ } break;
+
+ case IR::Name::builtin_declare_vars: if (c->args) {
+ IR::Const *deletable = c->args->expr->asConst();
+ assert(deletable->type == IR::BoolType);
+ const bool isDeletable = deletable->value != 0;
+ for (IR::ExprList *it = c->args->next; it; it = it->next) {
+ Instruction::CallBuiltinDeclareVar call;
+ call.isDeletable = isDeletable;
+ call.varName = _engine->newString(*it->expr->asName()->id);
}
} break;
diff --git a/moth/qv4vme_moth.cpp b/moth/qv4vme_moth.cpp
index 46bd64299c..5a0ba30b25 100644
--- a/moth/qv4vme_moth.cpp
+++ b/moth/qv4vme_moth.cpp
@@ -212,10 +212,12 @@ VM::Value VME::operator()(QQmlJS::VM::ExecutionContext *context, const uchar *co
void *buf;
switch (instr.builtin) {
case Instr::instr_callBuiltin::builtin_typeof:
+ Q_ASSERT(instr.argc == 1);
TEMP(instr.targetTempIndex) = __qmljs_builtin_typeof(args[0], context);
break;
case Instr::instr_callBuiltin::builtin_throw:
TRACE(builtin_throw, "Throwing now...%s", "");
+ Q_ASSERT(instr.argc == 1);
__qmljs_builtin_throw(args[0], context);
break;
case Instr::instr_callBuiltin::builtin_create_exception_handler: {
@@ -245,11 +247,22 @@ VM::Value VME::operator()(QQmlJS::VM::ExecutionContext *context, const uchar *co
TEMP(instr.targetTempIndex) = __qmljs_get_exception(context);
break;
case Instr::instr_callBuiltin::builtin_foreach_iterator_object:
+ Q_ASSERT(instr.argc == 1);
TEMP(instr.targetTempIndex) = __qmljs_foreach_iterator_object(args[0], context);
break;
case Instr::instr_callBuiltin::builtin_foreach_next_property_name:
+ Q_ASSERT(instr.argc == 1);
TEMP(instr.targetTempIndex) = __qmljs_foreach_next_property_name(args[0]);
break;
+ case Instr::instr_callBuiltin::builtin_push_with:
+ Q_ASSERT(instr.argc == 1);
+ __qmljs_builtin_push_with(args[0], context);
+ break;
+ case Instr::instr_callBuiltin::builtin_pop_with:
+ __qmljs_builtin_pop_with(context);
+ break;
+ default:
+ Q_UNREACHABLE();
}
MOTH_END_INSTR(CallBuiltin)
@@ -269,6 +282,10 @@ VM::Value VME::operator()(QQmlJS::VM::ExecutionContext *context, const uchar *co
TEMP(instr.targetTempIndex) = VM::Value::fromBoolean(false);
MOTH_END_INSTR(CallBuiltinDeleteValue)
+ MOTH_BEGIN_INSTR(CallBuiltinDeclareVar)
+ __qmljs_builtin_declare_var(context, instr.isDeletable, instr.varName);
+ MOTH_END_INSTR(CallBuiltinDeleteValue)
+
MOTH_BEGIN_INSTR(CreateValue)
VM::Value *args = stack.data() + instr.args;
TEMP(instr.targetTempIndex) = __qmljs_construct_value(context, TEMP(instr.func), args, instr.argc);