From 62f398e4aed5b34ee2bd8edff9fb3afa80d75e25 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 21 Jan 2014 03:35:43 -0800 Subject: [PATCH] Implement internal multiply (for the compiler). --- Parser.hpp | 2 +- Replace.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Parser.hpp b/Parser.hpp index 0e4b51f..59e657f 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -2043,7 +2043,7 @@ CYPrefix_(false, "-", Negate) CYPrefix_(false, "~", BitwiseNot) CYPrefix_(false, "!", LogicalNot) -CYInfix_(false, 5, "*", Multiply) +CYInfix_(false, 5, "*", Multiply, CYReplace) CYInfix_(false, 5, "/", Divide) CYInfix_(false, 5, "%", Modulus) CYInfix_(false, 6, "+", Add, CYReplace) diff --git a/Replace.cpp b/Replace.cpp index 83a5c47..f577919 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -533,6 +533,19 @@ CYStatement *CYLetStatement::Replace(CYContext &context) { return $E($ CYCall(CYNonLocalize(context, $ CYFunctionExpression(NULL, declarations_->Parameter(context), code_)), declarations_->Argument(context))); } +CYExpression *CYMultiply::Replace(CYContext &context) { + CYInfix::Replace(context); + + CYExpression *lhp(lhs_->Primitive(context)); + CYExpression *rhp(rhs_->Primitive(context)); + + if (CYNumber *lhn = lhp->Number(context)) + if (CYNumber *rhn = rhp->Number(context)) + return $D(lhn->Value() * rhn->Value()); + + return this; +} + namespace cy { namespace Syntax { -- 2.45.2