aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/compiler')
-rw-r--r--src/qml/compiler/qv4codegen.cpp52
-rw-r--r--src/qml/compiler/qv4compileddata.cpp38
-rw-r--r--src/qml/compiler/qv4compileddata_p.h2
-rw-r--r--src/qml/compiler/qv4compilercontext.cpp8
4 files changed, 49 insertions, 51 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 09c0e60f4d..75c47164c9 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -3059,34 +3059,36 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast,
statementList(body);
- bytecodeGenerator->setLocation(ast->lastSourceLocation());
- _context->emitBlockFooter(this);
-
- if (_returnLabel || hasError || !functionEndsWithReturn) {
- if (_returnLabel)
- _returnLabel->link();
+ if (!hasError) {
+ bytecodeGenerator->setLocation(ast->lastSourceLocation());
+ _context->emitBlockFooter(this);
+
+ if (_returnLabel || !functionEndsWithReturn) {
+ if (_returnLabel)
+ _returnLabel->link();
+
+ if (_returnLabel || requiresReturnValue) {
+ Instruction::LoadReg load;
+ load.reg = Moth::StackSlot::createRegister(_returnAddress);
+ bytecodeGenerator->addInstruction(load);
+ } else {
+ Reference::fromConst(this, Encode::undefined()).loadInAccumulator();
+ }
- if (_returnLabel || requiresReturnValue) {
- Instruction::LoadReg load;
- load.reg = Moth::StackSlot::createRegister(_returnAddress);
- bytecodeGenerator->addInstruction(load);
- } else {
- Reference::fromConst(this, Encode::undefined()).loadInAccumulator();
+ bytecodeGenerator->addInstruction(Instruction::Ret());
}
- bytecodeGenerator->addInstruction(Instruction::Ret());
- }
-
- Q_ASSERT(_context == _functionContext);
- bytecodeGenerator->finalize(_context);
- _context->registerCountInFunction = bytecodeGenerator->registerCount();
- static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_BYTECODE");
- if (showCode) {
- qDebug() << "=== Bytecode for" << _context->name << "strict mode" << _context->isStrict
- << "register count" << _context->registerCountInFunction << "implicit return" << requiresReturnValue;
- QV4::Moth::dumpBytecode(_context->code, _context->locals.size(), _context->arguments.size(),
- _context->line, _context->lineNumberMapping);
- qDebug();
+ Q_ASSERT(_context == _functionContext);
+ bytecodeGenerator->finalize(_context);
+ _context->registerCountInFunction = bytecodeGenerator->registerCount();
+ static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_BYTECODE");
+ if (showCode) {
+ qDebug() << "=== Bytecode for" << _context->name << "strict mode" << _context->isStrict
+ << "register count" << _context->registerCountInFunction << "implicit return" << requiresReturnValue;
+ QV4::Moth::dumpBytecode(_context->code, _context->locals.size(), _context->arguments.size(),
+ _context->line, _context->lineNumberMapping);
+ qDebug();
+ }
}
qSwap(_returnAddress, returnAddress);
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index 3b2d6e0a48..b8497937c1 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -415,13 +415,20 @@ QStringList CompilationUnit::moduleRequests() const
Heap::Module *CompilationUnit::instantiate(ExecutionEngine *engine)
{
- if (m_module)
+ if (isESModule() && m_module)
return m_module;
+ if (data->indexOfRootFunction < 0)
+ return nullptr;
+
if (!this->engine)
linkToEngine(engine);
- m_module = engine->memoryManager->allocate<Module>(engine, this);
+ Scope scope(engine);
+ Scoped<Module> module(scope, engine->memoryManager->allocate<Module>(engine, this));
+
+ if (isESModule())
+ m_module = module->d();
for (const QString &request: moduleRequests()) {
auto dependentModuleUnit = engine->loadModule(QUrl(request), this);
@@ -430,7 +437,6 @@ Heap::Module *CompilationUnit::instantiate(ExecutionEngine *engine)
dependentModuleUnit->instantiate(engine);
}
- Scope scope(engine);
ScopedString importName(scope);
const uint importCount = data->importEntryTableSize;
@@ -465,7 +471,7 @@ Heap::Module *CompilationUnit::instantiate(ExecutionEngine *engine)
}
}
- return m_module;
+ return module->d();
}
const Value *CompilationUnit::resolveExport(QV4::String *exportName)
@@ -590,10 +596,13 @@ void CompilationUnit::getExportedNamesRecursively(QStringList *names, QVector<co
void CompilationUnit::evaluate()
{
- if (m_moduleEvaluated)
- return;
- m_moduleEvaluated = true;
+ QV4::Scope scope(engine);
+ QV4::Scoped<Module> module(scope, m_module);
+ module->evaluate();
+}
+void CompilationUnit::evaluateModuleRequests()
+{
for (const QString &request: moduleRequests()) {
auto dependentModuleUnit = engine->loadModule(QUrl(request), this);
if (engine->hasException)
@@ -602,19 +611,6 @@ void CompilationUnit::evaluate()
if (engine->hasException)
return;
}
-
- QV4::Function *moduleFunction = runtimeFunctions[data->indexOfRootFunction];
- CppStackFrame frame;
- frame.init(engine, moduleFunction, nullptr, 0);
- frame.setupJSFrame(engine->jsStackTop, Value::undefinedValue(), m_module->scope,
- Value::undefinedValue(), Value::undefinedValue());
-
- frame.push();
- engine->jsStackTop += frame.requiredJSStackFrameSize();
- auto frameCleanup = qScopeGuard([&frame]() {
- frame.pop();
- });
- Moth::VME::exec(&frame, engine);
}
bool CompilationUnit::loadFromDisk(const QUrl &url, const QDateTime &sourceTimeStamp, QString *errorString)
@@ -768,7 +764,7 @@ QString Binding::valueAsString(const CompilationUnit *unit) const
case Type_Translation: {
const TranslationData &translation = unit->unitData()->translations()[value.translationDataIndex];
// This code must match that in the qsTr() implementation
- const QString &path = unit->stringAt(unit->unitData()->sourceFileIndex);
+ const QString &path = unit->fileName();
int lastSlash = path.lastIndexOf(QLatin1Char('/'));
QStringRef context = (lastSlash > -1) ? path.midRef(lastSlash + 1, path.length() - lastSlash - 5)
: QStringRef();
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index d0785c6883..7c26b0b67d 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -1223,6 +1223,7 @@ public:
const Value *resolveExport(QV4::String *exportName);
QStringList exportedNames() const;
void evaluate();
+ void evaluateModuleRequests();
QV4::Function *linkToEngine(QV4::ExecutionEngine *engine);
void unlink();
@@ -1265,7 +1266,6 @@ private:
Q_NEVER_INLINE IdentifierHash createNamedObjectsPerComponent(int componentObjectIndex);
Heap::Module *m_module = nullptr;
- bool m_moduleEvaluated = false;
public:
#if defined(V4_BOOTSTRAP)
diff --git a/src/qml/compiler/qv4compilercontext.cpp b/src/qml/compiler/qv4compilercontext.cpp
index 572f24f148..ca4cbfc4fc 100644
--- a/src/qml/compiler/qv4compilercontext.cpp
+++ b/src/qml/compiler/qv4compilercontext.cpp
@@ -207,7 +207,7 @@ void Context::emitBlockHeader(Codegen *codegen)
blockIndex = codegen->module()->blocks.count() - 1;
}
- if (contextType == ContextType::Global || contextType == ContextType::ScriptImportedByQML) {
+ if (contextType == ContextType::Global) {
Instruction::PushScriptContext scriptContext;
scriptContext.index = blockIndex;
bytecodeGenerator->addInstruction(scriptContext);
@@ -222,7 +222,7 @@ void Context::emitBlockHeader(Codegen *codegen)
blockContext.index = blockIndex;
bytecodeGenerator->addInstruction(blockContext);
}
- } else if (contextType != ContextType::ESModule) {
+ } else if (contextType != ContextType::ESModule && contextType != ContextType::ScriptImportedByQML) {
Instruction::CreateCallContext createContext;
bytecodeGenerator->addInstruction(createContext);
}
@@ -316,9 +316,9 @@ void Context::emitBlockFooter(Codegen *codegen)
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wmaybe-uninitialized") // the loads below are empty structs.
- if (contextType == ContextType::Global || contextType == ContextType::ScriptImportedByQML)
+ if (contextType == ContextType::Global)
bytecodeGenerator->addInstruction(Instruction::PopScriptContext());
- else if (contextType != ContextType::ESModule)
+ else if (contextType != ContextType::ESModule && contextType != ContextType::ScriptImportedByQML)
bytecodeGenerator->addInstruction(Instruction::PopContext());
QT_WARNING_POP
}