scummvm/engines/private/grammar.h

143 lines
2.8 KiB
C
Raw Normal View History

2021-02-13 14:55:30 -03: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.
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
2021-02-16 17:51:09 -03:00
#ifndef PRIVATE_GRAMMAR_H
#define PRIVATE_GRAMMAR_H
#include "common/str.h"
#include "common/hash-str.h"
#include "common/hash-ptr.h"
2021-01-01 12:22:05 -03:00
#include "common/queue.h"
#include "common/list.h"
2021-01-02 00:58:58 -03:00
#include "common/array.h"
2021-01-05 21:03:34 -03:00
#include "common/rect.h"
2021-02-16 17:51:09 -03:00
#include "private/symbol.h"
2021-02-13 18:44:23 -03:00
#define NSTACK 256
#define NPROG 10000
2021-01-01 12:22:05 -03:00
2021-01-10 20:44:27 -03:00
namespace Private {
2021-02-13 18:44:23 -03:00
typedef struct Datum { /* interpreter stack type */
2021-03-05 19:27:58 +01:00
short type;
union {
int val;
const char *str;
Symbol *sym;
Common::Rect *rect;
} u;
} Datum;
2020-12-30 19:33:25 -03:00
2021-01-10 20:44:27 -03:00
typedef struct Arg {
2021-03-05 19:27:58 +01:00
int n;
int (** inst)();
2021-01-10 20:44:27 -03:00
} Arg;
2020-12-30 19:33:25 -03:00
typedef int (* Inst)(); /* machine instruction */
2021-03-05 19:27:58 +01:00
#define STOP (Inst) 0
2021-01-09 22:08:41 -03:00
typedef Common::HashMap<void *, Common::String *> PtrToName;
2021-02-17 16:51:34 -03:00
void initInsts();
void initFuncs();
2021-01-09 22:08:41 -03:00
2021-02-23 11:21:32 -03:00
namespace Settings {
typedef struct Setting {
2021-03-05 19:27:58 +01:00
Datum stack[NSTACK]; /* the stack */
Inst prog[NPROG]; /* the machine */
} Setting;
typedef Common::HashMap<Common::String, Setting *> SettingMap;
class SettingMaps {
2021-02-26 18:33:34 -03:00
public:
2021-03-05 19:27:58 +01:00
Setting *_setting;
SettingMap _map;
2021-03-05 19:27:58 +01:00
void init();
void save(const char *);
void load(const Common::String &);
};
2021-02-22 20:59:12 -03:00
extern SettingMaps *g_setts;
2021-02-23 11:21:32 -03:00
}
2021-01-02 00:58:58 -03:00
// Funtions
typedef Common::Array<Datum> ArgArray;
void call(const char *, const ArgArray &);
2021-01-02 00:58:58 -03:00
2021-02-23 11:21:32 -03:00
// Code Generation and Execution
2021-02-22 20:59:12 -03:00
namespace Gen {
class VM {
2021-02-26 18:33:34 -03:00
public:
2021-03-05 19:27:58 +01:00
Datum *_stack; /* the stack */
Datum *_stackp; /* next free spot on stack */
2021-02-22 20:59:12 -03:00
2021-03-05 19:27:58 +01:00
Inst *_progp; /* next free spot for code generation */
Inst *_prog; /* the machine */
Inst *_pc; /* program counter during execution */
void run(); /* run the virtual machine */
2021-02-22 20:59:12 -03:00
};
extern VM *g_vm;
Datum pop();
2021-03-04 18:03:36 +09:00
int push(const Datum &);
2021-03-04 18:03:36 +09:00
Inst *code(const Inst &);
int eval();
int add();
int negate();
int power();
int assign();
int bltin();
int varpush();
int constpush();
int strpush();
int funcpush();
int print();
int ifcode();
int fail();
int lt();
int gt();
int le();
int ge();
int eq();
int ne();
int randbool();
2020-12-30 21:26:15 -03:00
2021-01-02 00:58:58 -03:00
// Code Execution
2020-12-30 21:26:15 -03:00
2021-02-17 16:51:34 -03:00
void execute(Inst *);
2020-12-30 19:33:25 -03:00
2021-02-22 20:59:12 -03:00
}
2021-02-13 18:27:24 -03:00
} // End of namespace Private
#endif