scummvm/engines/private/grammar.h

131 lines
3.0 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.
*
*/
#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-01-10 20:44:27 -03:00
#include "private/symbol.h"
#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-10 20:44:27 -03:00
namespace Private {
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;
} 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;
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-02-13 18:44:23 -03:00
#define STOP (Inst) 0
2021-01-09 22:08:41 -03:00
typedef Common::HashMap<void *, Common::String *> PtrToName;
typedef Common::HashMap<Common::String, void *> NameToPtr;
2021-01-09 22:08:41 -03:00
extern void initInsts();
extern void initFuncs();
2021-01-09 22:08:41 -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 */
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 */
} Setting;
2021-01-02 00:58:58 -03:00
// Settings
extern Setting *psetting;
typedef Common::HashMap<Common::String, Setting *> SettingMap;
2021-01-01 12:22:05 -03:00
typedef Common::Queue<Common::String> StringQueue;
typedef Common::Queue<Common::Rect *> RectQueue;
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
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;
extern Inst *code(Inst);
2021-02-13 18:44:23 -03:00
extern Inst *prog;
extern int eval();
extern int add();
2021-01-17 21:52:04 -03:00
extern int negate();
extern int power();
2021-02-13 18:44:23 -03:00
extern int assign();
extern int bltin();
2021-01-17 21:52:04 -03:00
extern int varpush();
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();
extern int print();
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-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
#endif