Merge branch 'wip/v4' of ssh://codereview.qt-project.org/qt/qtdeclarative into dev
authorSimon Hausmann <simon.hausmann@digia.com>
Tue, 20 Aug 2013 14:54:29 +0000 (16:54 +0200)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 20 Aug 2013 14:54:29 +0000 (16:54 +0200)
Conflicts:
src/qml/compiler/qv4codegen.cpp
src/qml/compiler/qv4codegen_p.h
src/qml/compiler/qv4isel_moth.cpp
src/qml/jsruntime/qv4context_p.h
src/qml/jsruntime/qv4functionobject.cpp
src/qml/jsruntime/qv4runtime.cpp
src/qml/jsruntime/qv4runtime_p.h
src/qml/jsruntime/qv4script.cpp
sync.profile

Change-Id: I1d785e2134bffac9553a1c16eed12816cbd1ad2c

22 files changed:
1  2 
src/qml/compiler/compiler.pri
src/qml/compiler/qv4codegen.cpp
src/qml/compiler/qv4codegen_p.h
src/qml/compiler/qv4instr_moth_p.h
src/qml/compiler/qv4isel_masm.cpp
src/qml/compiler/qv4isel_masm_p.h
src/qml/compiler/qv4isel_moth.cpp
src/qml/compiler/qv4isel_moth_p.h
src/qml/compiler/qv4isel_p.cpp
src/qml/compiler/qv4isel_p.h
src/qml/compiler/qv4jsir.cpp
src/qml/compiler/qv4jsir_p.h
src/qml/jsruntime/qv4context.cpp
src/qml/jsruntime/qv4context_p.h
src/qml/jsruntime/qv4engine.cpp
src/qml/jsruntime/qv4engine_p.h
src/qml/jsruntime/qv4functionobject.cpp
src/qml/jsruntime/qv4runtime.cpp
src/qml/jsruntime/qv4runtime_p.h
src/qml/jsruntime/qv4script.cpp
src/qml/jsruntime/qv4vme_moth.cpp
tools/v4/main.cpp

@@@ -11,10 -13,11 +13,12 @@@ HEADERS += 
      $$PWD/qv4instr_moth_p.h \
      $$PWD/qv4isel_moth_p.h \
      $$PWD/qv4isel_util_p.h \
 -    $$PWD/qv4ssa_p.h
 +    $$PWD/qv4ssa_p.h \
 +    $$PWD/qv4regalloc_p.h
  
  SOURCES += \
+     $$PWD/qv4compileddata.cpp \
+     $$PWD/qv4compiler.cpp \
      $$PWD/qv4codegen.cpp \
      $$PWD/qv4instr_moth.cpp \
      $$PWD/qv4isel_masm.cpp \
@@@ -2574,30 -2580,26 +2574,30 @@@ void Codegen::throwSyntaxErrorOnEvalOrA
  
  void Codegen::throwSyntaxError(const SourceLocation &loc, const QString &detail)
  {
 -    QV4::DiagnosticMessage *msg = new QV4::DiagnosticMessage;
 -    msg->fileName = _module->fileName;
 -    msg->offset = loc.begin();
 -    msg->startLine = loc.startLine;
 -    msg->startColumn = loc.startColumn;
 -    msg->message = detail;
 -    if (_context)
 -        _context->throwSyntaxError(msg);
 -    else if (_errorHandler)
 -        _errorHandler->syntaxError(msg);
 -    else
 -        Q_ASSERT(!"No error handler available.");
 +    QQmlError error;
-     error.setUrl(QUrl::fromLocalFile(_fileName));
++    error.setUrl(QUrl::fromLocalFile(_module->fileName));
 +    error.setDescription(detail);
 +    error.setLine(loc.startLine);
 +    error.setColumn(loc.startColumn);
 +    _errors << error;
  }
  
  void Codegen::throwReferenceError(const SourceLocation &loc, const QString &detail)
  {
 -    if (_context)
 -        _context->throwReferenceError(QV4::Value::fromString(_context, detail), _module->fileName, loc.startLine);
 -    else if (_errorHandler)
 -        throwSyntaxError(loc, detail);
 -    else
 -        Q_ASSERT(!"No error handler available.");
 +    QQmlError error;
-     error.setUrl(QUrl::fromLocalFile(_fileName));
++    error.setUrl(QUrl::fromLocalFile(_module->fileName));
 +    error.setDescription(detail);
 +    error.setLine(loc.startLine);
 +    error.setColumn(loc.startColumn);
 +    _errors << error;
 +}
 +
 +void RuntimeCodegen::throwSyntaxError(const AST::SourceLocation &loc, const QString &detail)
 +{
-     context->throwSyntaxError(detail, _fileName, loc.startLine, loc.startColumn);
++    context->throwSyntaxError(detail, _module->fileName, loc.startLine, loc.startColumn);
 +}
 +
 +void RuntimeCodegen::throwReferenceError(const AST::SourceLocation &loc, const QString &detail)
 +{
-     context->throwReferenceError(detail, _fileName, loc.startLine, loc.startColumn);
++    context->throwReferenceError(detail, _module->fileName, loc.startLine, loc.startColumn);
  }
@@@ -407,13 -415,11 +407,12 @@@ protected
      virtual bool visit(AST::UiSourceElement *ast);
  
      void throwSyntaxErrorOnEvalOrArgumentsInStrictMode(V4IR::Expr* expr, const AST::SourceLocation &loc);
 +    virtual void throwSyntaxError(const AST::SourceLocation &loc, const QString &detail);
 +    virtual void throwReferenceError(const AST::SourceLocation &loc, const QString &detail);
  
 -    void throwSyntaxError(const AST::SourceLocation &loc, const QString &detail);
 -    void throwReferenceError(const AST::SourceLocation &loc, const QString &detail);
 +    QList<QQmlError> errors();
  
 -private:
 +protected:
-     QString _fileName;
      Result _expr;
      QString _property;
      UiMember _uiMember;
Simple merge
@@@ -991,15 -1002,9 +1019,15 @@@ void InstructionSelection::callBuiltinD
  
      generateFunctionCall(Assembler::Void, __qmljs_builtin_define_object_literal, Assembler::ContextRegister,
                           Assembler::PointerToValue(result), baseAddressForCallArguments(),
-                          Assembler::TrustedImmPtr(klass));
+                          Assembler::TrustedImm32(classId));
  }
  
 +void InstructionSelection::callBuiltinSetupArgumentObject(V4IR::Temp *result)
 +{
 +    generateFunctionCall(Assembler::Void, __qmljs_builtin_setup_arguments_object, Assembler::ContextRegister,
 +                         Assembler::PointerToValue(result));
 +}
 +
  void InstructionSelection::callValue(V4IR::Temp *value, V4IR::ExprList *args, V4IR::Temp *result)
  {
      int argc = prepareVariableArguments(args);
@@@ -1261,19 -1256,9 +1279,12 @@@ void InstructionSelection::callSubscrip
  void InstructionSelection::convertType(V4IR::Temp *source, V4IR::Temp *target)
  {
      // FIXME: do something more useful with this info
 -    copyValue(source, target);
 +    if (target->type & V4IR::NumberType && !(source->type & V4IR::NumberType))
 +        unop(V4IR::OpUPlus, source, target);
 +    else
 +        copyValue(source, target);
  }
  
- String *InstructionSelection::identifier(const QString &s)
- {
-     String *str = engine()->newIdentifier(s);
-     _vmFunction->identifiers.append(str);
-     return str;
- }
  void InstructionSelection::constructActivationProperty(V4IR::Name *func, V4IR::ExprList *args, V4IR::Temp *result)
  {
      assert(func != 0);
Simple merge
@@@ -1065,15 -1055,8 +1064,8 @@@ QByteArray InstructionSelection::squeez
      return squeezed;
  }
  
- QV4::String *InstructionSelection::identifier(const QString &s)
- {
-     QV4::String *str = engine()->newIdentifier(s);
-     _vmFunction->identifiers.append(str);
-     return str;
- }
 -Instr::Param InstructionSelection::getParam(V4IR::Expr *e) {
 -    typedef Instr::Param Param;
 +Param InstructionSelection::getParam(V4IR::Expr *e) {
 +    typedef Param Param;
      assert(e);
  
      if (V4IR::Const *c = e->asConst()) {
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -52,6 -52,30 +52,12 @@@ struct Object
  struct ExecutionEngine;
  struct DeclarativeEnvironment;
  struct Lookup;
 -struct Q_QML_EXPORT DiagnosticMessage
 -{
 -    enum { Error, Warning };
 -
 -    QString fileName;
 -    quint32 offset;
 -    quint32 length;
 -    quint32 startLine;
 -    unsigned startColumn: 31;
 -    unsigned type: 1;
 -    QString message;
 -    DiagnosticMessage *next;
 -
 -    DiagnosticMessage();
 -    ~DiagnosticMessage();
 -    String *buildFullMessage(ExecutionContext *ctx) const;
 -};
 -
+ namespace CompiledData {
+ struct CompilationUnit;
+ struct Function;
+ };
  struct CallContext;
  
  struct Q_QML_EXPORT ExecutionContext
@@@ -282,9 -275,9 +281,8 @@@ ExecutionEngine::~ExecutionEngine(
      delete memoryManager;
      delete m_qmlExtensions;
      emptyClass->destroy();
 -    delete identifierTable;
      delete bumperPointerAllocator;
      delete regExpCache;
-     UnwindHelper::deregisterFunctions(functions);
      delete regExpAllocator;
      delete executableAllocator;
  }
Simple merge
@@@ -211,11 -210,12 +211,12 @@@ Value FunctionCtor::construct(Managed *
  
      QQmlJS::V4IR::Module module;
  
 -    QQmlJS::Codegen cg(v4->current, f->strictMode);
 +    QQmlJS::RuntimeCodegen cg(v4->current, f->strictMode);
-     QQmlJS::V4IR::Function *irf = cg(QString(), function, fe, &module);
+     cg(QString(), function, fe, &module);
  
-     QScopedPointer<QQmlJS::EvalInstructionSelection> isel(v4->iselFactory->create(v4, &module));
-     QV4::Function *vmf = isel->vmFunction(irf);
+     QScopedPointer<QQmlJS::EvalInstructionSelection> isel(v4->iselFactory->create(v4->executableAllocator, &module));
+     QV4::CompiledData::CompilationUnit *compilationUnit = isel->compile();
+     QV4::Function *vmf = compilationUnit->linkToEngine(v4);
  
      return Value::fromObject(v4->newScriptFunction(v4->rootContext, vmf));
  }
@@@ -1252,26 -1223,16 +1230,36 @@@ void __qmljs_decrement(Value *result, c
      }
  }
  
 +int __qmljs_value_to_int32(const Value &value)
 +{
 +    return value.toInt32();
 +}
 +
 +int __qmljs_double_to_int32(double d)
 +{
 +    return Value::toInt32(d);
 +}
 +
 +unsigned __qmljs_value_to_uint32(const Value &value)
 +{
 +    return value.toUInt32();
 +}
 +
 +unsigned __qmljs_double_to_uint32(double d)
 +{
 +    return Value::toUInt32(d);
 +}
 +
+ void __qmljs_value_from_string(Value *result, String *string)
+ {
+     *result = Value::fromString(string);
+ }
+ void __qmljs_lookup_runtime_regexp(ExecutionContext *ctx, Value *result, int id)
+ {
+     *result = ctx->compilationUnit->runtimeRegularExpressions[id];
+ }
  } // namespace QV4
  
  QT_END_NAMESPACE
@@@ -124,16 -124,13 +124,14 @@@ void __qmljs_builtin_declare_var(QV4::E
  void __qmljs_builtin_define_property(QV4::ExecutionContext *ctx, const QV4::Value &object, QV4::String *name, QV4::Value *val);
  void __qmljs_builtin_define_array(QV4::ExecutionContext *ctx, QV4::Value *array, QV4::Value *values, uint length);
  void __qmljs_builtin_define_getter_setter(QV4::ExecutionContext *ctx, const QV4::Value &object, QV4::String *name, const QV4::Value *getter, const QV4::Value *setter);
- void __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, QV4::Value *result, const QV4::Value *args, QV4::InternalClass *klass);
+ void __qmljs_builtin_define_object_literal(QV4::ExecutionContext *ctx, QV4::Value *result, const QV4::Value *args, int classId);
 +void __qmljs_builtin_setup_arguments_object(ExecutionContext *ctx, QV4::Value *result);
+ void __qmljs_value_from_string(QV4::Value *result, QV4::String *string);
+ void __qmljs_lookup_runtime_regexp(QV4::ExecutionContext *ctx, QV4::Value *result, int id);
  // constructors
- void __qmljs_init_closure(QV4::ExecutionContext *ctx, QV4::Value *result, QV4::Function *clos);
- QV4::Function *__qmljs_register_function(QV4::ExecutionContext *ctx, QV4::String *name,
-                                          bool hasDirectEval,
-                                          bool usesArgumentsObject, bool isStrict,
-                                          bool hasNestedFunctions,
-                                          QV4::String **formals, unsigned formalCount,
-                                          QV4::String **locals, unsigned localCount);
+ void __qmljs_init_closure(QV4::ExecutionContext *ctx, QV4::Value *result, int functionId);
  
  // strings
  Q_QML_EXPORT double __qmljs_string_to_number(const QString &s);
@@@ -162,15 -173,14 +162,14 @@@ void Script::parse(
              for (String * const *i = scope->variables(), * const *ei = i + scope->variableCount(); i < ei; ++i)
                  inheritedLocals.append(*i ? (*i)->toQString() : QString());
  
 -        Codegen cg(scope, strictMode);
 +        RuntimeCodegen cg(scope, strictMode);
-         V4IR::Function *globalIRCode = cg(sourceFile, sourceCode, program, &module,
-                                           parseAsBinding ? QQmlJS::Codegen::QmlBinding : QQmlJS::Codegen::EvalCode, inheritedLocals);
-         QScopedPointer<EvalInstructionSelection> isel(v4->iselFactory->create(v4, &module));
+         cg(sourceFile, sourceCode, program, &module,
+            parseAsBinding ? QQmlJS::Codegen::QmlBinding : QQmlJS::Codegen::EvalCode, inheritedLocals);
+         QScopedPointer<EvalInstructionSelection> isel(v4->iselFactory->create(v4->executableAllocator, &module));
          if (inheritContext)
              isel->setUseFastLookups(false);
-         if (globalIRCode) {
-             vmFunction = isel->vmFunction(globalIRCode);
-         }
+         QV4::CompiledData::CompilationUnit *compilationUnit = isel->compile();
+         vmFunction = compilationUnit->linkToEngine(v4);
      }
  
      if (!vmFunction)
@@@ -464,13 -475,9 +475,13 @@@ QV4::Value VME::run(QV4::ExecutionConte
  
      MOTH_BEGIN_INSTR(CallBuiltinDefineObjectLiteral)
          QV4::Value *args = stack + instr.args;
-         __qmljs_builtin_define_object_literal(context, VALUEPTR(instr.result), args, instr.internalClass);
+         __qmljs_builtin_define_object_literal(context, VALUEPTR(instr.result), args, instr.internalClassId);
      MOTH_END_INSTR(CallBuiltinDefineObjectLiteral)
  
 +    MOTH_BEGIN_INSTR(CallBuiltinSetupArgumentsObject)
 +        __qmljs_builtin_setup_arguments_object(context, VALUEPTR(instr.result));
 +    MOTH_END_INSTR(CallBuiltinSetupArgumentsObject)
 +
      MOTH_BEGIN_INSTR(CreateValue)
          Q_ASSERT(instr.args + instr.argc <= stackSize);
          QV4::Value *args = stack + instr.args;
Simple merge