Skip to content

Commit

Permalink
DIRECTOR: Lingo: Implement logical operators
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent a7ec15f commit db23800
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 251 deletions.
49 changes: 49 additions & 0 deletions engines/director/lingo/lingo-funcs.cpp
Expand Up @@ -341,6 +341,55 @@ void Lingo::func_negate() {
g_lingo->push(d);
}

void Lingo::func_eq() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();

d1.val = (d1.val == d2.val) ? 1 : 0;
g_lingo->push(d1);
}

void Lingo::func_neq() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();

d1.val = (d1.val != d2.val) ? 1 : 0;
g_lingo->push(d1);
}

void Lingo::func_gt() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();

d1.val = (d1.val > d2.val) ? 1 : 0;
g_lingo->push(d1);
}

void Lingo::func_lt() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();

d1.val = (d1.val < d2.val) ? 1 : 0;
g_lingo->push(d1);
}

void Lingo::func_ge() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();

d1.val = (d1.val >= d2.val) ? 1 : 0;
g_lingo->push(d1);
}

void Lingo::func_le() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();

d1.val = (d1.val <= d2.val) ? 1 : 0;
g_lingo->push(d1);
}


void Lingo::func_ifcode() {
Datum d;
int savepc = g_lingo->_pc; /* then part */
Expand Down
375 changes: 222 additions & 153 deletions engines/director/lingo/lingo-gr.cpp

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions engines/director/lingo/lingo-gr.h
Expand Up @@ -60,7 +60,13 @@
tPUT = 276,
tSET = 277,
tTHEN = 278,
tTO = 279
tTO = 279,
tGE = 280,
tLE = 281,
tGT = 282,
tLT = 283,
tEQ = 284,
tNEQ = 285
};
#endif
/* Tokens. */
Expand All @@ -86,6 +92,12 @@
#define tSET 277
#define tTHEN 278
#define tTO 279
#define tGE 280
#define tLE 281
#define tGT 282
#define tLT 283
#define tEQ 284
#define tNEQ 285



Expand All @@ -100,7 +112,7 @@ typedef union YYSTYPE
int code;
}
/* Line 1529 of yacc.c. */
#line 104 "engines/director/lingo/lingo-gr.hpp"
#line 116 "engines/director/lingo/lingo-gr.hpp"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
Expand Down
9 changes: 8 additions & 1 deletion engines/director/lingo/lingo-gr.y
Expand Up @@ -75,6 +75,7 @@ using namespace Director;
%token<s> VAR STRING
%token tIF tEND tFRAME tGO tINTO tLOOP tMCI tMCIWAIT tMOVIE tNEXT tOF tPREVIOUS
%token tPUT tSET tTHEN tTO
%token tGE tLE tGT tLT tEQ tNEQ

%type<code> assign cond expr if end stmtlist
%type<s> gotoframe gotomovie
Expand Down Expand Up @@ -119,12 +120,18 @@ expr: INT { g_lingo->code1(g_lingo->func_constpush); inst i; WRITE_LE_UINT3
| expr '-' expr { g_lingo->code1(g_lingo->func_sub); }
| expr '*' expr { g_lingo->code1(g_lingo->func_mul); }
| expr '/' expr { g_lingo->code1(g_lingo->func_div); }
| expr '>' expr { g_lingo->code1(g_lingo->func_gt); }
| expr '<' expr { g_lingo->code1(g_lingo->func_lt); }
| expr tNEQ expr { g_lingo->code1(g_lingo->func_neq); }
| expr tGE expr { g_lingo->code1(g_lingo->func_ge); }
| expr tLE expr { g_lingo->code1(g_lingo->func_le); }
| '+' expr %prec UNARY { $$ = $2; }
| '-' expr %prec UNARY { $$ = $2; g_lingo->code1(g_lingo->func_negate); }
| '(' expr ')' { $$ = $2; }
;

cond: expr { g_lingo->code1(STOP); }
cond: expr { g_lingo->code1(STOP); }
| expr '=' expr { g_lingo->code2(g_lingo->func_eq, STOP); }
;
if: tIF { $$ = g_lingo->code1(g_lingo->func_ifcode); g_lingo->code3(STOP,STOP,STOP); }
;
Expand Down

0 comments on commit db23800

Please sign in to comment.