scummvm/engines/private/grammar.h

133 lines
2.8 KiB
C
Raw Normal View History

#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"
#ifndef PRIVATE_GRAMMAR_H
#define PRIVATE_GRAMMAR_H
2021-01-01 12:22:05 -03:00
#define NSTACK 256
#define NPROG 10000
2021-01-01 12:22:05 -03:00
typedef struct Arg {
int n;
int (**inst)();
} Arg;
typedef struct Symbol { /* symbol table entry */
2021-01-01 12:22:05 -03:00
Common::String *name;
short type; /* NAME, NUM, STRING or RECT */
union {
int val; /* NAME or NUM */
char *str; /* STRING */
Common::Rect *rect; /* RECT */
} u;
} Symbol;
2021-01-05 21:03:34 -03:00
typedef struct Datum { /* interpreter stack type */
short type;
union {
int val;
char *str;
Symbol *sym;
Common::Rect *rect;
} u;
} Datum;
2020-12-30 19:33:25 -03:00
namespace Private {
typedef int (*Inst)(); /* machine instruction */
#define STOP (Inst) 0
typedef Common::HashMap<void *, Common::String *> FuncHash;
extern void initFuncs();
typedef struct Setting {
Datum stack[NSTACK]; /* the stack */
Datum *stackp; /* next free spot on stack */
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-01 12:22:05 -03:00
extern StringQueue todefine;
extern SettingMap settingcode;
// Symbols
extern void showSymbol(Symbol *);
2021-01-01 12:22:05 -03:00
typedef Common::HashMap<Common::String, Symbol*> SymbolMap;
typedef Common::List<Symbol*> ConstantList;
extern SymbolMap settings, variables, cursors, locations, rects;
extern ConstantList constants;
extern void define(char *, Common::Rect *);
extern Symbol *install(Common::String *, int, int, char *, Common::Rect *, SymbolMap*);
2021-01-02 00:58:58 -03:00
extern Symbol *lookupName(char *);
2021-01-01 12:22:05 -03:00
extern Symbol *addconstant(int, int, char *);
extern void installall(char *);
extern Symbol *lookup(Common::String, SymbolMap);
2021-01-02 00:58:58 -03:00
// Funtions
typedef Common::Array<Datum> ArgArray;
extern void execFunction(char *, ArgArray);
// Code Generation
extern Datum pop();
2021-01-05 21:03:34 -03:00
extern int push(Datum);
2021-01-04 08:14:40 -03:00
extern Inst *progp;
extern Inst *code(Inst);
extern Inst *prog;
extern int eval();
extern int add();
extern int negate();
extern int power();
extern int assign();
extern int bltin();
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();
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
}
#endif