Skip to content

Commit

Permalink
Script Interpreter 64bit portablity: Defer stack variable copies till…
Browse files Browse the repository at this point in the history
… later.

We need to defer stack variables copies untill after they have been
allocated on the stack.

With this patch, the game is now playable natively on 64bit linux
systems for at least the first level and a half.
But there are some graphical glitches.
  • Loading branch information
phire authored and Miguel Boton committed Dec 1, 2011
1 parent de25afb commit d268563
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions neo/game/script/Script_Compiler.cpp
Expand Up @@ -2217,6 +2217,11 @@ void idCompiler::ParseFunctionDef( idTypeDef *returnType, const char *name ) {
} }
} }


// And now that the stack variables are sorted out, deal with all those copies we have been deferring.
for (int i = 0; i < func->deferredCopies.Num(); i++) {
func->deferredCopies[ i ]->value = func->deferredCopies[ i ]->copyOf->value;
}

// check if we should call the super class destructor // check if we should call the super class destructor
if ( oldscope->TypeDef()->Inherits( &type_object ) && !idStr::Icmp( name, "destroy" ) ) { if ( oldscope->TypeDef()->Inherits( &type_object ) && !idStr::Icmp( name, "destroy" ) ) {
idTypeDef *superClass; idTypeDef *superClass;
Expand Down
16 changes: 13 additions & 3 deletions neo/game/script/Script_Program.cpp
Expand Up @@ -1254,9 +1254,10 @@ idVarDef *idProgram::AllocDef( idTypeDef *type, const char *name, idVarDef *scop
if ( !strcmp( name, RESULT_STRING ) ) { if ( !strcmp( name, RESULT_STRING ) ) {
// <RESULT> vector defs don't need the _x, _y and _z components // <RESULT> vector defs don't need the _x, _y and _z components
assert( scope->Type() == ev_function ); assert( scope->Type() == ev_function );
def->value.stackOffset = scope->value.functionPtr->locals; def->value.stackOffset = -1;
def->initialized = idVarDef::stackVariable; def->initialized = idVarDef::stackVariable;
scope->value.functionPtr->locals += type->Size(); scope->value.functionPtr->stackVars.Append(def);

} else if ( scope->TypeDef()->Inherits( &type_object ) ) { } else if ( scope->TypeDef()->Inherits( &type_object ) ) {
idTypeDef newtype( ev_field, NULL, "float field", 0, &type_float ); idTypeDef newtype( ev_field, NULL, "float field", 0, &type_float );
idTypeDef *type = GetType( newtype, true ); idTypeDef *type = GetType( newtype, true );
Expand Down Expand Up @@ -1289,8 +1290,16 @@ idVarDef *idProgram::AllocDef( idTypeDef *type, const char *name, idVarDef *scop
def_z = AllocDef( &type_float, element, scope, constant ); def_z = AllocDef( &type_float, element, scope, constant );


// point the vector def to the x coordinate // point the vector def to the x coordinate
def->value = def_x->value;
def->initialized = def_x->initialized; def->initialized = def_x->initialized;
def->copyOf = def_x;

if(def->initialized == idVarDef::stackVariable) {
// The variable is allocated on the stack, we need to defer the copy till later.
scope->value.functionPtr->deferredCopies.Append(def);
} else {
def->value = def_x->value;

}
} }
} else if ( scope->TypeDef()->Inherits( &type_object ) ) { } else if ( scope->TypeDef()->Inherits( &type_object ) ) {
// //
Expand All @@ -1307,6 +1316,7 @@ idVarDef *idProgram::AllocDef( idTypeDef *type, const char *name, idVarDef *scop
// them on the stack until the entire function has been parsed // them on the stack until the entire function has been parsed
def->initialized = idVarDef::stackVariable; def->initialized = idVarDef::stackVariable;
scope->value.functionPtr->stackVars.Append(def); scope->value.functionPtr->stackVars.Append(def);
def->value.stackOffset = -1;
} else { } else {
// //
// global variable // global variable
Expand Down
4 changes: 4 additions & 0 deletions neo/game/script/Script_Program.h
Expand Up @@ -26,6 +26,8 @@ If you have questions concerning this license or the applicable additional terms
=========================================================================== ===========================================================================
*/ */


#include <utility>

#ifndef __SCRIPT_PROGRAM_H__ #ifndef __SCRIPT_PROGRAM_H__
#define __SCRIPT_PROGRAM_H__ #define __SCRIPT_PROGRAM_H__


Expand Down Expand Up @@ -70,6 +72,7 @@ class function_t {
int filenum; // source file defined in int filenum; // source file defined in
idList<int> parmSize; idList<int> parmSize;
idList<idVarDef *> stackVars; idList<idVarDef *> stackVars;
idList<idVarDef *> deferredCopies;
}; };


typedef union eval_s { typedef union eval_s {
Expand Down Expand Up @@ -317,6 +320,7 @@ class idVarDef {
varEval_t value; varEval_t value;
idVarDef * scope; // function, namespace, or object the var was defined in idVarDef * scope; // function, namespace, or object the var was defined in
int numUsers; // number of users if this is a constant int numUsers; // number of users if this is a constant
idVarDef * copyOf;


typedef enum { typedef enum {
uninitialized, initializedVariable, initializedConstant, stackVariable uninitialized, initializedVariable, initializedConstant, stackVariable
Expand Down

0 comments on commit d268563

Please sign in to comment.