2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-04-05 18:08:02 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2005-04-09 19:19:54 +00:00
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
*/
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2009-06-22 16:30:06 +00:00
|
|
|
#ifndef GOB_EXPRESSION_H
|
|
|
|
#define GOB_EXPRESSION_H
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2009-06-16 20:39:37 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
namespace Gob {
|
|
|
|
|
2009-06-16 20:39:37 +00:00
|
|
|
class GobEngine;
|
|
|
|
|
2009-04-07 10:41:23 +00:00
|
|
|
enum {
|
2009-06-15 23:08:44 +00:00
|
|
|
OP_NEG = 1,
|
|
|
|
OP_ADD = 2,
|
|
|
|
OP_SUB = 3,
|
|
|
|
OP_BITOR = 4,
|
|
|
|
OP_MUL = 5,
|
|
|
|
OP_DIV = 6,
|
|
|
|
OP_MOD = 7,
|
|
|
|
OP_BITAND = 8,
|
|
|
|
OP_BEGIN_EXPR = 9,
|
|
|
|
OP_END_EXPR = 10,
|
|
|
|
OP_NOT = 11,
|
|
|
|
|
|
|
|
OP_END_MARKER = 12, // Marks end of an array or string
|
|
|
|
|
|
|
|
|
|
|
|
OP_ARRAY_INT8 = 16,
|
|
|
|
OP_LOAD_VAR_INT16 = 17,
|
|
|
|
OP_LOAD_VAR_INT8 = 18,
|
|
|
|
OP_LOAD_IMM_INT32 = 19,
|
|
|
|
OP_LOAD_IMM_INT16 = 20,
|
|
|
|
OP_LOAD_IMM_INT8 = 21,
|
|
|
|
OP_LOAD_IMM_STR = 22,
|
|
|
|
OP_LOAD_VAR_INT32 = 23,
|
|
|
|
OP_LOAD_VAR_INT32_AS_INT16 = 24,
|
|
|
|
OP_LOAD_VAR_STR = 25,
|
|
|
|
OP_ARRAY_INT32 = 26,
|
|
|
|
OP_ARRAY_INT16 = 27,
|
|
|
|
OP_ARRAY_STR = 28,
|
2009-04-07 13:21:20 +00:00
|
|
|
|
|
|
|
OP_FUNC = 29,
|
|
|
|
|
2009-06-15 23:08:44 +00:00
|
|
|
OP_OR = 30, // Logical OR
|
|
|
|
OP_AND = 31, // Logical AND
|
|
|
|
OP_LESS = 32,
|
|
|
|
OP_LEQ = 33,
|
2009-04-07 13:21:20 +00:00
|
|
|
OP_GREATER = 34,
|
2009-06-15 23:08:44 +00:00
|
|
|
OP_GEQ = 35,
|
|
|
|
OP_EQ = 36,
|
|
|
|
OP_NEQ = 37
|
2009-04-07 13:21:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2009-06-15 23:08:44 +00:00
|
|
|
FUNC_SQRT1 = 0,
|
|
|
|
FUNC_SQRT2 = 1,
|
|
|
|
FUNC_SQRT3 = 6,
|
2009-04-07 13:21:20 +00:00
|
|
|
|
2009-06-15 23:08:44 +00:00
|
|
|
FUNC_SQR = 5,
|
|
|
|
FUNC_ABS = 7,
|
|
|
|
FUNC_RAND = 10
|
2009-04-07 13:21:20 +00:00
|
|
|
};
|
2009-06-15 23:09:04 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
TYPE_IMM_INT8 = OP_LOAD_IMM_INT8, // 21
|
|
|
|
TYPE_IMM_INT32 = OP_LOAD_IMM_INT32, // 19
|
|
|
|
TYPE_IMM_INT16 = OP_LOAD_IMM_INT16, // 20
|
|
|
|
TYPE_IMM_STR = OP_LOAD_IMM_STR, // 22
|
|
|
|
TYPE_VAR_INT8 = OP_LOAD_VAR_INT8, // 18
|
|
|
|
TYPE_VAR_INT16 = OP_LOAD_VAR_INT16, // 17
|
|
|
|
TYPE_VAR_INT32 = OP_LOAD_VAR_INT32, // 23
|
|
|
|
TYPE_VAR_STR = OP_LOAD_VAR_STR, // 25
|
|
|
|
TYPE_ARRAY_INT8 = OP_ARRAY_INT8, // 16
|
|
|
|
TYPE_ARRAY_INT16 = OP_ARRAY_INT16, // 27
|
|
|
|
TYPE_ARRAY_INT32 = OP_ARRAY_INT32, // 26
|
|
|
|
TYPE_ARRAY_STR = OP_ARRAY_STR, // 28
|
|
|
|
TYPE_VAR_INT32_AS_INT16 = OP_LOAD_VAR_INT32_AS_INT16 // 24
|
|
|
|
};
|
2009-04-07 13:21:20 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
// FIXME: The following two 'truth values' are stored inside the list
|
2009-06-15 23:08:44 +00:00
|
|
|
// of "operators". So they somehow coincide with OP_LOAD_VAR_INT32
|
|
|
|
// and OP_LOAD_VAR_INT32_AS_INT16. I haven't yet quite understood
|
2009-04-07 13:21:20 +00:00
|
|
|
// how, resp. what that means. You have been warned.
|
2009-06-15 23:08:44 +00:00
|
|
|
GOB_TRUE = 24,
|
2009-04-07 13:21:20 +00:00
|
|
|
GOB_FALSE = 23
|
2009-04-07 10:41:23 +00:00
|
|
|
};
|
|
|
|
|
2009-06-22 16:30:06 +00:00
|
|
|
class Expression {
|
2006-01-03 23:14:39 +00:00
|
|
|
public:
|
2009-06-22 16:30:06 +00:00
|
|
|
Expression(GobEngine *vm);
|
|
|
|
virtual ~Expression() {}
|
2009-06-22 10:11:25 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void skipExpr(char stopToken);
|
|
|
|
void printExpr(char stopToken);
|
2009-11-02 21:54:57 +00:00
|
|
|
void printVarIndex();
|
2009-06-07 01:45:09 +00:00
|
|
|
|
2009-06-15 23:08:09 +00:00
|
|
|
int16 parseVarIndex(uint16 *size = 0, uint16 *type = 0);
|
2009-06-07 01:45:09 +00:00
|
|
|
int16 parseValExpr(byte stopToken = 99);
|
2009-06-15 23:08:09 +00:00
|
|
|
int16 parseExpr(byte stopToken, byte *type);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2009-06-22 10:11:25 +00:00
|
|
|
int32 getResultInt();
|
2009-06-22 10:11:53 +00:00
|
|
|
char *getResultStr();
|
2009-06-15 23:10:51 +00:00
|
|
|
|
2009-06-07 01:45:09 +00:00
|
|
|
private:
|
2009-06-16 20:15:19 +00:00
|
|
|
class Stack {
|
|
|
|
public:
|
|
|
|
byte *opers;
|
|
|
|
int32 *values;
|
|
|
|
|
|
|
|
Stack(size_t size = 20);
|
|
|
|
~Stack();
|
|
|
|
};
|
|
|
|
class StackFrame {
|
|
|
|
public:
|
|
|
|
byte *opers;
|
|
|
|
int32 *values;
|
|
|
|
int16 pos;
|
|
|
|
|
|
|
|
StackFrame(const Stack &stack);
|
|
|
|
|
|
|
|
void push(int count = 1);
|
|
|
|
void pop(int count = 1);
|
|
|
|
};
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
enum PointerType {
|
2009-06-15 23:08:44 +00:00
|
|
|
kExecPtr = 0,
|
2006-01-03 23:14:39 +00:00
|
|
|
kInterVar = 1,
|
2009-06-15 23:08:44 +00:00
|
|
|
kResStr = 2
|
2006-01-03 23:14:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GobEngine *_vm;
|
|
|
|
|
2009-06-22 10:11:25 +00:00
|
|
|
int32 _resultInt;
|
2009-06-22 10:11:53 +00:00
|
|
|
char _resultStr[200];
|
2009-06-22 10:11:25 +00:00
|
|
|
|
2007-04-02 11:05:09 +00:00
|
|
|
int32 encodePtr(byte *ptr, int type);
|
|
|
|
byte *decodePtr(int32 n);
|
2006-05-21 21:18:23 +00:00
|
|
|
|
|
|
|
void printExpr_internal(char stopToken);
|
2009-04-07 13:20:29 +00:00
|
|
|
|
2009-06-15 23:08:44 +00:00
|
|
|
bool getVarBase(uint32 &varBase, bool mindStop = false,
|
|
|
|
uint16 *size = 0, uint16 *type = 0);
|
2009-06-16 20:15:19 +00:00
|
|
|
int cmpHelper(const StackFrame &stackFrame);
|
|
|
|
void loadValue(byte operation, uint32 varBase, const StackFrame &stackFrame);
|
2009-06-16 20:14:56 +00:00
|
|
|
|
2009-06-16 20:15:19 +00:00
|
|
|
void simpleArithmetic1(StackFrame &stackFrame);
|
|
|
|
void simpleArithmetic2(StackFrame &stackFrame);
|
|
|
|
bool complexArithmetic(Stack &stack, StackFrame &stackFrame, int16 brackStart);
|
2009-06-15 23:10:27 +00:00
|
|
|
void getResult(byte operation, int32 value, byte *type);
|
2006-01-03 23:14:39 +00:00
|
|
|
};
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
} // End of namespace Gob
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2009-06-22 16:30:06 +00:00
|
|
|
#endif // GOB_EXPRESSION_H
|