From f0c42f10bda5c8a489fe1ada356eb420c0fa3685 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 8 Apr 2011 00:21:49 +0200 Subject: MOHAWK: Implement LBCode logical operators. --- engines/mohawk/livingbooks_code.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index 661c2385f8..48c48ba917 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -257,8 +257,29 @@ LBValue LBCode::runCode(byte terminator) { } void LBCode::parseStatement() { - // FIXME: logical operators parseComparisons(); + + if (_currToken != kTokenAnd && _currToken != kTokenOr) + return; + byte op = _currToken; + if (op == kTokenAnd) + debugN(" && "); + else + debugN(" || "); + + nextToken(); + parseComparisons(); + + LBValue val2 = _stack.pop(); + LBValue val1 = _stack.pop(); + bool result; + if (op == kTokenAnd) + result = !val1.isZero() && !val2.isZero(); + else + result = !val1.isZero() || !val2.isZero(); + + debugN(" [--> %s]", result ? "true" : "false"); + _stack.push(result); } void LBCode::parseComparisons() { @@ -320,7 +341,7 @@ void LBCode::parseComparisons() { } debugN(" [--> %s]", result ? "true" : "false"); - _stack.push(result ? 1 : 0); + _stack.push(result); } void LBCode::parseConcat() { -- cgit v1.2.3