PRIVATE: clean up and reorganization
This commit is contained in:
parent
756efded43
commit
211c767685
9 changed files with 1682 additions and 1764 deletions
|
@ -8,8 +8,8 @@
|
|||
|
||||
namespace Private {
|
||||
|
||||
Setting *psetting;
|
||||
SettingMap settingcode;
|
||||
Setting *setting;
|
||||
SettingMap settingMap;
|
||||
|
||||
Datum *stack = NULL; /* the stack */
|
||||
Datum *stackp = NULL; /* next free spot on stack */
|
||||
|
@ -47,11 +47,11 @@ void initInsts() {
|
|||
|
||||
void initSetting() /* initialize for code generation */
|
||||
{
|
||||
psetting = (Setting*) malloc(sizeof(Setting));
|
||||
memset((void *) psetting, 0, sizeof(Setting));
|
||||
setting = (Setting*) malloc(sizeof(Setting));
|
||||
memset((void *) setting, 0, sizeof(Setting));
|
||||
|
||||
prog = (Inst *) &psetting->prog;
|
||||
stack = (Datum *) &psetting->stack;
|
||||
prog = (Inst *) &setting->prog;
|
||||
stack = (Datum *) &setting->stack;
|
||||
|
||||
stackp = stack;
|
||||
progp = prog;
|
||||
|
@ -60,19 +60,19 @@ void initSetting() /* initialize for code generation */
|
|||
void saveSetting(char *name)
|
||||
{
|
||||
Common::String s(name);
|
||||
settingcode.setVal(s, psetting);
|
||||
settingMap.setVal(s, setting);
|
||||
//debug("setting %s", name);
|
||||
}
|
||||
|
||||
void loadSetting(Common::String *name)
|
||||
{
|
||||
assert(settingcode.contains(*name));
|
||||
psetting = settingcode.getVal(*name);
|
||||
assert(settingMap.contains(*name));
|
||||
setting = settingMap.getVal(*name);
|
||||
|
||||
debug("loading setting %s", name->c_str());
|
||||
|
||||
prog = (Inst *) &psetting->prog;
|
||||
stack = (Datum *) &psetting->stack;
|
||||
prog = (Inst *) &setting->prog;
|
||||
stack = (Datum *) &setting->stack;
|
||||
|
||||
stackp = stack;
|
||||
progp = prog;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "common/list.h"
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
#include "private/symbol.h"
|
||||
|
||||
#ifndef PRIVATE_GRAMMAR_H
|
||||
#define PRIVATE_GRAMMAR_H
|
||||
|
@ -12,20 +13,8 @@
|
|||
#define NSTACK 256
|
||||
#define NPROG 10000
|
||||
|
||||
typedef struct Arg {
|
||||
int n;
|
||||
int (**inst)();
|
||||
} Arg;
|
||||
|
||||
typedef struct Symbol { /* symbol table entry */
|
||||
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;
|
||||
namespace Private {
|
||||
|
||||
typedef struct Datum { /* interpreter stack type */
|
||||
short type;
|
||||
|
@ -37,7 +26,11 @@ typedef struct Datum { /* interpreter stack type */
|
|||
} u;
|
||||
} Datum;
|
||||
|
||||
namespace Private {
|
||||
|
||||
typedef struct Arg {
|
||||
int n;
|
||||
int (**inst)();
|
||||
} Arg;
|
||||
|
||||
typedef int (*Inst)(); /* machine instruction */
|
||||
#define STOP (Inst) 0
|
||||
|
@ -68,28 +61,6 @@ typedef Common::HashMap<Common::String, Setting*> SettingMap;
|
|||
typedef Common::Queue<Common::String> StringQueue;
|
||||
typedef Common::Queue<Common::Rect*> RectQueue;
|
||||
|
||||
|
||||
extern StringQueue todefine;
|
||||
extern SettingMap settingcode;
|
||||
|
||||
// Symbols
|
||||
|
||||
extern void showSymbol(Symbol *);
|
||||
extern void setSymbol(Symbol *, int);
|
||||
|
||||
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*);
|
||||
extern Symbol *lookupName(char *);
|
||||
extern Symbol *addconstant(int, int, char *);
|
||||
extern void installall(char *);
|
||||
extern Symbol *lookup(Common::String, SymbolMap);
|
||||
|
||||
// Funtions
|
||||
|
||||
typedef Common::Array<Datum> ArgArray;
|
||||
|
|
|
@ -32,8 +32,8 @@ TRUE return TRUETOK;
|
|||
NULL return NULLTOK;
|
||||
Random return RANDOMTOK;
|
||||
[A-Za-z_][A-Za-z_0-9]* yylval.s = strdup(yytext); return NAME;
|
||||
[\-]?[0-9]+ yylval.sym = Private::addconstant(NUM, atoi(yytext), NULL); return NUM;
|
||||
\"[^\"\r\n]*\" yylval.sym = Private::addconstant(STRING, 0, strdup(yytext)); return STRING;
|
||||
[\-]?[0-9]+ yylval.sym = Private::constant(NUM, atoi(yytext), NULL); return NUM;
|
||||
\"[^\"\r\n]*\" yylval.sym = Private::constant(STRING, 0, strdup(yytext)); return STRING;
|
||||
[\r|\n]+ /* ignore return */;
|
||||
[ \t]+ /* ignore whitespace */;
|
||||
. return *yytext;
|
||||
|
@ -46,21 +46,15 @@ namespace Private {
|
|||
int parse(char *code) {
|
||||
|
||||
initSetting();
|
||||
//_lines[0] = _lines[1] = _lines[2] = code;
|
||||
|
||||
YY_BUFFER_STATE bp;
|
||||
|
||||
//if (debugChannelSet(-1, kDebugParse))
|
||||
yydebug = 1;
|
||||
//else
|
||||
// yydebug = 0;
|
||||
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
|
||||
bp = yy_scan_string(code);
|
||||
yy_switch_to_buffer(bp);
|
||||
yyparse();
|
||||
//execute(prog);
|
||||
yy_delete_buffer(bp);
|
||||
|
||||
return 0;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -82,7 +82,7 @@ union YYSTYPE
|
|||
{
|
||||
#line 38 "engines/private/grammar.y"
|
||||
|
||||
struct Symbol *sym; /* symbol table pointer */
|
||||
Private::Symbol *sym; /* symbol table pointer */
|
||||
int (**inst)(); /* machine instruction */
|
||||
char *s;
|
||||
int *i;
|
||||
|
|
|
@ -36,7 +36,7 @@ int yywrap()
|
|||
%}
|
||||
|
||||
%union {
|
||||
struct Symbol *sym; /* symbol table pointer */
|
||||
Private::Symbol *sym; /* symbol table pointer */
|
||||
int (**inst)(); /* machine instruction */
|
||||
char *s;
|
||||
int *i;
|
||||
|
@ -56,7 +56,7 @@ lines: line lines
|
|||
;
|
||||
|
||||
line: DEBUGTOK '{' debug '}' { /* Not used in the game */ }
|
||||
| DEFINETOK NAME '{' define '}' { installall($NAME); }
|
||||
| DEFINETOK NAME '{' define '}' { installAll($NAME); }
|
||||
| SETTINGTOK NAME '{' statements '}' { saveSetting($NAME); initSetting(); }
|
||||
;
|
||||
|
||||
|
@ -69,9 +69,9 @@ statements: /* nothing */ { $$ = progp; }
|
|||
|
||||
|
||||
statement: GOTOTOK NAME ';' {
|
||||
code2(strpush, (Private::Inst) Private::addconstant(STRING, 0, $NAME));
|
||||
code2(constpush, (Private::Inst) Private::addconstant(NUM, 1, NULL));
|
||||
code2(strpush, (Private::Inst) Private::addconstant(STRING, 0, "goto"));
|
||||
code2(strpush, (Private::Inst) Private::constant(STRING, 0, $NAME));
|
||||
code2(constpush, (Private::Inst) Private::constant(NUM, 1, NULL));
|
||||
code2(strpush, (Private::Inst) Private::constant(STRING, 0, "goto"));
|
||||
code1(funcpush);
|
||||
}
|
||||
| fcall ';' { }
|
||||
|
@ -105,29 +105,29 @@ define: /* nothing */
|
|||
| NAME ',' RECT '(' NUM ',' NUM ',' NUM ',' NUM ')' ',' define {
|
||||
Common::Rect *r = new Common::Rect($5->u.val, $7->u.val, $9->u.val, $11->u.val);
|
||||
assert(r->isValidRect());
|
||||
define($NAME, r);
|
||||
defineSymbol($NAME, r);
|
||||
}
|
||||
| NAME ',' RECT '(' NUM ',' NUM ',' NUM ',' NUM ')' {
|
||||
Common::Rect *r = new Common::Rect($5->u.val, $7->u.val, $9->u.val, $11->u.val);
|
||||
define($NAME, r);
|
||||
defineSymbol($NAME, r);
|
||||
}
|
||||
| NAME ',' define { define($NAME, NULL); }
|
||||
| NAME { define($NAME, NULL); }
|
||||
| NAME ',' define { defineSymbol($NAME, NULL); }
|
||||
| NAME { defineSymbol($NAME, NULL); }
|
||||
;
|
||||
|
||||
fcall: GOTOTOK '(' NAME ')' {
|
||||
$$ = progp;
|
||||
code2(strpush, (Private::Inst) Private::addconstant(STRING, 0, $NAME));
|
||||
code2(constpush, (Private::Inst) Private::addconstant(NUM, 1, NULL));
|
||||
code2(strpush, (Private::Inst) Private::addconstant(STRING, 0, "goto"));
|
||||
code2(strpush, (Private::Inst) Private::constant(STRING, 0, $NAME));
|
||||
code2(constpush, (Private::Inst) Private::constant(NUM, 1, NULL));
|
||||
code2(strpush, (Private::Inst) Private::constant(STRING, 0, "goto"));
|
||||
code1(funcpush);
|
||||
}
|
||||
|
||||
| RECT '(' NUM ',' NUM ',' NUM ',' NUM ')' { $$ = progp; }
|
||||
| NAME '(' startp params ')' {
|
||||
$$ = $startp;
|
||||
code2(constpush, (Private::Inst) addconstant(NUM, $params, NULL));
|
||||
code2(strpush, (Private::Inst) addconstant(STRING, 0, $NAME));
|
||||
code2(constpush, (Private::Inst) constant(NUM, $params, NULL));
|
||||
code2(strpush, (Private::Inst) constant(STRING, 0, $NAME));
|
||||
code1(funcpush);
|
||||
}
|
||||
;
|
||||
|
@ -142,9 +142,9 @@ params: /* nothing */ { $$ = 0; }
|
|||
| fcall { $$ = 1; }
|
||||
;
|
||||
|
||||
value: NULLTOK { code2(Private::constpush, (Private::Inst) Private::addconstant(NUM, 0, NULL)); }
|
||||
| FALSETOK { code2(Private::constpush, (Private::Inst) Private::addconstant(NUM, 0, NULL)); }
|
||||
| TRUETOK { code2(Private::constpush, (Private::Inst) Private::addconstant(NUM, 1, NULL)); }
|
||||
value: NULLTOK { code2(Private::constpush, (Private::Inst) Private::constant(NUM, 0, NULL)); }
|
||||
| FALSETOK { code2(Private::constpush, (Private::Inst) Private::constant(NUM, 0, NULL)); }
|
||||
| TRUETOK { code2(Private::constpush, (Private::Inst) Private::constant(NUM, 1, NULL)); }
|
||||
| NUM { code2(Private::constpush, (Private::Inst)$NUM); }
|
||||
| STRING { code2(Private::strpush, (Private::Inst)$STRING); }
|
||||
| NAME { code1(Private::varpush); code1((Private::Inst) lookupName($NAME)); code1(Private::eval); }
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,14 +9,13 @@ ConstantList constants;
|
|||
StringQueue stringToDefine;
|
||||
RectQueue rectToDefine;
|
||||
|
||||
void define(char *n, Common::Rect *r) {
|
||||
void defineSymbol(char *n, Common::Rect *r) {
|
||||
Common::String *s = new Common::String(n);
|
||||
stringToDefine.push(*s);
|
||||
rectToDefine.push(r);
|
||||
}
|
||||
|
||||
char *emalloc(unsigned n) /* check return from malloc */
|
||||
{
|
||||
char *emalloc(unsigned n) {
|
||||
char *p;
|
||||
|
||||
p = (char*) malloc(n);
|
||||
|
@ -24,8 +23,7 @@ char *emalloc(unsigned n) /* check return from malloc */
|
|||
return p;
|
||||
}
|
||||
|
||||
void showSymbol(Symbol *s)
|
||||
{
|
||||
void showSymbol(Symbol *s) {
|
||||
if (s->type == NUM)
|
||||
debug("%s %d",s->name->c_str(), s->u.val);
|
||||
else if (s->type == STRING)
|
||||
|
@ -41,8 +39,8 @@ void setSymbol(Symbol *s, int v) {
|
|||
s->u.val = v;
|
||||
}
|
||||
|
||||
Symbol *lookup(Common::String s, SymbolMap symlist) /* find s in symbol table symlist */
|
||||
{
|
||||
/* find s in symbol table symlist */
|
||||
Symbol *lookup(Common::String s, SymbolMap symlist) {
|
||||
//debug("looking up %s", s.c_str());
|
||||
Symbol *r = symlist.getVal(s);
|
||||
/*if (strcmp(s.c_str(), "m_640x480") == 0) {
|
||||
|
@ -53,8 +51,8 @@ Symbol *lookup(Common::String s, SymbolMap symlist) /* find s in symbol table sy
|
|||
return r;
|
||||
}
|
||||
|
||||
Symbol *lookupName(char *n) /* install s in some symbol table */
|
||||
{
|
||||
/* lookup some name in some symbol table */
|
||||
Symbol *lookupName(char *n) {
|
||||
//debug("looking up %s", n);
|
||||
Common::String *s = new Common::String(n);
|
||||
|
||||
|
@ -75,15 +73,13 @@ Symbol *lookupName(char *n) /* install s in some symbol table */
|
|||
|
||||
else {
|
||||
debug("WARNING: %s not defined", n);
|
||||
return addconstant(NAME, 0, n);
|
||||
return constant(NAME, 0, n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void installall(char *n) {
|
||||
void installAll(char *n) {
|
||||
Common::String *s;
|
||||
Common::Rect *r;
|
||||
|
||||
|
@ -125,8 +121,7 @@ void installall(char *n) {
|
|||
|
||||
}
|
||||
|
||||
Symbol *addconstant(int t, int d, char *s)
|
||||
{
|
||||
Symbol *constant(int t, int d, char *s) {
|
||||
Symbol *sp;
|
||||
Common::String *n = new Common::String("<constant>");
|
||||
|
||||
|
@ -144,9 +139,8 @@ Symbol *addconstant(int t, int d, char *s)
|
|||
return sp;
|
||||
}
|
||||
|
||||
|
||||
Symbol *install(Common::String *n, int t, int d, char *s, Common::Rect *r, SymbolMap *symlist) /* install s in symbol table */
|
||||
{
|
||||
/* install some symbol s in a symbol table */
|
||||
Symbol *install(Common::String *n, int t, int d, char *s, Common::Rect *r, SymbolMap *symlist) {
|
||||
Common::String *name = new Common::String(*n);
|
||||
|
||||
Symbol *sp;
|
||||
|
|
44
engines/private/symbol.h
Normal file
44
engines/private/symbol.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "common/str.h"
|
||||
#include "common/hash-str.h"
|
||||
#include "common/hash-ptr.h"
|
||||
#include "common/queue.h"
|
||||
#include "common/list.h"
|
||||
#include "common/array.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
#ifndef PRIVATE_SYMBOL_H
|
||||
#define PRIVATE_SYMBOL_H
|
||||
|
||||
namespace Private {
|
||||
|
||||
typedef struct Symbol { /* symbol table entry */
|
||||
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;
|
||||
|
||||
// Symbols
|
||||
|
||||
extern void showSymbol(Symbol *);
|
||||
extern void setSymbol(Symbol *, int);
|
||||
|
||||
typedef Common::HashMap<Common::String, Symbol*> SymbolMap;
|
||||
typedef Common::List<Symbol*> ConstantList;
|
||||
|
||||
extern SymbolMap settings, variables, cursors, locations, rects;
|
||||
extern ConstantList constants;
|
||||
|
||||
extern void defineSymbol(char *, Common::Rect *);
|
||||
extern Symbol *install(Common::String *, int, int, char *, Common::Rect *, SymbolMap*);
|
||||
extern Symbol *lookupName(char *);
|
||||
extern Symbol *constant(int, int, char *);
|
||||
extern void installAll(char *);
|
||||
extern Symbol *lookup(Common::String, SymbolMap);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue