ScummVM API documentation
grammar.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef PRIVATE_GRAMMAR_H
23#define PRIVATE_GRAMMAR_H
24
25#include "common/str.h"
26#include "common/hash-str.h"
27#include "common/hash-ptr.h"
28#include "common/queue.h"
29#include "common/list.h"
30#include "common/array.h"
31#include "common/rect.h"
32
33#include "private/symbol.h"
34
35#define NSTACK 256
36#define NPROG 10000
37
38namespace Private {
39
40typedef struct Datum { /* interpreter stack type */
41 short type;
42 union {
43 int val;
44 const char *str;
45 Symbol *sym;
46 Common::Rect *rect;
47 } u;
48} Datum;
49
50typedef struct Arg {
51 int n;
52 int (** inst)();
53} Arg;
54
55typedef int (* Inst)(); /* machine instruction */
56#define STOP (Inst) 0
57
59
60void initInsts();
61void initFuncs();
62
63namespace Settings {
64
65typedef struct Setting {
66 Datum stack[NSTACK]; /* the stack */
67 Inst prog[NPROG]; /* the machine */
68} Setting;
69
71
73public:
76
77 Setting *_setting;
78 SettingMap _map;
79
80 void init();
81 void save(const char *);
82 void load(const Common::String &);
83
84private:
86};
87
88extern SettingMaps *g_setts;
89
90}
91
92// Funtions
93
95void call(const char *, const ArgArray &);
96
97// Code Generation and Execution
98
99namespace Gen {
100
101class VM {
102public:
103 Datum *_stack; /* the stack */
104 Datum *_stackp; /* next free spot on stack */
105
106 Inst *_progp; /* next free spot for code generation */
107 Inst *_prog; /* the machine */
108 Inst *_pc; /* program counter during execution */
109 void run(); /* run the virtual machine */
110};
111
112extern VM *g_vm;
113
114Datum pop();
115int push(const Datum &);
116
117Inst *code(const Inst &);
118int eval();
119int add();
120int negate();
121int power();
122int assign();
123int bltin();
124int varpush();
125int constpush();
126int strpush();
127int funcpush();
128int print();
129int ifcode();
130int fail();
131int lt();
132int gt();
133int le();
134int ge();
135int eq();
136int ne();
137int randbool();
138
139// Code Execution
140
141void execute(Inst *);
142
143}
144
145} // End of namespace Private
146
147#endif
Definition: array.h:52
Definition: hashmap.h:85
Definition: str.h:59
Definition: grammar.h:101
Definition: grammar.h:72
Definition: rect.h:536
Definition: grammar.h:50
Definition: grammar.h:40
Definition: grammar.h:65
Definition: symbol.h:35