DIRECTOR: LINGO: Reimplement when

This commit is contained in:
djsrv 2021-06-19 03:30:08 -04:00 committed by D.J. Servilla
parent 3f1df58337
commit a5865079a1
5 changed files with 934 additions and 896 deletions

View File

@ -45,6 +45,7 @@ struct NextRepeatNode;
struct ExitRepeatNode;
struct ExitNode;
struct TellNode;
struct WhenNode;
struct AssertErrorNode;
struct IntNode;
struct FloatNode;
@ -94,6 +95,7 @@ enum NodeType {
kExitRepeatNode,
kExitNode,
kTellNode,
kWhenNode,
kAssertErrorNode,
kIntNode,
kFloatNode,
@ -137,6 +139,7 @@ public:
virtual void visitExitRepeatNode(ExitRepeatNode *node) = 0;
virtual void visitExitNode(ExitNode *node) = 0;
virtual void visitTellNode(TellNode *node) = 0;
virtual void visitWhenNode(WhenNode *node) = 0;
virtual void visitAssertErrorNode(AssertErrorNode *node) = 0;
virtual void visitIntNode(IntNode *node) = 0;
virtual void visitFloatNode(FloatNode *node) = 0;
@ -496,6 +499,23 @@ struct TellNode : StmtNode {
}
};
/* WhenNode */
struct WhenNode : StmtNode {
Common::String *event;
Node *code;
WhenNode(Common::String *eventIn, Node *codeIn)
: StmtNode(kWhenNode), event(eventIn), code(codeIn) {}
virtual ~WhenNode() {
delete event;
delete code;
}
virtual void accept(NodeVisitor *visitor) {
visitor->visitWhenNode(this);
}
};
/* AssertErrorNode */
struct AssertErrorNode : StmtNode {

View File

@ -732,6 +732,14 @@ void LingoCompiler::visitTellNode(TellNode *node) {
code1(LC::c_telldone);
}
/* WhenNode */
void LingoCompiler::visitWhenNode(WhenNode *node) {
compile(node->code);
code1(LC::c_whencode);
codeString(node->event->c_str());
}
/* AssertErrorNode */
void LingoCompiler::visitAssertErrorNode(AssertErrorNode *node) {

View File

@ -96,6 +96,7 @@ public:
virtual void visitExitRepeatNode(ExitRepeatNode *node);
virtual void visitExitNode(ExitNode *node);
virtual void visitTellNode(TellNode *node);
virtual void visitWhenNode(WhenNode *node);
virtual void visitAssertErrorNode(AssertErrorNode *node);
virtual void visitIntNode(IntNode *node);
virtual void visitFloatNode(FloatNode *node);

File diff suppressed because it is too large Load Diff

View File

@ -166,7 +166,7 @@ static void checkEnd(Common::String *token, Common::String *expect, bool require
// STATEMENT
%type<node> stmt stmtoneliner
%type<node> proc asgn definevars
%type<node> ifstmt ifelsestmt loop tell
%type<node> ifstmt ifelsestmt loop tell when
%type<nodelist> cmdargs frameargs stmtlist nonemptystmtlist
%type<node> stmtlistline
@ -331,7 +331,7 @@ ID: tVARID
| tTO { $$ = new Common::String("to"); }
| tASSERTERROR { $$ = new Common::String("scummvmAssertError"); }
| tSPRITE { $$ = new Common::String("sprite"); }
| tWHEN { $$ = new Common::String("when"); }
// | tWHEN { $$ = new Common::String("when"); }
| tWHILE { $$ = new Common::String("while"); }
| tWINDOW { $$ = new Common::String("window"); }
| tWITH { $$ = new Common::String("with"); }
@ -362,6 +362,7 @@ stmt: stmtoneliner
| ifelsestmt
| loop
| tell
| when
;
stmtoneliner: proc
@ -503,6 +504,8 @@ tell: tTELL expr tTO stmtoneliner {
$$ = new TellNode($expr, $stmtlist); }
;
when: tWHEN ID tTHEN expr { $$ = new WhenNode($ID, $expr); } ;
stmtlist: /* empty */ { $$ = new NodeList; }
| nonemptystmtlist
;