diff options
author | Eugene Sandulenko | 2017-02-22 12:05:19 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2017-02-22 12:05:19 +0100 |
commit | 9dfb8ffd12742dcd29fdff15b6d9bc73ed333f85 (patch) | |
tree | d296b4dc5f6af5bb0913d941f66c145efa363368 | |
parent | 7db8908bc129fefa4b7d80792ec70d082b535824 (diff) | |
download | scummvm-rg350-9dfb8ffd12742dcd29fdff15b6d9bc73ed333f85.tar.gz scummvm-rg350-9dfb8ffd12742dcd29fdff15b6d9bc73ed333f85.tar.bz2 scummvm-rg350-9dfb8ffd12742dcd29fdff15b6d9bc73ed333f85.zip |
DIRECTOR: Lingo: Turned if() statement code into relative jumps
This will let us relocate code as we want, particularly when a
macro/handler is defined
-rw-r--r-- | engines/director/lingo/lingo-code.cpp | 6 | ||||
-rw-r--r-- | engines/director/lingo/lingo-codegen.cpp | 3 | ||||
-rw-r--r-- | engines/director/lingo/lingo-gr.cpp | 40 | ||||
-rw-r--r-- | engines/director/lingo/lingo-gr.y | 40 |
4 files changed, 46 insertions, 43 deletions
diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp index eeae0534d8..89650745ac 100644 --- a/engines/director/lingo/lingo-code.cpp +++ b/engines/director/lingo/lingo-code.cpp @@ -916,14 +916,14 @@ void Lingo::c_ifcode() { if (d.toInt()) { debugC(8, kDebugLingoExec, "executing then"); - g_lingo->execute(then); + g_lingo->execute(then + savepc - 1); } else if (elsep) { /* else part? */ debugC(8, kDebugLingoExec, "executing else"); - g_lingo->execute(elsep); + g_lingo->execute(elsep + savepc - 1); } if (!g_lingo->_returning && !skipEnd) { - g_lingo->_pc = end; /* next stmt */ + g_lingo->_pc = end + savepc - 1; /* next stmt */ debugC(8, kDebugLingoExec, "executing end"); } else { debugC(8, kDebugLingoExec, "Skipped end"); diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp index 0d771ec44e..8fa787bd33 100644 --- a/engines/director/lingo/lingo-codegen.cpp +++ b/engines/director/lingo/lingo-codegen.cpp @@ -380,6 +380,9 @@ void Lingo::processIf(int elselabel, int endlabel) { if (!label) break; + if (else1) + else1 = else1 - label; + WRITE_UINT32(&ielse1, else1); (*_currentScript)[label + 2] = ielse1; /* elsepart */ (*_currentScript)[label + 3] = iend; /* end, if cond fails */ diff --git a/engines/director/lingo/lingo-gr.cpp b/engines/director/lingo/lingo-gr.cpp index 8d1e84856b..d63a1363bd 100644 --- a/engines/director/lingo/lingo-gr.cpp +++ b/engines/director/lingo/lingo-gr.cpp @@ -2342,8 +2342,8 @@ yyreduce: #line 260 "engines/director/lingo/lingo-gr.y" { inst then = 0, end = 0; - WRITE_UINT32(&then, (yyvsp[(5) - (7)].code)); - WRITE_UINT32(&end, (yyvsp[(6) - (7)].code)); + WRITE_UINT32(&then, (yyvsp[(5) - (7)].code) - (yyvsp[(1) - (7)].code)); + WRITE_UINT32(&end, (yyvsp[(6) - (7)].code) - (yyvsp[(1) - (7)].code)); (*g_lingo->_currentScript)[(yyvsp[(1) - (7)].code) + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (7)].code) + 3] = end; /* end, if cond fails */ @@ -2356,9 +2356,9 @@ yyreduce: #line 270 "engines/director/lingo/lingo-gr.y" { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, (yyvsp[(5) - (10)].code)); - WRITE_UINT32(&else1, (yyvsp[(8) - (10)].code)); - WRITE_UINT32(&end, (yyvsp[(9) - (10)].code)); + WRITE_UINT32(&then, (yyvsp[(5) - (10)].code) - (yyvsp[(1) - (10)].code)); + WRITE_UINT32(&else1, (yyvsp[(8) - (10)].code) - (yyvsp[(1) - (10)].code)); + WRITE_UINT32(&end, (yyvsp[(9) - (10)].code) - (yyvsp[(1) - (10)].code)); (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 3] = end; /* end, if cond fails */ @@ -2372,25 +2372,25 @@ yyreduce: #line 282 "engines/director/lingo/lingo-gr.y" { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, (yyvsp[(5) - (10)].code)); - WRITE_UINT32(&else1, (yyvsp[(7) - (10)].code)); - WRITE_UINT32(&end, (yyvsp[(9) - (10)].code)); + WRITE_UINT32(&then, (yyvsp[(5) - (10)].code) - (yyvsp[(1) - (10)].code)); + WRITE_UINT32(&else1, (yyvsp[(7) - (10)].code) - (yyvsp[(1) - (10)].code)); + WRITE_UINT32(&end, (yyvsp[(9) - (10)].code) - (yyvsp[(1) - (10)].code)); (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 3] = end; /* end, if cond fails */ checkEnd((yyvsp[(10) - (10)].s), "if", true); - g_lingo->processIf(0, (yyvsp[(9) - (10)].code)); ;} + g_lingo->processIf(0, (yyvsp[(9) - (10)].code) - (yyvsp[(1) - (10)].code)); ;} break; case 33: #line 294 "engines/director/lingo/lingo-gr.y" { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, (yyvsp[(4) - (6)].code)); + WRITE_UINT32(&then, (yyvsp[(4) - (6)].code) - (yyvsp[(1) - (6)].code)); WRITE_UINT32(&else1, 0); - WRITE_UINT32(&end, (yyvsp[(6) - (6)].code)); + WRITE_UINT32(&end, (yyvsp[(6) - (6)].code) - (yyvsp[(1) - (6)].code)); (*g_lingo->_currentScript)[(yyvsp[(1) - (6)].code) + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (6)].code) + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (6)].code) + 3] = end; /* end, if cond fails */ @@ -2402,9 +2402,9 @@ yyreduce: #line 304 "engines/director/lingo/lingo-gr.y" { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, (yyvsp[(4) - (10)].code)); - WRITE_UINT32(&else1, (yyvsp[(8) - (10)].code)); - WRITE_UINT32(&end, (yyvsp[(10) - (10)].code)); + WRITE_UINT32(&then, (yyvsp[(4) - (10)].code) - (yyvsp[(1) - (10)].code)); + WRITE_UINT32(&else1, (yyvsp[(8) - (10)].code) - (yyvsp[(1) - (10)].code)); + WRITE_UINT32(&end, (yyvsp[(10) - (10)].code) - (yyvsp[(1) - (10)].code)); (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 3] = end; /* end, if cond fails */ @@ -2416,14 +2416,14 @@ yyreduce: #line 314 "engines/director/lingo/lingo-gr.y" { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, (yyvsp[(4) - (10)].code)); - WRITE_UINT32(&else1, (yyvsp[(6) - (10)].code)); - WRITE_UINT32(&end, (yyvsp[(10) - (10)].code)); + WRITE_UINT32(&then, (yyvsp[(4) - (10)].code) - (yyvsp[(1) - (10)].code)); + WRITE_UINT32(&else1, (yyvsp[(6) - (10)].code) - (yyvsp[(1) - (10)].code)); + WRITE_UINT32(&end, (yyvsp[(10) - (10)].code) - (yyvsp[(1) - (10)].code)); (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[(yyvsp[(1) - (10)].code) + 3] = end; /* end, if cond fails */ - g_lingo->processIf(0, (yyvsp[(10) - (10)].code)); ;} + g_lingo->processIf(0, (yyvsp[(10) - (10)].code) - (yyvsp[(1) - (10)].code)); ;} break; case 36: @@ -2440,7 +2440,7 @@ yyreduce: #line 338 "engines/director/lingo/lingo-gr.y" { inst then = 0; - WRITE_UINT32(&then, (yyvsp[(4) - (6)].code)); + WRITE_UINT32(&then, (yyvsp[(4) - (6)].code) - (yyvsp[(1) - (6)].code)); (*g_lingo->_currentScript)[(yyvsp[(1) - (6)].code) + 1] = then; /* thenpart */ g_lingo->codeLabel((yyvsp[(1) - (6)].code)); ;} @@ -2450,7 +2450,7 @@ yyreduce: #line 347 "engines/director/lingo/lingo-gr.y" { inst then = 0; - WRITE_UINT32(&then, (yyvsp[(5) - (6)].code)); + WRITE_UINT32(&then, (yyvsp[(5) - (6)].code) - (yyvsp[(1) - (6)].code)); (*g_lingo->_currentScript)[(yyvsp[(1) - (6)].code) + 1] = then; /* thenpart */ g_lingo->codeLabel((yyvsp[(1) - (6)].code)); ;} diff --git a/engines/director/lingo/lingo-gr.y b/engines/director/lingo/lingo-gr.y index 86f8743560..4fb2f4c01a 100644 --- a/engines/director/lingo/lingo-gr.y +++ b/engines/director/lingo/lingo-gr.y @@ -259,8 +259,8 @@ stmt: stmtoneliner ifstmt: if cond tTHEN nl stmtlist end ENDCLAUSE { inst then = 0, end = 0; - WRITE_UINT32(&then, $5); - WRITE_UINT32(&end, $6); + WRITE_UINT32(&then, $5 - $1); + WRITE_UINT32(&end, $6 - $1); (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */ @@ -269,9 +269,9 @@ ifstmt: if cond tTHEN nl stmtlist end ENDCLAUSE { g_lingo->processIf(0, 0); } | if cond tTHEN nl stmtlist end tNLELSE stmtlist end ENDCLAUSE { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, $5); - WRITE_UINT32(&else1, $8); - WRITE_UINT32(&end, $9); + WRITE_UINT32(&then, $5 - $1); + WRITE_UINT32(&else1, $8 - $1); + WRITE_UINT32(&end, $9 - $1); (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */ @@ -281,21 +281,21 @@ ifstmt: if cond tTHEN nl stmtlist end ENDCLAUSE { g_lingo->processIf(0, 0); } | if cond tTHEN nl stmtlist end begin elseifstmt end ENDCLAUSE { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, $5); - WRITE_UINT32(&else1, $7); - WRITE_UINT32(&end, $9); + WRITE_UINT32(&then, $5 - $1); + WRITE_UINT32(&else1, $7 - $1); + WRITE_UINT32(&end, $9 - $1); (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */ checkEnd($10, "if", true); - g_lingo->processIf(0, $9); } + g_lingo->processIf(0, $9 - $1); } | if cond tTHEN begin stmtoneliner end { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, $4); + WRITE_UINT32(&then, $4 - $1); WRITE_UINT32(&else1, 0); - WRITE_UINT32(&end, $6); + WRITE_UINT32(&end, $6 - $1); (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */ @@ -303,9 +303,9 @@ ifstmt: if cond tTHEN nl stmtlist end ENDCLAUSE { g_lingo->processIf(0, 0); } | if cond tTHEN begin stmtoneliner end tNLELSE begin stmtoneliner end { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, $4); - WRITE_UINT32(&else1, $8); - WRITE_UINT32(&end, $10); + WRITE_UINT32(&then, $4 - $1); + WRITE_UINT32(&else1, $8 - $1); + WRITE_UINT32(&end, $10 - $1); (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */ @@ -313,14 +313,14 @@ ifstmt: if cond tTHEN nl stmtlist end ENDCLAUSE { g_lingo->processIf(0, 0); } | if cond tTHEN begin stmtoneliner end elseifstmtoneliner end elsestmtoneliner end { inst then = 0, else1 = 0, end = 0; - WRITE_UINT32(&then, $4); - WRITE_UINT32(&else1, $6); - WRITE_UINT32(&end, $10); + WRITE_UINT32(&then, $4 - $1); + WRITE_UINT32(&else1, $6 - $1); + WRITE_UINT32(&end, $10 - $1); (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ (*g_lingo->_currentScript)[$1 + 2] = else1; /* elsepart */ (*g_lingo->_currentScript)[$1 + 3] = end; /* end, if cond fails */ - g_lingo->processIf(0, $10); } + g_lingo->processIf(0, $10 - $1); } ; elsestmtoneliner: /* nothing */ { $$ = 0; } @@ -337,7 +337,7 @@ elseifstmtoneliner: elseifstmtoneliner elseifstmtoneliner1 elseifstmtoneliner1: elseif cond tTHEN begin stmt end { inst then = 0; - WRITE_UINT32(&then, $4); + WRITE_UINT32(&then, $4 - $1); (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ g_lingo->codeLabel($1); } @@ -346,7 +346,7 @@ elseifstmtoneliner1: elseif cond tTHEN begin stmt end { elseifstmt1: elseifstmtoneliner | elseif cond tTHEN begin stmtlist end { inst then = 0; - WRITE_UINT32(&then, $5); + WRITE_UINT32(&then, $5 - $1); (*g_lingo->_currentScript)[$1 + 1] = then; /* thenpart */ g_lingo->codeLabel($1); } |