From: Michael Brasser Date: Wed, 7 Mar 2012 23:16:07 +0000 (+1000) Subject: Add Math.ceil and Math.abs support to v4. X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=3eeba70a199de4d2ba85553a32a07c81d81664c9;p=konrad%2Fqtdeclarative.git Add Math.ceil and Math.abs support to v4. Change-Id: I23e7c8294abf80914d4529740af6e9124f66c5bf Reviewed-by: Roberto Raggi --- diff --git a/src/qml/qml/v4/qv4bindings.cpp b/src/qml/qml/v4/qv4bindings.cpp index 4fd8494..3f3b666 100644 --- a/src/qml/qml/v4/qv4bindings.cpp +++ b/src/qml/qml/v4/qv4bindings.cpp @@ -1172,6 +1172,15 @@ void QV4Bindings::run(int instrIndex, quint32 &executedBlocks, } QML_V4_END_INSTR(MathCosReal, unaryop) + QML_V4_BEGIN_INSTR(MathAbsReal, unaryop) + { + const Register &src = registers[instr->unaryop.src]; + Register &output = registers[instr->unaryop.output]; + if (src.isUndefined()) output.setUndefined(); + else output.setqreal(qAbs(src.getqreal())); + } + QML_V4_END_INSTR(MathAbsReal, unaryop) + QML_V4_BEGIN_INSTR(MathRoundReal, unaryop) { const Register &src = registers[instr->unaryop.src]; @@ -1190,6 +1199,15 @@ void QV4Bindings::run(int instrIndex, quint32 &executedBlocks, } QML_V4_END_INSTR(MathFloorReal, unaryop) + QML_V4_BEGIN_INSTR(MathCeilReal, unaryop) + { + const Register &src = registers[instr->unaryop.src]; + Register &output = registers[instr->unaryop.output]; + if (src.isUndefined()) output.setUndefined(); + else output.setint(qCeil(src.getqreal())); + } + QML_V4_END_INSTR(MathCeilReal, unaryop) + QML_V4_BEGIN_INSTR(MathPIReal, unaryop) { static const qreal qmlPI = 2.0 * qAsin(1.0); diff --git a/src/qml/qml/v4/qv4compiler.cpp b/src/qml/qml/v4/qv4compiler.cpp index 608368a..ce83c2d 100644 --- a/src/qml/qml/v4/qv4compiler.cpp +++ b/src/qml/qml/v4/qv4compiler.cpp @@ -803,6 +803,12 @@ void QV4CompilerPrivate::visitCall(IR::Call *call) gen(i); } return; + case IR::MathAbsBuiltinFunction: { + Instr::MathAbsReal i; + i.output = i.src = currentReg; + gen(i); + } return; + case IR::MathRoundBultinFunction: { Instr::MathRoundReal i; i.output = i.src = currentReg; @@ -815,6 +821,12 @@ void QV4CompilerPrivate::visitCall(IR::Call *call) gen(i); } return; + case IR::MathCeilBuiltinFunction: { + Instr::MathCeilReal i; + i.output = i.src = currentReg; + gen(i); + } return; + case IR::MathPIBuiltinConstant: break; } // switch diff --git a/src/qml/qml/v4/qv4instruction.cpp b/src/qml/qml/v4/qv4instruction.cpp index efbd2b2..309ae90 100644 --- a/src/qml/qml/v4/qv4instruction.cpp +++ b/src/qml/qml/v4/qv4instruction.cpp @@ -195,12 +195,18 @@ void Bytecode::dump(const V4Instr *i, int address) const case V4Instr::MathCosReal: INSTR_DUMP << "\t" << "MathCosReal" << "\t\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")"; break; + case V4Instr::MathAbsReal: + INSTR_DUMP << "\t" << "MathAbsReal" << "\t\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")"; + break; case V4Instr::MathRoundReal: INSTR_DUMP << "\t" << "MathRoundReal" << "\t\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")"; break; case V4Instr::MathFloorReal: INSTR_DUMP << "\t" << "MathFloorReal" << "\t\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")"; break; + case V4Instr::MathCeilReal: + INSTR_DUMP << "\t" << "MathCeilReal" << "\t\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")"; + break; case V4Instr::MathPIReal: INSTR_DUMP << "\t" << "MathPIReal" << "\t\t" << "Input_Reg(" << i->unaryop.src << ") -> Output_Reg(" << i->unaryop.output << ")"; break; diff --git a/src/qml/qml/v4/qv4instruction_p.h b/src/qml/qml/v4/qv4instruction_p.h index 964c955..fef8565 100644 --- a/src/qml/qml/v4/qv4instruction_p.h +++ b/src/qml/qml/v4/qv4instruction_p.h @@ -100,8 +100,10 @@ QT_BEGIN_NAMESPACE F(ResolveUrl, unaryop) \ F(MathSinReal, unaryop) \ F(MathCosReal, unaryop) \ + F(MathAbsReal, unaryop) \ F(MathRoundReal, unaryop) \ F(MathFloorReal, unaryop) \ + F(MathCeilReal, unaryop) \ F(MathPIReal, unaryop) \ F(LoadReal, real_value) \ F(LoadInt, int_value) \ diff --git a/src/qml/qml/v4/qv4ir.cpp b/src/qml/qml/v4/qv4ir.cpp index 68175d3..051df56 100644 --- a/src/qml/qml/v4/qv4ir.cpp +++ b/src/qml/qml/v4/qv4ir.cpp @@ -219,10 +219,14 @@ void Name::init(Name *base, Type type, const QString *id, Symbol symbol, quint32 builtin = MathSinBultinFunction; } else if (id->length() == 8 && *id == QLatin1String("Math.cos")) { builtin = MathCosBultinFunction; + } else if (id->length() == 8 && *id == QLatin1String("Math.abs")) { + builtin = MathAbsBuiltinFunction; } else if (id->length() == 10 && *id == QLatin1String("Math.round")) { builtin = MathRoundBultinFunction; } else if (id->length() == 10 && *id == QLatin1String("Math.floor")) { builtin = MathFloorBultinFunction; + } else if (id->length() == 9 && *id == QLatin1String("Math.ceil")) { + builtin = MathCeilBuiltinFunction; } else if (id->length() == 7 && *id == QLatin1String("Math.PI")) { builtin = MathPIBuiltinConstant; this->type = RealType; @@ -353,10 +357,12 @@ Type Call::typeForFunction(Expr *base) switch (name->builtin) { case MathSinBultinFunction: case MathCosBultinFunction: + case MathAbsBuiltinFunction: //### type could also be Int if input was Int return RealType; case MathRoundBultinFunction: case MathFloorBultinFunction: + case MathCeilBuiltinFunction: return IntType; case NoBuiltinSymbol: diff --git a/src/qml/qml/v4/qv4ir_p.h b/src/qml/qml/v4/qv4ir_p.h index 3d3288b..6520131 100644 --- a/src/qml/qml/v4/qv4ir_p.h +++ b/src/qml/qml/v4/qv4ir_p.h @@ -239,6 +239,8 @@ enum BuiltinSymbol { MathCosBultinFunction, MathRoundBultinFunction, MathFloorBultinFunction, + MathCeilBuiltinFunction, + MathAbsBuiltinFunction, MathPIBuiltinConstant };