Skip to content

Commit

Permalink
DIRECTOR: Lingo: Implemented grammar for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 13, 2017
1 parent 72c676b commit 08cdd94
Show file tree
Hide file tree
Showing 8 changed files with 629 additions and 580 deletions.
16 changes: 16 additions & 0 deletions engines/director/lingo/lingo-code.cpp
Expand Up @@ -55,6 +55,7 @@ static struct FuncDescr {
} funcDescr[] = {
{ 0, "STOP", "" },
{ Lingo::c_xpop, "c_xpop", "" },
{ Lingo::c_arraypush, "c_arraypush", "i" },
{ Lingo::c_printtop, "c_printtop", "" },
{ Lingo::c_constpush, "c_constpush", "i" },
{ Lingo::c_voidpush, "c_voidpush", "" },
Expand Down Expand Up @@ -233,6 +234,21 @@ void Lingo::c_symbolpush() {
g_lingo->push(Datum(new Common::String(s)));
}

void Lingo::c_arraypush() {
Datum d;
inst v = (*g_lingo->_currentScript)[g_lingo->_pc++];
int arraySize = READ_UINT32(&v);

warning("STUB: c_arraypush()");

for (int i = 0; i < arraySize; i++)
g_lingo->pop();

d.u.i = arraySize;
d.type = INT;
g_lingo->push(d);
}

void Lingo::c_varpush() {
Common::String name((char *)&(*g_lingo->_currentScript)[g_lingo->_pc]);
Datum d;
Expand Down
9 changes: 9 additions & 0 deletions engines/director/lingo/lingo-codegen.cpp
Expand Up @@ -272,6 +272,15 @@ int Lingo::codeConst(int val) {
return res;
}

int Lingo::codeArray(int arraySize) {
int res = g_lingo->code1(g_lingo->c_arraypush);
inst i = 0;
WRITE_UINT32(&i, arraySize);
g_lingo->code1(i);

return res;
}

void Lingo::codeArg(Common::String *s) {
_argstack.push_back(s);
}
Expand Down
1,175 changes: 597 additions & 578 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 @@ -436,6 +436,7 @@ expr: INT { $$ = g_lingo->codeConst($1); }
| '+' expr %prec UNARY { $$ = $2; }
| '-' expr %prec UNARY { $$ = $2; g_lingo->code1(g_lingo->c_negate); }
| '(' expr ')' { $$ = $2; }
| '[' arglist ']' { $$ = g_lingo->codeArray($2); }
| tSPRITE expr tINTERSECTS expr { g_lingo->code1(g_lingo->c_intersects); }
| tSPRITE expr tWITHIN expr { g_lingo->code1(g_lingo->c_within); }
| tCHAR expr tOF expr { g_lingo->code1(g_lingo->c_charOf); }
Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo-lex.cpp
Expand Up @@ -415,7 +415,7 @@ static yyconst flex_int32_t yy_ec[256] =
15, 16, 1, 1, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 26,
1, 1, 1, 8, 41, 1, 42, 43, 44, 45,
8, 1, 8, 8, 41, 1, 42, 43, 44, 45,

46, 47, 48, 49, 50, 26, 26, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
Expand Down
2 changes: 1 addition & 1 deletion engines/director/lingo/lingo-lex.l
Expand Up @@ -65,7 +65,7 @@ identifier [_[:alpha:]][_[:alnum:]]*
constfloat [[:digit:]]+\.[[:digit:]]*
constinteger [[:digit:]]+
conststring \"[^\"\r\n]*\"
operator [-+*/%=^:,()><&]
operator [-+*/%=^:,()><&\[\]]
newline [ \t]*[\n\r]
whitespace [\t ]
Expand Down
2 changes: 2 additions & 0 deletions engines/director/lingo/lingo.h
Expand Up @@ -211,6 +211,7 @@ class Lingo {
int codeString(const char *s);
void codeLabel(int label);
int codeConst(int val);
int codeArray(int arraySize);

int calcStringAlignment(const char *s) {
return calcCodeAlignment(strlen(s) + 1);
Expand Down Expand Up @@ -267,6 +268,7 @@ class Lingo {
static void c_stringpush();
static void c_symbolpush();
static void c_varpush();
static void c_arraypush();
static void c_assign();
bool verify(Symbol *s);
static void c_eval();
Expand Down
2 changes: 2 additions & 0 deletions engines/director/lingo/tests/arrays.lingo
@@ -0,0 +1,2 @@
set a to [1, 2, 3]
put a

0 comments on commit 08cdd94

Please sign in to comment.