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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-12-31 17:03:11 -03:00
|
|
|
#include "common/str.h"
|
|
|
|
#include "common/hash-str.h"
|
2021-01-06 21:46:54 -03:00
|
|
|
#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-01-10 20:44:27 -03:00
|
|
|
#include "private/symbol.h"
|
2020-12-31 17:03:11 -03:00
|
|
|
|
|
|
|
#ifndef PRIVATE_GRAMMAR_H
|
|
|
|
#define PRIVATE_GRAMMAR_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-06 21:46:54 -03:00
|
|
|
|
2021-01-10 20:44:27 -03:00
|
|
|
namespace Private {
|
2020-12-30 09:16:19 -03:00
|
|
|
|
2021-02-13 18:44:23 -03:00
|
|
|
typedef struct Datum { /* interpreter stack type */
|
2021-01-17 21:52:04 -03:00
|
|
|
short type;
|
|
|
|
union {
|
2021-02-13 18:44:23 -03:00
|
|
|
int val;
|
2021-01-17 21:52:04 -03:00
|
|
|
char *str;
|
2021-02-13 18:44:23 -03:00
|
|
|
Symbol *sym;
|
2021-01-17 21:52:04 -03:00
|
|
|
Common::Rect *rect;
|
|
|
|
} u;
|
2020-12-30 09:16:19 -03:00
|
|
|
} Datum;
|
2020-12-30 19:33:25 -03:00
|
|
|
|
2021-01-10 20:44:27 -03:00
|
|
|
|
|
|
|
typedef struct Arg {
|
2021-01-17 21:52:04 -03:00
|
|
|
int n;
|
2021-02-15 00:17:29 -03:00
|
|
|
int (** inst)();
|
2021-01-10 20:44:27 -03:00
|
|
|
} Arg;
|
2020-12-30 19:33:25 -03:00
|
|
|
|
2021-02-15 00:17:29 -03:00
|
|
|
typedef int (* Inst)(); /* machine instruction */
|
2021-02-13 18:44:23 -03:00
|
|
|
#define STOP (Inst) 0
|
2020-12-30 09:16:19 -03:00
|
|
|
|
2021-01-09 22:08:41 -03:00
|
|
|
typedef Common::HashMap<void *, Common::String *> PtrToName;
|
|
|
|
typedef Common::HashMap<Common::String, void *> NameToPtr;
|
2021-01-06 21:46:54 -03:00
|
|
|
|
2021-01-09 22:08:41 -03:00
|
|
|
extern void initInsts();
|
2021-01-06 21:46:54 -03:00
|
|
|
extern void initFuncs();
|
|
|
|
|
2021-01-09 22:08:41 -03:00
|
|
|
|
2020-12-31 17:03:11 -03:00
|
|
|
typedef struct Setting {
|
|
|
|
|
2021-02-13 18:44:23 -03:00
|
|
|
Datum stack[NSTACK]; /* the stack */
|
|
|
|
Datum *stackp; /* next free spot on stack */
|
2020-12-31 17:03:11 -03:00
|
|
|
|
2021-02-13 18:44:23 -03:00
|
|
|
Inst prog[NPROG]; /* the machine */
|
|
|
|
Inst *progp; /* next free spot for code generation */
|
|
|
|
Inst *pc; /* program counter during execution */
|
2020-12-31 17:03:11 -03:00
|
|
|
|
|
|
|
} Setting;
|
|
|
|
|
2021-01-02 00:58:58 -03:00
|
|
|
// Settings
|
|
|
|
|
2020-12-31 17:03:11 -03:00
|
|
|
extern Setting *psetting;
|
|
|
|
|
2021-02-15 00:17:29 -03:00
|
|
|
typedef Common::HashMap<Common::String, Setting *> SettingMap;
|
2021-01-01 12:22:05 -03:00
|
|
|
typedef Common::Queue<Common::String> StringQueue;
|
2021-02-15 00:17:29 -03:00
|
|
|
typedef Common::Queue<Common::Rect *> RectQueue;
|
2021-01-07 23:10:19 -03:00
|
|
|
|
2021-01-02 00:58:58 -03:00
|
|
|
// Funtions
|
|
|
|
|
|
|
|
typedef Common::Array<Datum> ArgArray;
|
2021-01-09 22:08:41 -03:00
|
|
|
extern void call(char *, ArgArray);
|
2021-01-02 00:58:58 -03:00
|
|
|
|
|
|
|
// Code Generation
|
2020-12-31 17:03:11 -03:00
|
|
|
|
2021-02-13 18:44:23 -03:00
|
|
|
extern Datum pop();
|
2021-01-05 21:03:34 -03:00
|
|
|
extern int push(Datum);
|
2021-02-13 18:44:23 -03:00
|
|
|
extern Inst *progp;
|
2020-12-31 17:03:11 -03:00
|
|
|
|
2020-12-30 09:16:19 -03:00
|
|
|
extern Inst *code(Inst);
|
2021-02-13 18:44:23 -03:00
|
|
|
extern Inst *prog;
|
|
|
|
extern int eval();
|
2020-12-30 09:16:19 -03:00
|
|
|
extern int add();
|
2021-01-17 21:52:04 -03:00
|
|
|
extern int negate();
|
2020-12-30 09:16:19 -03:00
|
|
|
extern int power();
|
2021-02-13 18:44:23 -03:00
|
|
|
extern int assign();
|
2020-12-30 09:16:19 -03:00
|
|
|
extern int bltin();
|
2021-01-17 21:52:04 -03:00
|
|
|
extern int varpush();
|
2020-12-30 09:16:19 -03:00
|
|
|
extern int constpush();
|
2020-12-30 14:34:32 -03:00
|
|
|
extern int strpush();
|
2021-01-02 00:58:58 -03:00
|
|
|
extern int funcpush();
|
2020-12-30 09:16:19 -03:00
|
|
|
extern int print();
|
2021-01-03 12:19:10 -03:00
|
|
|
extern int ifcode();
|
|
|
|
extern int fail();
|
2020-12-30 21:26:15 -03:00
|
|
|
extern int lt();
|
|
|
|
extern int gt();
|
2021-01-04 08:14:40 -03:00
|
|
|
extern int le();
|
|
|
|
extern int ge();
|
2021-01-09 16:11:30 -03:00
|
|
|
extern int eq();
|
|
|
|
extern int ne();
|
2021-01-10 15:38:10 -03:00
|
|
|
extern 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-01-02 00:58:58 -03:00
|
|
|
extern void initSetting();
|
|
|
|
extern void saveSetting(char *);
|
|
|
|
extern void loadSetting(Common::String *);
|
2020-12-31 17:03:11 -03:00
|
|
|
|
2020-12-30 14:34:32 -03:00
|
|
|
extern void execute(Inst *);
|
2020-12-30 19:33:25 -03:00
|
|
|
|
2021-02-13 18:27:24 -03:00
|
|
|
} // End of namespace Private
|
2020-12-31 17:03:11 -03:00
|
|
|
|
|
|
|
#endif
|