Some refactoring and some initial work on the Date object.
authorRoberto Raggi <roberto.raggi@nokia.com>
Fri, 18 May 2012 08:10:36 +0000 (10:10 +0200)
committerRoberto Raggi <roberto.raggi@nokia.com>
Fri, 18 May 2012 08:10:36 +0000 (10:10 +0200)
main.cpp
qmljs_objects.cpp
qmljs_objects.h
qmljs_runtime.h
qv4codegen.cpp
qv4codegen_p.h
qv4ecmaobjects.cpp
qv4ecmaobjects_p.h
qv4isel.cpp

index 9026a96..44cd18d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -47,78 +47,81 @@ struct Print: FunctionObject
 } // builtins
 
 
-void evaluate(QQmlJS::VM::ExecutionEngine *vm, QQmlJS::Engine *engine, const QString &fileName, const QString &code)
+void evaluate(QQmlJS::VM::ExecutionEngine *vm, const QString &fileName, const QString &source)
 {
     using namespace QQmlJS;
 
-    Lexer lexer(engine);
-    lexer.setCode(code, 1, false);
-    Parser parser(engine);
+    IR::Module module;
+    IR::Function *globalCode = 0;
 
-    const bool parsed = parser.parseProgram();
+    const size_t codeSize = 10 * getpagesize();
+    uchar *code = (uchar *) malloc(codeSize);
+    assert(! (size_t(code) & 15));
 
-    foreach (const DiagnosticMessage &m, parser.diagnosticMessages()) {
-        std::cerr << qPrintable(fileName) << ':' << m.loc.startLine << ':' << m.loc.startColumn
-                  << ": error: " << qPrintable(m.message) << std::endl;
-    }
+    {
+        QQmlJS::Engine ee, *engine = &ee;
+        Lexer lexer(engine);
+        lexer.setCode(source, 1, false);
+        Parser parser(engine);
 
-    if (parsed) {
-        using namespace AST;
-        Program *program = AST::cast<Program *>(parser.rootNode());
+        const bool parsed = parser.parseProgram();
 
-        Codegen cg;
-        IR::Module module;
-        IR::Function *globalCode = cg(program, &module);
+        foreach (const DiagnosticMessage &m, parser.diagnosticMessages()) {
+            std::cerr << qPrintable(fileName) << ':' << m.loc.startLine << ':' << m.loc.startColumn
+                      << ": error: " << qPrintable(m.message) << std::endl;
+        }
 
-        const size_t codeSize = 10 * getpagesize();
-        uchar *code = (uchar *) malloc(codeSize);
+        if (parsed) {
+            using namespace AST;
+            Program *program = AST::cast<Program *>(parser.rootNode());
 
-        x86_64::InstructionSelection isel(vm, &module, code);
-        foreach (IR::Function *function, module.functions) {
-            isel(function);
+            Codegen cg;
+            globalCode = cg(program, &module);
+
+            x86_64::InstructionSelection isel(vm, &module, code);
+            foreach (IR::Function *function, module.functions) {
+                isel(function);
+            }
         }
+    }
 
-        if (! protect(code, codeSize))
-            Q_UNREACHABLE();
+    if (! protect(code, codeSize))
+        Q_UNREACHABLE();
 
-        VM::Object *globalObject = vm->globalObject.objectValue;
-        VM::Context *ctx = vm->rootContext;
+    VM::Object *globalObject = vm->globalObject.objectValue;
+    VM::Context *ctx = vm->rootContext;
 
-        globalObject->put(vm->identifier(QLatin1String("print")),
-                          VM::Value::fromObject(new builtins::Print(ctx)));
+    globalObject->put(vm->identifier(QLatin1String("print")),
+                      VM::Value::fromObject(new builtins::Print(ctx)));
 
-        ctx->varCount = globalCode->locals.size();
-        if (ctx->varCount) {
-            ctx->locals = new VM::Value[ctx->varCount];
-            ctx->vars = new VM::String*[ctx->varCount];
-            std::fill(ctx->locals, ctx->locals + ctx->varCount, VM::Value::undefinedValue());
-            for (size_t i = 0; i < ctx->varCount; ++i)
-                ctx->vars[i] = ctx->engine->identifier(*globalCode->locals.at(i));
-        }
+    ctx->varCount = globalCode->locals.size();
+    if (ctx->varCount) {
+        ctx->locals = new VM::Value[ctx->varCount];
+        ctx->vars = new VM::String*[ctx->varCount];
+        std::fill(ctx->locals, ctx->locals + ctx->varCount, VM::Value::undefinedValue());
+        for (size_t i = 0; i < ctx->varCount; ++i)
+            ctx->vars[i] = ctx->engine->identifier(*globalCode->locals.at(i));
+    }
 
-        globalCode->code(ctx);
+    globalCode->code(ctx);
 
-        delete[] ctx->locals;
-        delete[] ctx->vars;
-    }
+    delete[] ctx->locals;
+    delete[] ctx->vars;
 }
 
 int main(int argc, char *argv[])
 {
-    using namespace QQmlJS;
-
     QCoreApplication app(argc, argv);
     QStringList args = app.arguments();
     args.removeFirst();
 
-    VM::ExecutionEngine vm;
-    Engine engine;
+    QQmlJS::VM::ExecutionEngine vm;
     foreach (const QString &fn, args) {
         QFile file(fn);
         if (file.open(QFile::ReadOnly)) {
             const QString code = QString::fromUtf8(file.readAll());
             file.close();
-            evaluate(&vm, &engine, fn, code);
+            evaluate(&vm, fn, code);
         }
     }
 }
index 44d8430..0fdf99b 100644 (file)
@@ -2,11 +2,15 @@
 #include "qmljs_objects.h"
 #include "qv4ir_p.h"
 #include "qv4ecmaobjects_p.h"
+#include <QtCore/qmath.h>
 #include <QtCore/QDebug>
 #include <cassert>
 
 using namespace QQmlJS::VM;
 
+//
+// Object
+//
 Object::~Object()
 {
     delete members;
@@ -207,16 +211,19 @@ ExecutionEngine::ExecutionEngine()
     objectCtor = ObjectCtor::create(this);
     stringCtor = StringCtor::create(this);
     numberCtor = NumberCtor::create(this);
+    dateCtor = DateCtor::create(this);
 
     String *prototype = identifier(QLatin1String("prototype"));
 
     objectCtor.objectValue->get(prototype, &objectPrototype);
     stringCtor.objectValue->get(prototype, &stringPrototype);
     numberCtor.objectValue->get(prototype, &numberPrototype);
+    dateCtor.objectValue->get(prototype, &datePrototype);
 
     glo->put(identifier(QLatin1String("Object")), objectCtor);
     glo->put(identifier(QLatin1String("String")), stringCtor);
     glo->put(identifier(QLatin1String("Number")), numberCtor);
+    glo->put(identifier(QLatin1String("Date")), dateCtor);
     glo->put(identifier(QLatin1String("Math")), Value::fromObject(newMathObject(rootContext)));
 }
 
@@ -314,6 +321,23 @@ Object *ExecutionEngine::newBooleanPrototype(Context *ctx, FunctionObject *proto
     return booleanProto;
 }
 
+Object *ExecutionEngine::newDateObject(const Value &value)
+{
+    return new Object(); // ### FIXME
+}
+
+FunctionObject *ExecutionEngine::newDateCtor(Context *ctx)
+{
+    return new DateCtor(ctx);
+}
+
+Object *ExecutionEngine::newDatePrototype(Context *ctx, FunctionObject *proto)
+{
+    Object *dateProto = new DatePrototype(ctx, proto);
+    dateProto->prototype = objectPrototype.objectValue;
+    return dateProto;
+}
+
 Object *ExecutionEngine::newErrorObject(const Value &value)
 {
     return new ErrorObject(value);
index 08f9bcb..b2b2ea3 100644 (file)
@@ -360,10 +360,12 @@ struct ExecutionEngine
     Value objectCtor;
     Value stringCtor;
     Value numberCtor;
+    Value dateCtor;
 
     Value objectPrototype;
     Value stringPrototype;
     Value numberPrototype;
+    Value datePrototype;
 
     QHash<QString, String *> identifiers;
 
@@ -393,6 +395,10 @@ struct ExecutionEngine
     FunctionObject *newBooleanCtor(Context *ctx);
     Object *newBooleanPrototype(Context *ctx, FunctionObject *proto);
 
+    Object *newDateObject(const Value &value);
+    FunctionObject *newDateCtor(Context *ctx);
+    Object *newDatePrototype(Context *ctx, FunctionObject *proto);
+
     Object *newErrorObject(const Value &value);
     Object *newMathObject(Context *ctx);
     Object *newArgumentsObject(Context *ctx);
index 467e302..223a219 100644 (file)
@@ -597,18 +597,26 @@ inline void __qmljs_ushr(Context *ctx, Value *result, const Value *left, const V
 
 inline void __qmljs_gt(Context *ctx, Value *result, const Value *left, const Value *right)
 {
-    __qmljs_compare(ctx, result, left, right, false);
+    if (left->type == NUMBER_TYPE && right->type == NUMBER_TYPE) {
+        __qmljs_init_boolean(result, left->numberValue > right->numberValue);
+    } else {
+        __qmljs_compare(ctx, result, left, right, false);
 
-    if (result->type == UNDEFINED_TYPE)
-        __qmljs_init_boolean(result, false);
+        if (result->type == UNDEFINED_TYPE)
+            __qmljs_init_boolean(result, false);
+    }
 }
 
 inline void __qmljs_lt(Context *ctx, Value *result, const Value *left, const Value *right)
 {
-    __qmljs_compare(ctx, result, left, right, true);
+    if (left->type == NUMBER_TYPE && right->type == NUMBER_TYPE) {
+        __qmljs_init_boolean(result, left->numberValue < right->numberValue);
+    } else {
+        __qmljs_compare(ctx, result, left, right, true);
 
-    if (result->type == UNDEFINED_TYPE)
-        __qmljs_init_boolean(result, false);
+        if (result->type == UNDEFINED_TYPE)
+            __qmljs_init_boolean(result, false);
+    }
 }
 
 inline void __qmljs_ge(Context *ctx, Value *result, const Value *left, const Value *right)
index a5f2b3d..9226749 100644 (file)
@@ -341,6 +341,16 @@ IR::Expr *Codegen::argument(IR::Expr *expr)
     return expr;
 }
 
+IR::Expr *Codegen::unop(IR::AluOp op, IR::Expr *expr)
+{
+    if (! expr->asTemp()) {
+        const unsigned t = _block->newTemp();
+        move(_block->TEMP(t), expr);
+        expr = _block->TEMP(t);
+    }
+    return _block->UNOP(op, expr);
+}
+
 IR::Expr *Codegen::binop(IR::AluOp op, IR::Expr *left, IR::Expr *right)
 {
     if (left && ! left->asTemp()) {
@@ -369,7 +379,14 @@ IR::Expr *Codegen::call(IR::Expr *base, IR::ExprList *args)
 
 void Codegen::move(IR::Expr *target, IR::Expr *source, IR::AluOp op)
 {
-    if (target->asMember()) {
+    if (op != IR::OpInvalid) {
+        if (! (source->asTemp() || source->asConst())) {
+            const unsigned t = _block->newTemp();
+            _block->MOVE(_block->TEMP(t), source);
+            _block->MOVE(target, _block->TEMP(t), op);
+            return;
+        }
+    } else if (target->asMember() || target->asSubscript()) {
         if (! (source->asTemp() || source->asConst())) {
             const unsigned t = _block->newTemp();
             _block->MOVE(_block->TEMP(t), source);
@@ -387,6 +404,16 @@ void Codegen::move(IR::Expr *target, IR::Expr *source, IR::AluOp op)
     _block->MOVE(target, source, op);
 }
 
+void Codegen::cjump(IR::Expr *cond, IR::BasicBlock *iftrue, IR::BasicBlock *iffalse)
+{
+    if (! cond->asTemp()) {
+        const unsigned t = _block->newTemp();
+        _block->MOVE(_block->TEMP(t), cond);
+        cond = _block->TEMP(t);
+    }
+    _block->CJUMP(cond, iftrue, iffalse);
+}
+
 void Codegen::accept(Node *node)
 {
     if (node)
@@ -419,7 +446,7 @@ void Codegen::condition(ExpressionNode *ast, IR::BasicBlock *iftrue, IR::BasicBl
         accept(ast);
         qSwap(_expr, r);
         if (r.format == ex) {
-            _block->CJUMP(*r, r.iftrue, r.iffalse);
+            cjump(*r, r.iftrue, r.iffalse);
         }
     }
 }
@@ -851,7 +878,7 @@ bool Codegen::visit(BinaryExpression *ast)
 
             const unsigned r = _block->newTemp();
             move(_block->TEMP(r), *expression(ast->left));
-            _block->CJUMP(_block->TEMP(r), endif, iffalse);
+            cjump(_block->TEMP(r), endif, iffalse);
             _block = iffalse;
             move(_block->TEMP(r), *expression(ast->right));
             if (! _block->isTerminated())
@@ -913,7 +940,7 @@ bool Codegen::visit(BinaryExpression *ast)
     case QSOperator::StrictEqual:
     case QSOperator::StrictNotEqual:
         if (false && _expr.accept(cx)) {
-            _block->CJUMP(binop(IR::binaryOperator(ast->op), *left, *right), _expr.iftrue, _expr.iffalse);
+            cjump(binop(IR::binaryOperator(ast->op), *left, *right), _expr.iftrue, _expr.iffalse);
         } else {
             IR::Expr *e = binop(IR::binaryOperator(ast->op), *left, *right);
             if (e->asConst() || e->asString())
@@ -1081,7 +1108,7 @@ bool Codegen::visit(NotExpression *ast)
 {
     Result expr = expression(ast->expression);
     const unsigned r = _block->newTemp();
-    move(_block->TEMP(r), _block->UNOP(IR::OpNot, *expr));
+    move(_block->TEMP(r), unop(IR::OpNot, *expr));
     _expr.code = _block->TEMP(r);
     return false;
 }
@@ -1186,7 +1213,7 @@ bool Codegen::visit(TildeExpression *ast)
 {
     Result expr = expression(ast->expression);
     const unsigned t = _block->newTemp();
-    move(_block->TEMP(t), _block->UNOP(IR::OpCompl, *expr));
+    move(_block->TEMP(t), unop(IR::OpCompl, *expr));
     _expr.code = _block->TEMP(t);
     return false;
 }
@@ -1210,7 +1237,7 @@ bool Codegen::visit(UnaryMinusExpression *ast)
 {
     Result expr = expression(ast->expression);
     const unsigned t = _block->newTemp();
-    move(_block->TEMP(t), _block->UNOP(IR::OpUMinus, *expr));
+    move(_block->TEMP(t), unop(IR::OpUMinus, *expr));
     _expr.code = _block->TEMP(t);
     return false;
 }
@@ -1219,7 +1246,7 @@ bool Codegen::visit(UnaryPlusExpression *ast)
 {
     Result expr = expression(ast->expression);
     const unsigned t = _block->newTemp();
-    move(_block->TEMP(t), _block->UNOP(IR::OpUPlus, *expr));
+    move(_block->TEMP(t), unop(IR::OpUPlus, *expr));
     _expr.code = _block->TEMP(t);
     return false;
 }
index f878001..b93dac1 100644 (file)
@@ -126,9 +126,11 @@ protected:
     IR::Expr *member(IR::Expr *base, const QString *name);
     IR::Expr *subscript(IR::Expr *base, IR::Expr *index);
     IR::Expr *argument(IR::Expr *expr);
+    IR::Expr *unop(IR::AluOp op, IR::Expr *expr);
     IR::Expr *binop(IR::AluOp op, IR::Expr *left, IR::Expr *right);
     IR::Expr *call(IR::Expr *base, IR::ExprList *args);
     void move(IR::Expr *target, IR::Expr *source, IR::AluOp op = IR::OpInvalid);
+    void cjump(IR::Expr *cond, IR::BasicBlock *iftrue, IR::BasicBlock *iffalse);
 
     void linearize(IR::Function *function);
     IR::Function *defineFunction(const QString &name, AST::Node *ast, AST::FormalParameterList *formals,
index 506e866..4630502 100644 (file)
 
 #include "qv4ecmaobjects_p.h"
+#include <QtCore/qnumeric.h>
+#include <QtCore/qmath.h>
+#include <QtCore/QDateTime>
+#include <QtCore/QStringList>
+#include <QtCore/QDebug>
+#include <math.h>
 #include <qmath.h>
 #include <qnumeric.h>
 #include <cassert>
 
+#ifndef Q_WS_WIN
+#  include <time.h>
+#  ifndef Q_OS_VXWORKS
+#    include <sys/time.h>
+#  else
+#    include "qplatformdefs.h"
+#  endif
+#else
+#  include <windows.h>
+#endif
+
 using namespace QQmlJS::VM;
 
 static const double qt_PI = 2.0 * ::asin(1.0);
 
+static const double HoursPerDay = 24.0;
+static const double MinutesPerHour = 60.0;
+static const double SecondsPerMinute = 60.0;
+static const double msPerSecond = 1000.0;
+static const double msPerMinute = 60000.0;
+static const double msPerHour = 3600000.0;
+static const double msPerDay = 86400000.0;
+
+static double LocalTZA = 0.0; // initialized at startup
+
+static inline double TimeWithinDay(double t)
+{
+    double r = ::fmod(t, msPerDay);
+    return (r >= 0) ? r : r + msPerDay;
+}
+
+static inline int HourFromTime(double t)
+{
+    int r = int(::fmod(::floor(t / msPerHour), HoursPerDay));
+    return (r >= 0) ? r : r + int(HoursPerDay);
+}
+
+static inline int MinFromTime(double t)
+{
+    int r = int(::fmod(::floor(t / msPerMinute), MinutesPerHour));
+    return (r >= 0) ? r : r + int(MinutesPerHour);
+}
+
+static inline int SecFromTime(double t)
+{
+    int r = int(::fmod(::floor(t / msPerSecond), SecondsPerMinute));
+    return (r >= 0) ? r : r + int(SecondsPerMinute);
+}
+
+static inline int msFromTime(double t)
+{
+    int r = int(::fmod(t, msPerSecond));
+    return (r >= 0) ? r : r + int(msPerSecond);
+}
+
+static inline double Day(double t)
+{
+    return ::floor(t / msPerDay);
+}
+
+static inline double DaysInYear(double y)
+{
+    if (::fmod(y, 4))
+        return 365;
+
+    else if (::fmod(y, 100))
+        return 366;
+
+    else if (::fmod(y, 400))
+        return 365;
+
+    return 366;
+}
+
+static inline double DayFromYear(double y)
+{
+    return 365 * (y - 1970)
+        + ::floor((y - 1969) / 4)
+        - ::floor((y - 1901) / 100)
+        + ::floor((y - 1601) / 400);
+}
+
+static inline double TimeFromYear(double y)
+{
+    return msPerDay * DayFromYear(y);
+}
+
+static inline double YearFromTime(double t)
+{
+    int y = 1970;
+    y += (int) ::floor(t / (msPerDay * 365.2425));
+
+    double t2 = TimeFromYear(y);
+    return (t2 > t) ? y - 1 : ((t2 + msPerDay * DaysInYear(y)) <= t) ? y + 1 : y;
+}
+
+static inline bool InLeapYear(double t)
+{
+    double x = DaysInYear(YearFromTime(t));
+    if (x == 365)
+        return 0;
+
+    Q_ASSERT (x == 366);
+    return 1;
+}
+
+static inline double DayWithinYear(double t)
+{
+    return Day(t) - DayFromYear(YearFromTime(t));
+}
+
+static inline double MonthFromTime(double t)
+{
+    double d = DayWithinYear(t);
+    double l = InLeapYear(t);
+
+    if (d < 31.0)
+        return 0;
+
+    else if (d < 59.0 + l)
+        return 1;
+
+    else if (d < 90.0 + l)
+        return 2;
+
+    else if (d < 120.0 + l)
+        return 3;
+
+    else if (d < 151.0 + l)
+        return 4;
+
+    else if (d < 181.0 + l)
+        return 5;
+
+    else if (d < 212.0 + l)
+        return 6;
+
+    else if (d < 243.0 + l)
+        return 7;
+
+    else if (d < 273.0 + l)
+        return 8;
+
+    else if (d < 304.0 + l)
+        return 9;
+
+    else if (d < 334.0 + l)
+        return 10;
+
+    else if (d < 365.0 + l)
+        return 11;
+
+    return qSNaN(); // ### assert?
+}
+
+static inline double DateFromTime(double t)
+{
+    int m = (int) Value::toInteger(MonthFromTime(t));
+    double d = DayWithinYear(t);
+    double l = InLeapYear(t);
+
+    switch (m) {
+    case 0: return d + 1.0;
+    case 1: return d - 30.0;
+    case 2: return d - 58.0 - l;
+    case 3: return d - 89.0 - l;
+    case 4: return d - 119.0 - l;
+    case 5: return d - 150.0 - l;
+    case 6: return d - 180.0 - l;
+    case 7: return d - 211.0 - l;
+    case 8: return d - 242.0 - l;
+    case 9: return d - 272.0 - l;
+    case 10: return d - 303.0 - l;
+    case 11: return d - 333.0 - l;
+    }
+
+    return qSNaN(); // ### assert
+}
+
+static inline double WeekDay(double t)
+{
+    double r = ::fmod (Day(t) + 4.0, 7.0);
+    return (r >= 0) ? r : r + 7.0;
+}
+
+
+static inline double MakeTime(double hour, double min, double sec, double ms)
+{
+    return ((hour * MinutesPerHour + min) * SecondsPerMinute + sec) * msPerSecond + ms;
+}
+
+static inline double DayFromMonth(double month, double leap)
+{
+    switch ((int) month) {
+    case 0: return 0;
+    case 1: return 31.0;
+    case 2: return 59.0 + leap;
+    case 3: return 90.0 + leap;
+    case 4: return 120.0 + leap;
+    case 5: return 151.0 + leap;
+    case 6: return 181.0 + leap;
+    case 7: return 212.0 + leap;
+    case 8: return 243.0 + leap;
+    case 9: return 273.0 + leap;
+    case 10: return 304.0 + leap;
+    case 11: return 334.0 + leap;
+    }
+
+    return qSNaN(); // ### assert?
+}
+
+static double MakeDay(double year, double month, double day)
+{
+    year += ::floor(month / 12.0);
+
+    month = ::fmod(month, 12.0);
+    if (month < 0)
+        month += 12.0;
+
+    double t = TimeFromYear(year);
+    double leap = InLeapYear(t);
+
+    day += ::floor(t / msPerDay);
+    day += DayFromMonth(month, leap);
+
+    return day - 1;
+}
+
+static inline double MakeDate(double day, double time)
+{
+    return day * msPerDay + time;
+}
+
+static inline double DaylightSavingTA(double t)
+{
+#ifndef Q_WS_WIN
+    long int tt = (long int)(t / msPerSecond);
+    struct tm *tmtm = localtime((const time_t*)&tt);
+    if (! tmtm)
+        return 0;
+    return (tmtm->tm_isdst > 0) ? msPerHour : 0;
+#else
+    Q_UNUSED(t);
+    /// ### implement me
+    return 0;
+#endif
+}
+
+static inline double LocalTime(double t)
+{
+    return t + LocalTZA + DaylightSavingTA(t);
+}
+
+static inline double UTC(double t)
+{
+    return t - LocalTZA - DaylightSavingTA(t - LocalTZA);
+}
+
+static inline double currentTime()
+{
+#ifndef Q_WS_WIN
+    struct timeval tv;
+
+    gettimeofday(&tv, 0);
+    return ::floor(tv.tv_sec * msPerSecond + (tv.tv_usec / 1000.0));
+#else
+    SYSTEMTIME st;
+    GetSystemTime(&st);
+    FILETIME ft;
+    SystemTimeToFileTime(&st, &ft);
+    LARGE_INTEGER li;
+    li.LowPart = ft.dwLowDateTime;
+    li.HighPart = ft.dwHighDateTime;
+    return double(li.QuadPart - Q_INT64_C(116444736000000000)) / 10000.0;
+#endif
+}
+
+static inline double TimeClip(double t)
+{
+    if (! qIsFinite(t) || fabs(t) > 8.64e15)
+        return qSNaN();
+    return Value::toInteger(t);
+}
+
+static inline double FromDateTime(const QDateTime &dt)
+{
+    if (!dt.isValid())
+        return qSNaN();
+    QDate date = dt.date();
+    QTime taim = dt.time();
+    int year = date.year();
+    int month = date.month() - 1;
+    int day = date.day();
+    int hours = taim.hour();
+    int mins = taim.minute();
+    int secs = taim.second();
+    int ms = taim.msec();
+    double t = MakeDate(MakeDay(year, month, day),
+                        MakeTime(hours, mins, secs, ms));
+    if (dt.timeSpec() == Qt::LocalTime)
+        t = UTC(t);
+    return TimeClip(t);
+}
+
+static inline double ParseString(const QString &s)
+{
+    QDateTime dt = QDateTime::fromString(s, Qt::TextDate);
+    if (!dt.isValid())
+        dt = QDateTime::fromString(s, Qt::ISODate);
+    if (!dt.isValid()) {
+        QStringList formats;
+        formats << QLatin1String("M/d/yyyy")
+                << QLatin1String("M/d/yyyy hh:mm")
+                << QLatin1String("M/d/yyyy hh:mm A")
+
+                << QLatin1String("M/d/yyyy, hh:mm")
+                << QLatin1String("M/d/yyyy, hh:mm A")
+
+                << QLatin1String("MMM d yyyy")
+                << QLatin1String("MMM d yyyy hh:mm")
+                << QLatin1String("MMM d yyyy hh:mm:ss")
+                << QLatin1String("MMM d yyyy, hh:mm")
+                << QLatin1String("MMM d yyyy, hh:mm:ss")
+
+                << QLatin1String("MMMM d yyyy")
+                << QLatin1String("MMMM d yyyy hh:mm")
+                << QLatin1String("MMMM d yyyy hh:mm:ss")
+                << QLatin1String("MMMM d yyyy, hh:mm")
+                << QLatin1String("MMMM d yyyy, hh:mm:ss")
+
+                << QLatin1String("MMM d, yyyy")
+                << QLatin1String("MMM d, yyyy hh:mm")
+                << QLatin1String("MMM d, yyyy hh:mm:ss")
+
+                << QLatin1String("MMMM d, yyyy")
+                << QLatin1String("MMMM d, yyyy hh:mm")
+                << QLatin1String("MMMM d, yyyy hh:mm:ss")
+
+                << QLatin1String("d MMM yyyy")
+                << QLatin1String("d MMM yyyy hh:mm")
+                << QLatin1String("d MMM yyyy hh:mm:ss")
+                << QLatin1String("d MMM yyyy, hh:mm")
+                << QLatin1String("d MMM yyyy, hh:mm:ss")
+
+                << QLatin1String("d MMMM yyyy")
+                << QLatin1String("d MMMM yyyy hh:mm")
+                << QLatin1String("d MMMM yyyy hh:mm:ss")
+                << QLatin1String("d MMMM yyyy, hh:mm")
+                << QLatin1String("d MMMM yyyy, hh:mm:ss")
+
+                << QLatin1String("d MMM, yyyy")
+                << QLatin1String("d MMM, yyyy hh:mm")
+                << QLatin1String("d MMM, yyyy hh:mm:ss")
+
+                << QLatin1String("d MMMM, yyyy")
+                << QLatin1String("d MMMM, yyyy hh:mm")
+                << QLatin1String("d MMMM, yyyy hh:mm:ss");
+
+        for (int i = 0; i < formats.size(); ++i) {
+            dt = QDateTime::fromString(s, formats.at(i));
+            if (dt.isValid())
+                break;
+        }
+    }
+    return FromDateTime(dt);
+}
+
+/*!
+  \internal
+
+  Converts the ECMA Date value \tt (in UTC form) to QDateTime
+  according to \a spec.
+*/
+static inline QDateTime ToDateTime(double t, Qt::TimeSpec spec)
+{
+    if (qIsNaN(t))
+        return QDateTime();
+    if (spec == Qt::LocalTime)
+        t = LocalTime(t);
+    int year = int(YearFromTime(t));
+    int month = int(MonthFromTime(t) + 1);
+    int day = int(DateFromTime(t));
+    int hours = HourFromTime(t);
+    int mins = MinFromTime(t);
+    int secs = SecFromTime(t);
+    int ms = msFromTime(t);
+    return QDateTime(QDate(year, month, day), QTime(hours, mins, secs, ms), spec);
+}
+
+static inline QString ToString(double t)
+{
+    if (qIsNaN(t))
+        return QLatin1String("Invalid Date");
+    QString str = ToDateTime(t, Qt::LocalTime).toString() + QLatin1String(" GMT");
+    double tzoffset = LocalTZA + DaylightSavingTA(t);
+    if (tzoffset) {
+        int hours = static_cast<int>(::fabs(tzoffset) / 1000 / 60 / 60);
+        int mins = int(::fabs(tzoffset) / 1000 / 60) % 60;
+        str.append(QLatin1Char((tzoffset > 0) ?  '+' : '-'));
+        if (hours < 10)
+            str.append(QLatin1Char('0'));
+        str.append(QString::number(hours));
+        if (mins < 10)
+            str.append(QLatin1Char('0'));
+        str.append(QString::number(mins));
+    }
+    return str;
+}
+
+static inline QString ToUTCString(double t)
+{
+    if (qIsNaN(t))
+        return QLatin1String("Invalid Date");
+    return ToDateTime(t, Qt::UTC).toString() + QLatin1String(" GMT");
+}
+
+static inline QString ToDateString(double t)
+{
+    return ToDateTime(t, Qt::LocalTime).date().toString();
+}
+
+static inline QString ToTimeString(double t)
+{
+    return ToDateTime(t, Qt::LocalTime).time().toString();
+}
+
+static inline QString ToLocaleString(double t)
+{
+    return ToDateTime(t, Qt::LocalTime).toString(Qt::LocaleDate);
+}
+
+static inline QString ToLocaleDateString(double t)
+{
+    return ToDateTime(t, Qt::LocalTime).date().toString(Qt::LocaleDate);
+}
+
+static inline QString ToLocaleTimeString(double t)
+{
+    return ToDateTime(t, Qt::LocalTime).time().toString(Qt::LocaleDate);
+}
+
+static double getLocalTZA()
+{
+#ifndef Q_WS_WIN
+    struct tm* t;
+    time_t curr;
+    time(&curr);
+    t = localtime(&curr);
+    time_t locl = mktime(t);
+    t = gmtime(&curr);
+    time_t globl = mktime(t);
+    return double(locl - globl) * 1000.0;
+#else
+    TIME_ZONE_INFORMATION tzInfo;
+    GetTimeZoneInformation(&tzInfo);
+    return -tzInfo.Bias * 60.0 * 1000.0;
+#endif
+}
+
 //
 // Object
 //
@@ -632,6 +1093,429 @@ void BooleanPrototype::method_valueOf(Context *ctx)
 }
 
 //
+// Date object
+//
+Value DateCtor::create(ExecutionEngine *engine)
+{
+    Context *ctx = engine->rootContext;
+    FunctionObject *ctor = ctx->engine->newDateCtor(ctx);
+    ctor->setProperty(ctx, QLatin1String("prototype"), Value::fromObject(ctx->engine->newNumberPrototype(ctx, ctor)));
+    return Value::fromObject(ctor);
+}
+
+DateCtor::DateCtor(Context *scope)
+    : FunctionObject(scope)
+{
+}
+
+void DateCtor::construct(Context *ctx)
+{
+    // called as constructor
+    double t;
+
+    if (ctx->argumentCount == 0)
+        t = currentTime();
+
+    else if (ctx->argumentCount == 1) {
+        Value arg = ctx->argument(0);
+//        if (arg.isDate())
+//            arg = arg.internalValue();
+//        else
+//          __qmljs_to_primitive(ctx, &arg, &arg, PREFERREDTYPE_HINT);
+
+        if (arg.isString())
+            t = ParseString(arg.toString(ctx)->toQString());
+        else
+            t = TimeClip(arg.toNumber(ctx));
+    }
+
+    else { // context->argumentCount() > 1
+        double year  = ctx->argument(0).toNumber(ctx);
+        double month = ctx->argument(1).toNumber(ctx);
+        double day  = ctx->argumentCount >= 3 ? ctx->argument(2).toNumber(ctx) : 1;
+        double hours = ctx->argumentCount >= 4 ? ctx->argument(3).toNumber(ctx) : 0;
+        double mins = ctx->argumentCount >= 5 ? ctx->argument(4).toNumber(ctx) : 0;
+        double secs = ctx->argumentCount >= 6 ? ctx->argument(5).toNumber(ctx) : 0;
+        double ms    = ctx->argumentCount >= 7 ? ctx->argument(6).toNumber(ctx) : 0;
+        if (year >= 0 && year <= 99)
+            year += 1900;
+        t = MakeDate(MakeDay(year, month, day), MakeTime(hours, mins, secs, ms));
+        t = TimeClip(UTC(t));
+    }
+
+//    Value &obj = ctx->m_thisObject;
+//    obj.setClassInfo(classInfo());
+//    obj.setInternalValue(Value(t));
+//    obj.setPrototype(publicPrototype);
+//    ctx->setReturnValue(obj);
+}
+
+void DateCtor::call(Context *ctx)
+{
+    double t = currentTime();
+    ctx->result = Value::fromString(ctx, ToString(t));
+}
+
+DatePrototype::DatePrototype(Context *ctx, FunctionObject *ctor)
+{
+    LocalTZA = getLocalTZA();
+
+    ctor->setProperty(ctx, QLatin1String("parse"), method_parse, 1);
+    ctor->setProperty(ctx, QLatin1String("UTC"), method_UTC, 7);
+
+    setProperty(ctx, QLatin1String("constructor"), Value::fromObject(ctor));
+    setProperty(ctx, QLatin1String("toString"), method_toString, 0);
+    setProperty(ctx, QLatin1String("toDateString"), method_toDateString, 0);
+    setProperty(ctx, QLatin1String("toTimeString"), method_toTimeString, 0);
+    setProperty(ctx, QLatin1String("toLocaleString"), method_toLocaleString, 0);
+    setProperty(ctx, QLatin1String("toLocaleDateString"), method_toLocaleDateString, 0);
+    setProperty(ctx, QLatin1String("toLocaleTimeString"), method_toLocaleTimeString, 0);
+    setProperty(ctx, QLatin1String("valueOf"), method_valueOf, 0);
+    setProperty(ctx, QLatin1String("getTime"), method_getTime, 0);
+    setProperty(ctx, QLatin1String("getYear"), method_getYear, 0);
+    setProperty(ctx, QLatin1String("getFullYear"), method_getFullYear, 0);
+    setProperty(ctx, QLatin1String("getUTCFullYear"), method_getUTCFullYear, 0);
+    setProperty(ctx, QLatin1String("getMonth"), method_getMonth, 0);
+    setProperty(ctx, QLatin1String("getUTCMonth"), method_getUTCMonth, 0);
+    setProperty(ctx, QLatin1String("getDate"), method_getDate, 0);
+    setProperty(ctx, QLatin1String("getUTCDate"), method_getUTCDate, 0);
+    setProperty(ctx, QLatin1String("getDay"), method_getDay, 0);
+    setProperty(ctx, QLatin1String("getUTCDay"), method_getUTCDay, 0);
+    setProperty(ctx, QLatin1String("getHours"), method_getHours, 0);
+    setProperty(ctx, QLatin1String("getUTCHours"), method_getUTCHours, 0);
+    setProperty(ctx, QLatin1String("getMinutes"), method_getMinutes, 0);
+    setProperty(ctx, QLatin1String("getUTCMinutes"), method_getUTCMinutes, 0);
+    setProperty(ctx, QLatin1String("getSeconds"), method_getSeconds, 0);
+    setProperty(ctx, QLatin1String("getUTCSeconds"), method_getUTCSeconds, 0);
+    setProperty(ctx, QLatin1String("getMilliseconds"), method_getMilliseconds, 0);
+    setProperty(ctx, QLatin1String("getUTCMilliseconds"), method_getUTCMilliseconds, 0);
+    setProperty(ctx, QLatin1String("getTimezoneOffset"), method_getTimezoneOffset, 0);
+    setProperty(ctx, QLatin1String("setTime"), method_setTime, 1);
+    setProperty(ctx, QLatin1String("setMilliseconds"), method_setMilliseconds, 1);
+    setProperty(ctx, QLatin1String("setUTCMilliseconds"), method_setUTCMilliseconds, 1);
+    setProperty(ctx, QLatin1String("setSeconds"), method_setSeconds, 2);
+    setProperty(ctx, QLatin1String("setUTCSeconds"), method_setUTCSeconds, 2);
+    setProperty(ctx, QLatin1String("setMinutes"), method_setMinutes, 3);
+    setProperty(ctx, QLatin1String("setUTCMinutes"), method_setUTCMinutes, 3);
+    setProperty(ctx, QLatin1String("setHours"), method_setHours, 4);
+    setProperty(ctx, QLatin1String("setUTCHours"), method_setUTCHours, 4);
+    setProperty(ctx, QLatin1String("setDate"), method_setDate, 1);
+    setProperty(ctx, QLatin1String("setUTCDate"), method_setUTCDate, 1);
+    setProperty(ctx, QLatin1String("setMonth"), method_setMonth, 2);
+    setProperty(ctx, QLatin1String("setUTCMonth"), method_setUTCMonth, 2);
+    setProperty(ctx, QLatin1String("setYear"), method_setYear, 1);
+    setProperty(ctx, QLatin1String("setFullYear"), method_setFullYear, 3);
+    setProperty(ctx, QLatin1String("setUTCFullYear"), method_setUTCFullYear, 3);
+    setProperty(ctx, QLatin1String("toUTCString"), method_toUTCString, 0);
+    setProperty(ctx, QLatin1String("toGMTString"), method_toUTCString, 0);
+}
+
+double DatePrototype::getThisDate(Context *ctx)
+{
+    assert(ctx->thisObject.isObject());
+    Value internalValue;
+    ctx->thisObject.objectValue->defaultValue(ctx, &internalValue, NUMBER_HINT);
+    assert(internalValue.isNumber());
+    return internalValue.numberValue;
+}
+
+void DatePrototype::method_MakeTime(Context *ctx)
+{
+}
+
+void DatePrototype::method_MakeDate(Context *ctx)
+{
+}
+
+void DatePrototype::method_TimeClip(Context *ctx)
+{
+}
+
+void DatePrototype::method_parse(Context *ctx)
+{
+    ctx->result = Value::fromNumber(ParseString(ctx->argument(0).toString(ctx)->toQString()));
+}
+
+void DatePrototype::method_UTC(Context *ctx)
+{
+    const int numArgs = ctx->argumentCount;
+    if (numArgs >= 2) {
+        double year  = ctx->argument(0).toNumber(ctx);
+        double month = ctx->argument(1).toNumber(ctx);
+        double day   = numArgs >= 3 ? ctx->argument(2).toNumber(ctx) : 1;
+        double hours = numArgs >= 4 ? ctx->argument(3).toNumber(ctx) : 0;
+        double mins  = numArgs >= 5 ? ctx->argument(4).toNumber(ctx) : 0;
+        double secs  = numArgs >= 6 ? ctx->argument(5).toNumber(ctx) : 0;
+        double ms    = numArgs >= 7 ? ctx->argument(6).toNumber(ctx) : 0;
+        if (year >= 0 && year <= 99)
+            year += 1900;
+        double t = MakeDate(MakeDay(year, month, day),
+                            MakeTime(hours, mins, secs, ms));
+        ctx->result = Value::fromNumber(TimeClip(t));
+    }
+}
+
+void DatePrototype::method_toString(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    ctx->result = Value::fromString(ctx, ToString(t));
+}
+
+void DatePrototype::method_toDateString(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    ctx->result = Value::fromString(ctx, ToDateString(t));
+}
+
+void DatePrototype::method_toTimeString(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    ctx->result = Value::fromString(ctx, ToTimeString(t));
+}
+
+void DatePrototype::method_toLocaleString(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    ctx->result = Value::fromString(ctx, ToLocaleString(t));
+}
+
+void DatePrototype::method_toLocaleDateString(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    ctx->result = Value::fromString(ctx, ToLocaleDateString(t));
+}
+
+void DatePrototype::method_toLocaleTimeString(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    ctx->result = Value::fromString(ctx, ToLocaleTimeString(t));
+}
+
+void DatePrototype::method_valueOf(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getTime(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getYear(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = YearFromTime(LocalTime(t)) - 1900;
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getFullYear(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = YearFromTime(LocalTime(t));
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getUTCFullYear(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = YearFromTime(t);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getMonth(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = MonthFromTime(LocalTime(t));
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getUTCMonth(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = MonthFromTime(t);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getDate(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = DateFromTime(LocalTime(t));
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getUTCDate(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = DateFromTime(t);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getDay(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = WeekDay(LocalTime(t));
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getUTCDay(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = WeekDay(t);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getHours(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = HourFromTime(LocalTime(t));
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getUTCHours(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = HourFromTime(t);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getMinutes(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = MinFromTime(LocalTime(t));
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getUTCMinutes(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = MinFromTime(t);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getSeconds(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = SecFromTime(LocalTime(t));
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getUTCSeconds(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = SecFromTime(t);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getMilliseconds(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = msFromTime(LocalTime(t));
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getUTCMilliseconds(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = msFromTime(t);
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_getTimezoneOffset(Context *ctx)
+{
+    double t = getThisDate(ctx);
+    if (! qIsNaN(t))
+        t = (t - LocalTime(t)) / msPerMinute;
+    ctx->result = Value::fromNumber(t);
+}
+
+void DatePrototype::method_setTime(Context *ctx)
+{
+}
+
+void DatePrototype::method_setMilliseconds(Context *ctx)
+{
+}
+
+void DatePrototype::method_setUTCMilliseconds(Context *ctx)
+{
+}
+
+void DatePrototype::method_setSeconds(Context *ctx)
+{
+}
+
+void DatePrototype::method_setUTCSeconds(Context *ctx)
+{
+}
+
+void DatePrototype::method_setMinutes(Context *ctx)
+{
+}
+
+void DatePrototype::method_setUTCMinutes(Context *ctx)
+{
+}
+
+void DatePrototype::method_setHours(Context *ctx)
+{
+}
+
+void DatePrototype::method_setUTCHours(Context *ctx)
+{
+}
+
+void DatePrototype::method_setDate(Context *ctx)
+{
+}
+
+void DatePrototype::method_setUTCDate(Context *ctx)
+{
+}
+
+void DatePrototype::method_setMonth(Context *ctx)
+{
+}
+
+void DatePrototype::method_setUTCMonth(Context *ctx)
+{
+}
+
+void DatePrototype::method_setYear(Context *ctx)
+{
+}
+
+void DatePrototype::method_setFullYear(Context *ctx)
+{
+}
+
+void DatePrototype::method_setUTCFullYear(Context *ctx)
+{
+}
+
+void DatePrototype::method_toUTCString(Context *ctx)
+{
+}
+
+//
 // Math object
 //
 MathObject::MathObject(Context *ctx)
index d37aefc..68c1522 100644 (file)
@@ -102,6 +102,73 @@ protected:
     static void method_valueOf(Context *ctx);
 };
 
+struct DateCtor: FunctionObject
+{
+    static Value create(ExecutionEngine *engine);
+
+    DateCtor(Context *scope);
+
+    virtual void construct(Context *ctx);
+    virtual void call(Context *ctx);
+};
+
+struct DatePrototype: Object
+{
+    DatePrototype(Context *ctx, FunctionObject *ctor);
+
+protected:
+    static double getThisDate(Context *ctx);
+
+    static void method_MakeTime(Context *ctx);
+    static void method_MakeDate(Context *ctx);
+    static void method_TimeClip(Context *ctx);
+    static void method_parse(Context *ctx);
+    static void method_UTC(Context *ctx);
+    static void method_toString(Context *ctx);
+    static void method_toDateString(Context *ctx);
+    static void method_toTimeString(Context *ctx);
+    static void method_toLocaleString(Context *ctx);
+    static void method_toLocaleDateString(Context *ctx);
+    static void method_toLocaleTimeString(Context *ctx);
+    static void method_valueOf(Context *ctx);
+    static void method_getTime(Context *ctx);
+    static void method_getYear(Context *ctx);
+    static void method_getFullYear(Context *ctx);
+    static void method_getUTCFullYear(Context *ctx);
+    static void method_getMonth(Context *ctx);
+    static void method_getUTCMonth(Context *ctx);
+    static void method_getDate(Context *ctx);
+    static void method_getUTCDate(Context *ctx);
+    static void method_getDay(Context *ctx);
+    static void method_getUTCDay(Context *ctx);
+    static void method_getHours(Context *ctx);
+    static void method_getUTCHours(Context *ctx);
+    static void method_getMinutes(Context *ctx);
+    static void method_getUTCMinutes(Context *ctx);
+    static void method_getSeconds(Context *ctx);
+    static void method_getUTCSeconds(Context *ctx);
+    static void method_getMilliseconds(Context *ctx);
+    static void method_getUTCMilliseconds(Context *ctx);
+    static void method_getTimezoneOffset(Context *ctx);
+    static void method_setTime(Context *ctx);
+    static void method_setMilliseconds(Context *ctx);
+    static void method_setUTCMilliseconds(Context *ctx);
+    static void method_setSeconds(Context *ctx);
+    static void method_setUTCSeconds(Context *ctx);
+    static void method_setMinutes(Context *ctx);
+    static void method_setUTCMinutes(Context *ctx);
+    static void method_setHours(Context *ctx);
+    static void method_setUTCHours(Context *ctx);
+    static void method_setDate(Context *ctx);
+    static void method_setUTCDate(Context *ctx);
+    static void method_setMonth(Context *ctx);
+    static void method_setUTCMonth(Context *ctx);
+    static void method_setYear(Context *ctx);
+    static void method_setFullYear(Context *ctx);
+    static void method_setUTCFullYear(Context *ctx);
+    static void method_toUTCString(Context *ctx);
+};
+
 struct MathObject: Object
 {
     MathObject(Context *ctx);
index 3a85815..e26b726 100644 (file)
@@ -506,6 +506,9 @@ void InstructionSelection::visitMove(IR::Move *s)
                     return;
                 }
                 assert(!"todo");
+            } else if (IR::Subscript *ss = s->source->asSubscript()) {
+                qWarning() << "TODO load subscript";
+                return;
             } else if (IR::Unop *u = s->source->asUnop()) {
                 if (IR::Temp *e = u->expr->asTemp()) {
                     amd64_mov_reg_reg(_codePtr, AMD64_RDI, AMD64_R14, 8);
@@ -522,8 +525,9 @@ void InstructionSelection::visitMove(IR::Move *s)
                     } // switch
                     amd64_call_code(_codePtr, op);
                     return;
+                } else if (IR::Const *c = u->expr->asConst()) {
+                    return;
                 }
-
             } else if (IR::Binop *b = s->source->asBinop()) {
                 IR::Temp *l = b->left->asTemp();
                 IR::Temp *r = b->right->asTemp();
@@ -660,9 +664,40 @@ void InstructionSelection::visitMove(IR::Move *s)
                     return;
                 }
             }
+        } else if (IR::Subscript *ss = s->target->asSubscript()) {
+            if (IR::Temp *t = s->source->asTemp()) {
+                return;
+            } else if (IR::Const *c = s->source->asConst()) {
+                return;
+            }
         }
     } else {
         // inplace assignment, e.g. x += 1, ++x, ...
+        if (IR::Temp *t = s->target->asTemp()) {
+            if (IR::Const *c = s->source->asConst()) {
+                return;
+            } else if (IR::Temp *t2 = s->source->asTemp()) {
+                return;
+            }
+        } else if (IR::Name *n = s->target->asName()) {
+            if (IR::Const *c = s->source->asConst()) {
+                return;
+            } else if (IR::Temp *t = s->source->asTemp()) {
+                return;
+            }
+        } else if (IR::Subscript *ss = s->target->asSubscript()) {
+            if (IR::Const *c = s->source->asConst()) {
+                return;
+            } else if (IR::Temp *t = s->source->asTemp()) {
+                return;
+            }
+        } else if (IR::Member *m = s->target->asMember()) {
+            if (IR::Const *c = s->source->asConst()) {
+                return;
+            } else if (IR::Temp *t = s->source->asTemp()) {
+                return;
+            }
+        }
     }
 
     Q_UNIMPLEMENTED();