mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 18:45:38 +00:00
added local variable usage in expressions
This commit is contained in:
parent
fac8fb8fcb
commit
ed92ffcf89
6 changed files with 103 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include "generator.hpp"
|
#include "generator.hpp"
|
||||||
#include "scanner.hpp"
|
#include "scanner.hpp"
|
||||||
#include "errorhandler.hpp"
|
#include "errorhandler.hpp"
|
||||||
|
#include "locals.hpp"
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
{
|
{
|
||||||
|
@ -212,6 +213,19 @@ namespace Compiler
|
||||||
Scanner& scanner)
|
Scanner& scanner)
|
||||||
{
|
{
|
||||||
mFirst = false;
|
mFirst = false;
|
||||||
|
|
||||||
|
if (mNextOperand)
|
||||||
|
{
|
||||||
|
char type = mLocals.getType (name);
|
||||||
|
|
||||||
|
if (type!=' ')
|
||||||
|
{
|
||||||
|
Generator::fetchLocal (mCode, type, mLocals.getIndex (name));
|
||||||
|
mNextOperand = false;
|
||||||
|
mOperands.push_back (type=='f' ? 'f' : 'l');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Parser::parseName (name, loc, scanner);
|
return Parser::parseName (name, loc, scanner);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,6 +160,21 @@ namespace
|
||||||
{
|
{
|
||||||
code.push_back (segment3 (0, buttons));
|
code.push_back (segment3 (0, buttons));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void opFetchLocalShort (Compiler::Generator::CodeContainer& code)
|
||||||
|
{
|
||||||
|
code.push_back (segment5 (21));
|
||||||
|
}
|
||||||
|
|
||||||
|
void opFetchLocalLong (Compiler::Generator::CodeContainer& code)
|
||||||
|
{
|
||||||
|
code.push_back (segment5 (22));
|
||||||
|
}
|
||||||
|
|
||||||
|
void opFetchLocalFloat (Compiler::Generator::CodeContainer& code)
|
||||||
|
{
|
||||||
|
code.push_back (segment5 (23));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
|
@ -347,6 +362,33 @@ namespace Compiler
|
||||||
opPushInt (code, index);
|
opPushInt (code, index);
|
||||||
opMessageBox (code, buttons);
|
opMessageBox (code, buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fetchLocal (CodeContainer& code, char localType, int localIndex)
|
||||||
|
{
|
||||||
|
opPushInt (code, localIndex);
|
||||||
|
|
||||||
|
switch (localType)
|
||||||
|
{
|
||||||
|
case 'f':
|
||||||
|
|
||||||
|
opFetchLocalFloat (code);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
|
||||||
|
opFetchLocalShort (code);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
|
||||||
|
opFetchLocalLong (code);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
assert (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ namespace Compiler
|
||||||
|
|
||||||
void message (CodeContainer& code, Literals& literals, const std::string& message,
|
void message (CodeContainer& code, Literals& literals, const std::string& message,
|
||||||
int buttons);
|
int buttons);
|
||||||
|
|
||||||
|
void fetchLocal (CodeContainer& code, char localType, int localIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,9 @@ op 17: convert stack[1] from integer to float
|
||||||
op 18: convert stack[1] from float to integer
|
op 18: convert stack[1] from float to integer
|
||||||
op 19: take square root of stack[0] (float)
|
op 19: take square root of stack[0] (float)
|
||||||
op 20: return
|
op 20: return
|
||||||
opcodes 21-33554431 unused
|
op 21: replace stack[0] with local short stack[0]
|
||||||
|
op 22: replace stack[0] with local long stack[0]
|
||||||
|
op 23: replace stack[0] with local float stack[0]
|
||||||
|
opcodes 24-33554431 unused
|
||||||
opcodes 33554432-67108863 reserved for extensions
|
opcodes 33554432-67108863 reserved for extensions
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,16 @@ namespace Interpreter
|
||||||
interpreter.installSegment5 (17, new OpIntToFloat1);
|
interpreter.installSegment5 (17, new OpIntToFloat1);
|
||||||
interpreter.installSegment5 (18, new OpFloatToInt1);
|
interpreter.installSegment5 (18, new OpFloatToInt1);
|
||||||
|
|
||||||
// local variables
|
// local variables & literals
|
||||||
interpreter.installSegment5 (0, new OpStoreLocalShort);
|
interpreter.installSegment5 (0, new OpStoreLocalShort);
|
||||||
interpreter.installSegment5 (1, new OpStoreLocalLong);
|
interpreter.installSegment5 (1, new OpStoreLocalLong);
|
||||||
interpreter.installSegment5 (2, new OpStoreLocalFloat);
|
interpreter.installSegment5 (2, new OpStoreLocalFloat);
|
||||||
interpreter.installSegment5 (4, new OpFetchIntLiteral);
|
interpreter.installSegment5 (4, new OpFetchIntLiteral);
|
||||||
interpreter.installSegment5 (5, new OpFetchFloatLiteral);
|
interpreter.installSegment5 (5, new OpFetchFloatLiteral);
|
||||||
|
interpreter.installSegment5 (21, new OpFetchLocalShort);
|
||||||
|
interpreter.installSegment5 (22, new OpFetchLocalLong);
|
||||||
|
interpreter.installSegment5 (23, new OpFetchLocalFloat);
|
||||||
|
|
||||||
// math
|
// math
|
||||||
interpreter.installSegment5 (9, new OpAddInt<Type_Integer>);
|
interpreter.installSegment5 (9, new OpAddInt<Type_Integer>);
|
||||||
interpreter.installSegment5 (10, new OpAddInt<Type_Float>);
|
interpreter.installSegment5 (10, new OpAddInt<Type_Float>);
|
||||||
|
|
|
@ -76,6 +76,42 @@ namespace Interpreter
|
||||||
runtime[0] = *reinterpret_cast<Type_Data *> (&floatValue);
|
runtime[0] = *reinterpret_cast<Type_Data *> (&floatValue);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OpFetchLocalShort : public Opcode0
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void execute (Runtime& runtime)
|
||||||
|
{
|
||||||
|
int index = runtime[0];
|
||||||
|
int value = runtime.getContext().getLocalShort (index);
|
||||||
|
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class OpFetchLocalLong : public Opcode0
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void execute (Runtime& runtime)
|
||||||
|
{
|
||||||
|
int index = runtime[0];
|
||||||
|
int value = runtime.getContext().getLocalLong (index);
|
||||||
|
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class OpFetchLocalFloat : public Opcode0
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void execute (Runtime& runtime)
|
||||||
|
{
|
||||||
|
int index = runtime[0];
|
||||||
|
float value = runtime.getContext().getLocalFloat (index);
|
||||||
|
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue