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"
|
2020-12-31 17:03:11 -03:00
|
|
|
|
|
|
|
#ifndef PRIVATE_GRAMMAR_H
|
|
|
|
#define PRIVATE_GRAMMAR_H
|
|
|
|
|
2021-01-01 12:22:05 -03:00
|
|
|
#define NSTACK 256
|
2021-01-03 12:19:10 -03:00
|
|
|
#define NPROG 10000
|
2021-01-01 12:22:05 -03:00
|
|
|
|
2021-01-06 21:46:54 -03:00
|
|
|
typedef struct Arg {
|
|
|
|
int n;
|
|
|
|
int (**inst)();
|
|
|
|
} Arg;
|
|
|
|
|
2020-12-30 09:16:19 -03:00
|
|
|
typedef struct Symbol { /* symbol table entry */
|
2021-01-01 12:22:05 -03:00
|
|
|
Common::String *name;
|
2021-01-07 23:10:19 -03:00
|
|
|
short type; /* NAME, NUM, STRING or RECT */
|
2020-12-30 09:16:19 -03:00
|
|
|
union {
|
2021-01-07 23:10:19 -03:00
|
|
|
int val; /* NAME or NUM */
|
|
|
|
char *str; /* STRING */
|
|
|
|
Common::Rect *rect; /* RECT */
|
2020-12-30 09:16:19 -03:00
|
|
|
} 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;
|
2020-12-30 09:16:19 -03:00
|
|
|
} Datum;
|
2020-12-30 19:33:25 -03:00
|
|
|
|
|
|
|
namespace Private {
|
|
|
|
|
2020-12-30 09:16:19 -03:00
|
|
|
typedef int (*Inst)(); /* machine instruction */
|
|
|
|
#define STOP (Inst) 0
|
|
|
|
|
2021-01-06 21:46:54 -03:00
|
|
|
typedef Common::HashMap<void *, Common::String *> FuncHash;
|
|
|
|
|
|
|
|
extern void initFuncs();
|
|
|
|
|
2020-12-31 17:03:11 -03:00
|
|
|
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
|
|
|
|
|
2020-12-31 17:03:11 -03:00
|
|
|
extern Setting *psetting;
|
|
|
|
|
|
|
|
typedef Common::HashMap<Common::String, Setting*> SettingMap;
|
2021-01-01 12:22:05 -03:00
|
|
|
typedef Common::Queue<Common::String> StringQueue;
|
2021-01-07 23:10:19 -03:00
|
|
|
typedef Common::Queue<Common::Rect*> RectQueue;
|
|
|
|
|
2021-01-01 12:22:05 -03:00
|
|
|
|
|
|
|
extern StringQueue todefine;
|
|
|
|
extern SettingMap settingcode;
|
|
|
|
|
|
|
|
// Symbols
|
|
|
|
|
2021-01-06 21:46:54 -03:00
|
|
|
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;
|
2020-12-31 17:03:11 -03:00
|
|
|
|
2021-01-07 23:10:19 -03:00
|
|
|
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);
|
2020-12-31 17:03:11 -03:00
|
|
|
|
2021-01-02 00:58:58 -03:00
|
|
|
// Funtions
|
|
|
|
|
|
|
|
typedef Common::Array<Datum> ArgArray;
|
|
|
|
extern void execFunction(char *, ArgArray);
|
|
|
|
|
|
|
|
// Code Generation
|
2020-12-31 17:03:11 -03:00
|
|
|
|
|
|
|
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;
|
2020-12-31 17:03:11 -03:00
|
|
|
|
2020-12-30 09:16:19 -03:00
|
|
|
extern Inst *code(Inst);
|
2020-12-30 20:57:05 -03:00
|
|
|
extern Inst *prog;
|
2020-12-30 09:16:19 -03:00
|
|
|
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();
|
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();
|
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
|
|
|
|
|
|
|
}
|
2020-12-31 17:03:11 -03:00
|
|
|
|
|
|
|
#endif
|