[Scummvm-git-logs] scummvm master -> bb61cca4512b4cc7f5f79e076f326995a5f45e43
moralrecordings
code at moral.net.au
Sat Jan 18 04:32:31 UTC 2020
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
329b77bd82 DIRECTOR: LINGO: Fix constant size check
87f6d6257d DIRECTOR: LINGO: Add previous script context to call frame
bb61cca451 DIRECTOR: LINGO: Add reference to script context in Symbol, allow local calls
Commit: 329b77bd82619c489744a75cda5751b28ebed7d2
https://github.com/scummvm/scummvm/commit/329b77bd82619c489744a75cda5751b28ebed7d2
Author: Scott Percival (code at moral.net.au)
Date: 2020-01-18T11:36:47+08:00
Commit Message:
DIRECTOR: LINGO: Fix constant size check
Changed paths:
engines/director/lingo/lingo-bytecode.cpp
diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp
index cb60347..833c40e 100644
--- a/engines/director/lingo/lingo-bytecode.cpp
+++ b/engines/director/lingo/lingo-bytecode.cpp
@@ -494,14 +494,14 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty
constant.type = STRING;
constant.u.s = new Common::String();
uint32 pointer = value;
- if (pointer + 4 >= constsStoreSize) {
+ if (pointer + 4 > constsStoreSize) {
error("Constant string is too small");
break;
}
uint32 length = READ_BE_UINT32(&constsStore[pointer]);
pointer += 4;
uint32 end = pointer + length;
- if (end >= constsStoreSize) {
+ if (end > constsStoreSize) {
error("Constant string is too large");
break;
}
@@ -515,7 +515,7 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty
}
pointer += 1;
}
- if (pointer >= constsStoreSize) {
+ if (pointer > constsStoreSize) {
warning("Constant string has no null terminator");
break;
}
Commit: 87f6d6257d151b5377bc4ad433aacc181037bcfb
https://github.com/scummvm/scummvm/commit/87f6d6257d151b5377bc4ad433aacc181037bcfb
Author: Scott Percival (code at moral.net.au)
Date: 2020-01-18T11:36:47+08:00
Commit Message:
DIRECTOR: LINGO: Add previous script context to call frame
Changed paths:
engines/director/lingo/lingo-bytecode.cpp
engines/director/lingo/lingo-code.cpp
engines/director/lingo/lingo-code.h
engines/director/lingo/lingo.cpp
engines/director/lingo/lingo.h
diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp
index 833c40e..7b9e392 100644
--- a/engines/director/lingo/lingo-bytecode.cpp
+++ b/engines/director/lingo/lingo-bytecode.cpp
@@ -215,15 +215,15 @@ void LC::cb_field() {
void LC::cb_localcall() {
- int nameId = g_lingo->readInt();
- Common::String name = g_lingo->_namelist[nameId];
+ int functionId = g_lingo->readInt();
Datum nargs = g_lingo->pop();
if ((nargs.type == ARGC) || (nargs.type == ARGCNORET)) {
- warning("STUB: cb_localcall(%s)", name.c_str());
- for (int i = 0; i < nargs.u.i; i++) {
- g_lingo->pop();
- }
+ Symbol *sym = g_lingo->_currentScriptContext->functions[functionId];
+ if (debugChannelSet(3, kDebugLingoExec))
+ g_lingo->printSTUBWithArglist(sym->name.c_str(), nargs.u.i, "call:");
+
+ LC::call(sym, nargs.u.i);
} else {
warning("cb_localcall: first arg should be of type ARGC or ARGCNORET, not %s", nargs.type2str());
@@ -565,8 +565,7 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty
}
_currentScriptFunction = i;
- _currentScriptContext->functions.push_back(new ScriptData);
- _currentScript = _currentScriptContext->functions[_currentScriptFunction];
+ _currentScript = new ScriptData;
uint16 nameIndex = stream.readUint16();
stream.readUint16();
@@ -742,12 +741,20 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty
}
// Attach to handlers
+ Symbol *sym = NULL;
if (nameIndex < _namelist.size()) {
- g_lingo->define(_namelist[nameIndex], argCount, new ScriptData(&(*_currentScript)[0], _currentScript->size()));
-
+ sym = g_lingo->define(_namelist[nameIndex], argCount, _currentScript);
+ _currentScriptContext->functions.push_back(sym);
} else {
warning("Function has unknown name id %d, skipping define", nameIndex);
+ sym = new Symbol;
+ sym->type = HANDLER;
+ sym->u.defn = _currentScript;
+ sym->nargs = argCount;
+ sym->maxArgs = argCount;
}
+ _currentScriptContext->functions.push_back(sym);
+
}
free(codeStore);
diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index 6e45d45..a529e29 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -1164,8 +1164,6 @@ void LC::c_call() {
}
void LC::call(Common::String name, int nargs) {
- bool dropArgs = false;
-
if (debugChannelSet(3, kDebugLingoExec))
g_lingo->printSTUBWithArglist(name.c_str(), nargs, "call:");
@@ -1180,16 +1178,22 @@ void LC::call(Common::String name, int nargs) {
}
}
+ call(sym, nargs);
+}
+
+void LC::call(Symbol *sym, int nargs) {
+ bool dropArgs = false;
+
if (sym == NULL) {
- warning("Call to undefined handler '%s'. Dropping %d stack items", name.c_str(), nargs);
+ warning("Call to undefined handler. Dropping %d stack items", nargs);
dropArgs = true;
} else {
if ((sym->type == BLTIN || sym->type == FBLTIN || sym->type == RBLTIN)
&& sym->nargs != -1 && sym->nargs != nargs && sym->maxArgs != nargs) {
if (sym->nargs == sym->maxArgs)
- warning("Incorrect number of arguments to handler '%s', expecting %d. Dropping %d stack items", name.c_str(), sym->nargs, nargs);
+ warning("Incorrect number of arguments to handler '%s', expecting %d. Dropping %d stack items", sym->name.c_str(), sym->nargs, nargs);
else
- warning("Incorrect number of arguments to handler '%s', expecting %d or %d. Dropping %d stack items", name.c_str(), sym->nargs, sym->maxArgs, nargs);
+ warning("Incorrect number of arguments to handler '%s', expecting %d or %d. Dropping %d stack items", sym->name.c_str(), sym->nargs, sym->maxArgs, nargs);
dropArgs = true;
}
@@ -1207,14 +1211,14 @@ void LC::call(Common::String name, int nargs) {
if (sym->nargs != -1 && sym->maxArgs < nargs) {
warning("Incorrect number of arguments for function %s (%d, expected %d to %d). Dropping extra %d",
- name.c_str(), nargs, sym->nargs, sym->maxArgs, nargs - sym->nargs);
+ sym->name.c_str(), nargs, sym->nargs, sym->maxArgs, nargs - sym->nargs);
for (int i = 0; i < nargs - sym->maxArgs; i++)
g_lingo->pop();
}
if (sym->type == BLTIN || sym->type == FBLTIN || sym->type == RBLTIN) {
if (sym->u.bltin == LB::b_factory) {
- g_lingo->factoryCall(name, nargs);
+ g_lingo->factoryCall(sym->name, nargs);
} else {
int stackSize = g_lingo->_stack.size() - nargs;
@@ -1224,10 +1228,10 @@ void LC::call(Common::String name, int nargs) {
if (sym->type == FBLTIN || sym->type == RBLTIN) {
if (stackNewSize - stackSize != 1)
- warning("built-in function %s did not return value", name.c_str());
+ warning("built-in function %s did not return value", sym->name.c_str());
} else {
if (stackNewSize - stackSize != 0)
- warning("built-in procedure %s returned extra %d values", name.c_str(), stackNewSize - stackSize);
+ warning("built-in procedure %s returned extra %d values", sym->name.c_str(), stackNewSize - stackSize);
}
}
@@ -1248,6 +1252,7 @@ void LC::call(Common::String name, int nargs) {
fp->sp = sym;
fp->retpc = g_lingo->_pc;
fp->retscript = g_lingo->_currentScript;
+ fp->retctx = g_lingo->_currentScriptContext;
fp->localvars = g_lingo->_localvars;
// Create new set of local variables
@@ -1274,6 +1279,7 @@ void LC::c_procret() {
g_lingo->_callstack.pop_back();
g_lingo->_currentScript = fp->retscript;
+ g_lingo->_currentScriptContext = fp->retctx;
g_lingo->_pc = fp->retpc;
g_lingo->cleanLocalVars();
diff --git a/engines/director/lingo/lingo-code.h b/engines/director/lingo/lingo-code.h
index f6f9f38..329145b 100644
--- a/engines/director/lingo/lingo-code.h
+++ b/engines/director/lingo/lingo-code.h
@@ -101,6 +101,7 @@ namespace LC {
void c_jumpifz();
void c_call();
+ void call(Symbol *, int nargs);
void call(Common::String name, int nargs);
void c_procret();
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index de4ab1d..75ab60a 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -142,8 +142,9 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) {
// FIXME: unpack into seperate functions
_currentScriptFunction = 0;
- _currentScriptContext->functions.push_back(new ScriptData);
- _currentScript = _currentScriptContext->functions[_currentScriptFunction];
+ _currentScriptContext->functions.push_back(new Symbol);
+ _currentScript = new ScriptData;
+ _currentScriptContext->functions[_currentScriptFunction]->u.defn = _currentScript;
_linenumber = _colnumber = 1;
_hadError = false;
@@ -232,7 +233,7 @@ void Lingo::executeScript(ScriptType type, uint16 id, uint16 function) {
debugC(1, kDebugLingoExec, "Executing script type: %s, id: %d, function: %d", scriptType2str(type), id, function);
_currentScriptContext = _scriptContexts[type][id];
- _currentScript = _currentScriptContext->functions[function];
+ _currentScript = _currentScriptContext->functions[function]->u.defn;
_pc = 0;
_returning = false;
diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h
index 55dfa50..f313674 100644
--- a/engines/director/lingo/lingo.h
+++ b/engines/director/lingo/lingo.h
@@ -82,7 +82,7 @@ struct Symbol { /* symbol table entry */
int nargs; /* number of arguments */
int maxArgs; /* maximal number of arguments, for builtins */
bool parens; /* whether parens required or not, for builitins */
-
+
bool global;
Symbol();
@@ -119,7 +119,7 @@ struct Builtin {
};
struct ScriptContext {
- Common::Array<ScriptData *> functions;
+ Common::Array<Symbol *> functions;
Common::Array<Datum> constants;
};
@@ -135,6 +135,7 @@ struct CFrame { /* proc/func call stack frame */
Symbol *sp; /* symbol table entry */
int retpc; /* where to resume after return */
ScriptData *retscript; /* which script to resume after return */
+ ScriptContext *retctx; /* which script context to use after return */
SymbolHash *localvars;
};
Commit: bb61cca4512b4cc7f5f79e076f326995a5f45e43
https://github.com/scummvm/scummvm/commit/bb61cca4512b4cc7f5f79e076f326995a5f45e43
Author: Scott Percival (code at moral.net.au)
Date: 2020-01-18T12:30:31+08:00
Commit Message:
DIRECTOR: LINGO: Add reference to script context in Symbol, allow local calls
Changed paths:
engines/director/lingo/lingo-bytecode.cpp
engines/director/lingo/lingo-code.cpp
engines/director/lingo/lingo-codegen.cpp
engines/director/lingo/lingo.cpp
engines/director/lingo/lingo.h
diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp
index 7b9e392..cbd2d72 100644
--- a/engines/director/lingo/lingo-bytecode.cpp
+++ b/engines/director/lingo/lingo-bytecode.cpp
@@ -528,14 +528,12 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty
case 9: // Float type
{
constant.type = FLOAT;
- if (value < constsStoreOffset) {
- warning("Constant float start offset is out of bounds");
- break;
- } else if (value + 4 > constsStoreSize) {
+ if (value + 4 > constsStoreSize) {
warning("Constant float end offset is out of bounds");
break;
}
- constant.u.f = *(float *)(constsStore + value);
+ warning("Float constants not implemented yet");
+ constant.u.f = 0.0;
}
break;
default:
@@ -744,7 +742,6 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty
Symbol *sym = NULL;
if (nameIndex < _namelist.size()) {
sym = g_lingo->define(_namelist[nameIndex], argCount, _currentScript);
- _currentScriptContext->functions.push_back(sym);
} else {
warning("Function has unknown name id %d, skipping define", nameIndex);
sym = new Symbol;
@@ -753,6 +750,7 @@ void Lingo::addCodeV4(Common::SeekableSubReadStreamEndian &stream, ScriptType ty
sym->nargs = argCount;
sym->maxArgs = argCount;
}
+ sym->ctx = _currentScriptContext;
_currentScriptContext->functions.push_back(sym);
}
diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index a529e29..84046d4 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -1261,6 +1261,10 @@ void LC::call(Symbol *sym, int nargs) {
g_lingo->_callstack.push_back(fp);
g_lingo->_currentScript = sym->u.defn;
+ if (sym->ctx) {
+ g_lingo->_currentScriptContext = sym->ctx;
+ }
+
g_lingo->execute(0);
g_lingo->_returning = false;
diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp
index 3e43f67..0ff965f 100644
--- a/engines/director/lingo/lingo-codegen.cpp
+++ b/engines/director/lingo/lingo-codegen.cpp
@@ -269,6 +269,7 @@ Symbol *Lingo::define(Common::String &name, int nargs, ScriptData *code) {
sym->u.defn = code;
sym->nargs = nargs;
sym->maxArgs = nargs;
+ sym->ctx = NULL;
if (debugChannelSet(1, kDebugLingoCompile)) {
uint pc = 0;
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index 75ab60a..c7c8822 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -144,7 +144,9 @@ void Lingo::addCode(const char *code, ScriptType type, uint16 id) {
_currentScriptFunction = 0;
_currentScriptContext->functions.push_back(new Symbol);
_currentScript = new ScriptData;
+ _currentScriptContext->functions[_currentScriptFunction]->type = HANDLER;
_currentScriptContext->functions[_currentScriptFunction]->u.defn = _currentScript;
+ _currentScriptContext->functions[_currentScriptFunction]->ctx = _currentScriptContext;
_linenumber = _colnumber = 1;
_hadError = false;
diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h
index f313674..59dec88 100644
--- a/engines/director/lingo/lingo.h
+++ b/engines/director/lingo/lingo.h
@@ -42,6 +42,7 @@ struct TheEntity;
struct TheEntityField;
struct LingoV4Bytecode;
struct LingoV4TheEntity;
+struct ScriptContext;
class DirectorEngine;
class Frame;
@@ -84,6 +85,7 @@ struct Symbol { /* symbol table entry */
bool parens; /* whether parens required or not, for builitins */
bool global;
+ ScriptContext *ctx; /* optional script context to execute with */
Symbol();
};
More information about the Scummvm-git-logs
mailing list