Skip to content

Commit

Permalink
DIRECTOR: Lingo: Implemented '&' string operator
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent 598be95 commit cca7137
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 271 deletions.
2 changes: 2 additions & 0 deletions engines/director/director.cpp
Expand Up @@ -128,7 +128,9 @@ Common::Error DirectorEngine::run() {
else put 5\n\
end repeat\n\
set z = \"foo bar baz\"\n\
set z1 = z & \" meow\"\n\
put z\n\
put z1\n\
", kMovieScript, 2);

_lingo->executeScript(kMovieScript, 2);
Expand Down
31 changes: 28 additions & 3 deletions engines/director/lingo/lingo-code.cpp
Expand Up @@ -160,15 +160,25 @@ void Lingo::c_assign() {
return;
}

if (d1.u.sym->type != INT && d1.u.sym->type != VOID) {
if (d1.u.sym->type != INT && d1.u.sym->type != VOID &&
d1.u.sym->type != FLOAT && d1.u.sym->type != STRING) {
warning("assignment to non-variable '%s'", d1.u.sym->name);
return;
}

d1.u.sym->u.val = d2.u.i;
if (d1.u.sym->type == STRING) // Free memory if needed
delete d1.u.sym->u.str;

if (d2.type == INT)
d1.u.sym->u.val = d2.u.i;
else if (d2.type == FLOAT)
d1.u.sym->u.fval = d2.u.f;
else if (d2.type == STRING)
d1.u.sym->u.str = new Common::String(*d2.u.s);

d1.u.sym->type = d2.type;

g_lingo->push(d2);
g_lingo->push(d1);
}

bool Lingo::verify(Symbol *s) {
Expand Down Expand Up @@ -266,6 +276,21 @@ void Lingo::c_negate() {
g_lingo->push(d);
}

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

if (d1.type != STRING || d2.type != STRING) {
error("Wrong operands for & operation: %d %d", d1.type, d2.type);
}

*d1.u.s += *d2.u.s;

delete d2.u.s;

g_lingo->push(d1);
}

void Lingo::c_eq() {
Datum d2 = g_lingo->pop();
Datum d1 = g_lingo->pop();
Expand Down
547 changes: 285 additions & 262 deletions engines/director/lingo/lingo-gr.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions engines/director/lingo/lingo-gr.y
Expand Up @@ -334,6 +334,7 @@ expr: INT {
| expr tNEQ expr { g_lingo->code1(g_lingo->c_neq); }
| expr tGE expr { g_lingo->code1(g_lingo->c_ge); }
| expr tLE expr { g_lingo->code1(g_lingo->c_le); }
| expr '&' expr { g_lingo->code1(g_lingo->c_ampersand); }
| '+' expr %prec UNARY { $$ = $2; }
| '-' expr %prec UNARY { $$ = $2; g_lingo->code1(g_lingo->c_negate); }
| '(' expr ')' { $$ = $2; }
Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo-lex.cpp
Expand Up @@ -397,7 +397,7 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 4, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 5, 6, 7, 1, 1, 8, 1, 1, 8,
1, 5, 6, 7, 1, 1, 8, 8, 1, 8,
8, 8, 8, 8, 9, 10, 8, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 8, 1, 12,
13, 14, 1, 1, 15, 16, 17, 18, 19, 20,
Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo-lex.l
Expand Up @@ -51,7 +51,7 @@ identifier [_[:alpha:]][_[:alnum:]]*
constfloat [[:digit:]]+\.[[:digit:]]*
constinteger [[:digit:]]+
conststring \"[^\"\n]*\"
operator [-+*/%=^:,()><]
operator [-+*/%=^:,()><&]
newline [ \t]*[\n\r]+
whitespace [\t ]
Expand Down
11 changes: 7 additions & 4 deletions engines/director/lingo/lingo.h
Expand Up @@ -81,10 +81,10 @@ struct Symbol { /* symbol table entry */
char *name;
int type;
union {
int val; /* VAR */
float fval; /* FLOAT */
ScriptData *defn; /* FUNCTION, PROCEDURE */
char *str; /* STRING */
int val; /* VAR */
float fval; /* FLOAT */
ScriptData *defn; /* FUNCTION, PROCEDURE */
Common::String *str; /* STRING */
} u;
int nargs;
bool global;
Expand Down Expand Up @@ -172,11 +172,14 @@ class Lingo {

static void c_xpop();
static void c_printtop();

static void c_add();
static void c_sub();
static void c_mul();
static void c_div();
static void c_negate();
static void c_ampersand();

static void c_constpush();
static void c_fconstpush();
static void c_stringpush();
Expand Down

0 comments on commit cca7137

Please sign in to comment.