diff options
author | Alyssa Milburn | 2011-04-07 23:07:04 +0200 |
---|---|---|
committer | Alyssa Milburn | 2011-04-07 23:07:04 +0200 |
commit | ac1522e177de979d6d9ef3248c0747de3dba00b5 (patch) | |
tree | f9d2ea5d81f1ed76c231c5de01e0ebf47922b356 | |
parent | f65840feef59557d3c759e7fa44996ae76d199be (diff) | |
download | scummvm-rg350-ac1522e177de979d6d9ef3248c0747de3dba00b5.tar.gz scummvm-rg350-ac1522e177de979d6d9ef3248c0747de3dba00b5.tar.bz2 scummvm-rg350-ac1522e177de979d6d9ef3248c0747de3dba00b5.zip |
MOHAWK: Implement some more LBCode ops.
-rw-r--r-- | engines/mohawk/livingbooks_code.cpp | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp index dc72b2f974..354fb0488a 100644 --- a/engines/mohawk/livingbooks_code.cpp +++ b/engines/mohawk/livingbooks_code.cpp @@ -249,7 +249,7 @@ LBValue LBCode::runCode(byte terminator) { if (_currToken == terminator || _currToken == kTokenEndOfFile) break; if (_currToken != kTokenEndOfStatement && _currToken != kTokenEndOfFile) - error("missing EOS"); + error("missing EOS (got %02x)", _currToken); debugN("\n"); } @@ -325,12 +325,45 @@ void LBCode::parseComparisons() { void LBCode::parseConcat() { parseArithmetic1(); - // FIXME: string concat + + if (_currToken != kTokenConcat) + return; + + debugN(" & "); + nextToken(); + parseArithmetic1(); + + LBValue val2 = _stack.pop(); + LBValue val1 = _stack.pop(); + Common::String result = val1.toString() + val2.toString(); + debugN(" [--> \"%s\"]", result.c_str()); + _stack.push(result); } void LBCode::parseArithmetic1() { parseArithmetic2(); - // FIXME: -/+ math operators + + if (_currToken != kTokenMinus && _currToken != kTokenPlus) + return; + + byte op = _currToken; + if (op == kTokenMinus) + debugN(" - "); + else if (op == kTokenPlus) + debugN(" + "); + + nextToken(); + parseArithmetic2(); + + LBValue val2 = _stack.pop(); + LBValue val1 = _stack.pop(); + LBValue result; + // TODO: cope with non-integers + if (op == kTokenMinus) + result = val1.toInt() - val2.toInt(); + else + result = val1.toInt() + val2.toInt(); + _stack.push(result); } void LBCode::parseArithmetic2() { @@ -357,6 +390,7 @@ void LBCode::parseMain() { _stack.push(LBValue(_currSource)); if (_currToken == kTokenAssign) error("attempted assignment to self"); + break; } else if (_currToken == kTokenAssign) { debugN(" = "); nextToken(); @@ -369,7 +403,16 @@ void LBCode::parseMain() { } else { _stack.push(_vm->_variables[varname]); } - // FIXME: pre/postincrement + // FIXME: pre/postincrement for non-integers + if (_currToken == kTokenPlusPlus) { + debugN("++"); + _vm->_variables[varname].integer++; + nextToken(); + } else if (_currToken == kTokenMinusMinus) { + debugN("--"); + _vm->_variables[varname].integer--; + nextToken(); + } } break; @@ -391,6 +434,17 @@ void LBCode::parseMain() { nextToken(); break; + case kTokenTrue: + debugN("TRUE"); + _stack.push(true); + nextToken(); + break; + case kTokenFalse: + debugN("FALSE"); + _stack.push(false); + nextToken(); + break; + case kTokenOpenBracket: debugN("("); nextToken(); |