1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 08:15:37 +00:00

Issue #181: added code generation for member variable access

This commit is contained in:
Marc Zinnschlag 2012-06-16 10:49:34 +02:00
parent 050559d2e2
commit d1441d79e7
2 changed files with 117 additions and 1 deletions

View file

@ -260,6 +260,36 @@ namespace
code.push_back (Compiler::Generator::segment5 (44));
}
void opStoreMemberShort (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (59));
}
void opStoreMemberLong (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (60));
}
void opStoreMemberFloat (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (61));
}
void opFetchMemberShort (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (62));
}
void opFetchMemberLong (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (63));
}
void opFetchMemberFloat (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (64));
}
void opRandom (Compiler::Generator::CodeContainer& code)
{
code.push_back (Compiler::Generator::segment5 (45));
@ -644,7 +674,7 @@ namespace Compiler
if (localType!=valueType)
{
if (localType=='f' && valueType=='l')
if (localType=='f' && (valueType=='l' || valueType=='s'))
{
opIntToFloat (code);
}
@ -707,6 +737,86 @@ namespace Compiler
}
}
void assignToMember (CodeContainer& code, Literals& literals, char localType,
const std::string& name, const std::string& id, const CodeContainer& value, char valueType)
{
int index = literals.addString (name);
opPushInt (code, index);
index = literals.addString (id);
opPushInt (code, index);
std::copy (value.begin(), value.end(), std::back_inserter (code));
if (localType!=valueType)
{
if (localType=='f' && (valueType=='l' || valueType=='s'))
{
opIntToFloat (code);
}
else if ((localType=='l' || localType=='s') && valueType=='f')
{
opFloatToInt (code);
}
}
switch (localType)
{
case 'f':
opStoreMemberFloat (code);
break;
case 's':
opStoreMemberShort (code);
break;
case 'l':
opStoreMemberLong (code);
break;
default:
assert (0);
}
}
void fetchMember (CodeContainer& code, Literals& literals, char localType,
const std::string& name, const std::string& id)
{
int index = literals.addString (name);
opPushInt (code, index);
index = literals.addString (id);
switch (localType)
{
case 'f':
opFetchMemberFloat (code);
break;
case 's':
opFetchMemberShort (code);
break;
case 'l':
opFetchMemberLong (code);
break;
default:
assert (0);
}
}
void random (CodeContainer& code)
{
opRandom (code);

View file

@ -101,6 +101,12 @@ namespace Compiler
void fetchGlobal (CodeContainer& code, Literals& literals, char localType,
const std::string& name);
void assignToMember (CodeContainer& code, Literals& literals, char memberType,
const std::string& name, const std::string& id, const CodeContainer& value, char valueType);
void fetchMember (CodeContainer& code, Literals& literals, char memberType,
const std::string& name, const std::string& id);
void random (CodeContainer& code);
void scriptRunning (CodeContainer& code);