From a1e9cecd39bbd3541cc8e9cd69cca4578151b8d9 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sun, 3 Jul 2011 18:19:32 +0200 Subject: MOHAWK: Implement the remaining LBCode arithmetic operators. --- engines/mohawk/livingbooks_code.cpp | 49 ++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'engines/mohawk') diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index 83b801ed6b..e9ef2516e2 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -405,8 +405,55 @@ void LBCode::parseArithmetic1() { } void LBCode::parseArithmetic2() { - // FIXME: other math operators parseMain(); + + while (true) { + byte op = _currToken; + switch (op) { + case kTokenMultiply: + debugN(" * "); + break; + case kTokenDivide: + debugN(" / "); + break; + case kTokenIntDivide: + debugN(" div "); + break; + case kTokenModulo: + debugN(" %% "); + break; + default: + return; + } + + nextToken(); + parseMain(); + + LBValue val2 = _stack.pop(); + LBValue val1 = _stack.pop(); + LBValue result; + // TODO: cope with non-integers + if (op == kTokenMultiply) { + result = val1.toInt() * val2.toInt(); + } else if (val2.toInt() == 0) { + result = 1; + } else { + switch (op) { + case kTokenDivide: + // TODO: fp divide + result = val1.toInt() / val2.toInt(); + break; + case kTokenIntDivide: + result = val1.toInt() / val2.toInt(); + break; + case kTokenModulo: + result = val1.toInt() % val2.toInt(); + break; + } + } + + _stack.push(result); + } } void LBCode::parseMain() { -- cgit v1.2.3