Skip to content

Commit

Permalink
DIRECTOR: Lingo: Implemented 'global' keyword. Start of local/global …
Browse files Browse the repository at this point in the history
…var implementation
  • Loading branch information
sev- committed Aug 3, 2016
1 parent 4b871b6 commit 7013f6b
Show file tree
Hide file tree
Showing 9 changed files with 526 additions and 471 deletions.
20 changes: 20 additions & 0 deletions engines/director/lingo/lingo-code.cpp
Expand Up @@ -424,4 +424,24 @@ void Lingo::c_procret() {
g_lingo->_returning = true;
}

void Lingo::c_global() {
Common::String name((char *)&(*g_lingo->_currentScript)[g_lingo->_pc]);

Symbol *s = g_lingo->lookupVar(name.c_str(), false);
if (s) {
if (s->global) {
warning("Redefinition of global variable %s", name.c_str());
} else {
warning("Local variable %s declared as global", name.c_str());
}

return;
}

s = g_lingo->lookupVar(name.c_str(), true, false);
s->global = true;

g_lingo->_pc += g_lingo->calcStringAlignment(name.c_str());
}

}
8 changes: 7 additions & 1 deletion engines/director/lingo/lingo-codegen.cpp
Expand Up @@ -64,10 +64,13 @@ void Lingo::execute(int pc) {
}
}

Symbol *Lingo::lookupVar(const char *name) {
Symbol *Lingo::lookupVar(const char *name, bool create, bool putInLocalList) {
Symbol *sym;

if (!_vars.contains(name)) { // Create variable if it was not defined
if (!create)
return NULL;

sym = new Symbol;
sym->name = (char *)calloc(strlen(name) + 1, 1);
Common::strlcpy(sym->name, name, strlen(name) + 1);
Expand All @@ -79,6 +82,9 @@ Symbol *Lingo::lookupVar(const char *name) {
sym = g_lingo->_vars[name];
}

if (putInLocalList)
_localvars[name] = true;

return sym;
}

Expand Down

0 comments on commit 7013f6b

Please sign in to comment.