replaced flat Type_Data stack with a union

actorid
Marc Zinnschlag 15 years ago
parent 8873c9bb3b
commit c9a6335918

@ -26,10 +26,10 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string file = runtime.getStringLiteral (runtime[0]);
std::string file = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string text = runtime.getStringLiteral (runtime[0]);
std::string text = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().say (context.getReference(), file, text,
@ -60,7 +60,7 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().streamMusic (sound, context);
@ -76,7 +76,7 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().playSound (sound, 1.0, 1.0, context);
@ -92,13 +92,13 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
float volume = *reinterpret_cast<float *> (&runtime[0]);
Interpreter::Type_Float volume = runtime[0].mFloat;
runtime.pop();
float pitch = *reinterpret_cast<float *> (&runtime[0]);
Interpreter::Type_Float pitch = runtime[0].mFloat;
runtime.pop();
context.getSoundManager().playSound (sound, volume, pitch, context);
@ -118,7 +118,7 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().playSound3D (context.getReference(), sound,
@ -139,13 +139,13 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
float volume = *reinterpret_cast<float *> (&runtime[0]);
Interpreter::Type_Float volume = runtime[0].mFloat;
runtime.pop();
float pitch = *reinterpret_cast<float *> (&runtime[0]);
Interpreter::Type_Float pitch = runtime[0].mFloat;
runtime.pop();
context.getSoundManager().playSound3D (context.getReference(), sound, volume,
@ -163,7 +163,7 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().stopSound3D (context.getReference(), sound, context);
@ -179,7 +179,7 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
int index = runtime[0];
int index = runtime[0].mInteger;
runtime.pop();
runtime.push (context.getSoundManager().getSoundPlaying (
@ -196,13 +196,13 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0]);
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string file = runtime.getStringLiteral (runtime[0]);
std::string file = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string text = runtime.getStringLiteral (runtime[0]);
std::string text = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().say (context.getWorld().getPtr (id, true),
@ -219,7 +219,7 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0]);
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
runtime.push (context.getSoundManager().sayDone (
@ -240,10 +240,10 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0]);
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().playSound3D (
@ -264,16 +264,16 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0]);
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
float volume = *reinterpret_cast<float *> (&runtime[0]);
Interpreter::Type_Float volume = runtime[0].mFloat;
runtime.pop();
float pitch = *reinterpret_cast<float *> (&runtime[0]);
Interpreter::Type_Float pitch = runtime[0].mFloat;
runtime.pop();
context.getSoundManager().playSound3D (
@ -291,10 +291,10 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0]);
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
std::string sound = runtime.getStringLiteral (runtime[0]);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
context.getSoundManager().stopSound3D (
@ -311,10 +311,10 @@ namespace MWScript
MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string id = runtime.getStringLiteral (runtime[0]);
std::string id = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
int index = runtime[0];
int index = runtime[0].mInteger;
runtime.pop();
runtime.push (context.getSoundManager().getSoundPlaying (

@ -24,7 +24,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Data data = runtime[0];
Type_Integer data = runtime[0].mInteger;
runtime.pop();
if (data==0)
@ -38,7 +38,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Data data = runtime[0];
Type_Integer data = runtime[0].mInteger;
runtime.pop();
if (data!=0)

@ -12,7 +12,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime, unsigned int arg0)
{
runtime.push (arg0);
runtime.push (static_cast<Type_Integer> (arg0));
}
};
@ -22,9 +22,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Integer data = *reinterpret_cast<Type_Integer *> (&runtime[0]);
Type_Integer data = runtime[0].mInteger;
Type_Float floatValue = static_cast<Type_Float> (data);
runtime[0] = *reinterpret_cast<Type_Data *> (&floatValue);
runtime[0].mFloat = floatValue;
}
};
@ -34,9 +34,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Float data = *reinterpret_cast<Type_Float *> (&runtime[0]);
Type_Float data = runtime[0].mFloat;
Type_Integer integerValue = static_cast<Type_Integer> (data);
runtime[0] = *reinterpret_cast<Type_Data *> (&integerValue);
runtime[0].mInteger = integerValue;
}
};
@ -46,9 +46,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Integer data = *reinterpret_cast<Type_Integer *> (&runtime[0]);
Type_Integer data = runtime[0].mInteger;
data = -data;
runtime[0] = *reinterpret_cast<Type_Data *> (&data);
runtime[0].mInteger = data;
}
};
@ -58,9 +58,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Float data = *reinterpret_cast<Type_Float *> (&runtime[0]);
Type_Float data = runtime[0].mFloat;
data = -data;
runtime[0] = *reinterpret_cast<Type_Data *> (&data);
runtime[0].mFloat = data;
}
};
@ -70,9 +70,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Integer data = *reinterpret_cast<Type_Integer *> (&runtime[1]);
Type_Integer data = runtime[1].mInteger;
Type_Float floatValue = static_cast<Type_Float> (data);
runtime[1] = *reinterpret_cast<Type_Data *> (&floatValue);
runtime[1].mFloat = floatValue;
}
};
@ -82,9 +82,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Float data = *reinterpret_cast<Type_Float *> (&runtime[1]);
Type_Float data = runtime[1].mFloat;
Type_Integer integerValue = static_cast<Type_Integer> (data);
runtime[1] = *reinterpret_cast<Type_Data *> (&integerValue);
runtime[1].mInteger = integerValue;
}
};
}

@ -13,10 +13,10 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Data data = runtime[0];
int index = runtime[1];
Type_Integer data = runtime[0].mInteger;
int index = runtime[1].mInteger;
runtime.getContext().setLocalShort (index, *reinterpret_cast<int *> (&data));
runtime.getContext().setLocalShort (index, data);
runtime.pop();
runtime.pop();
@ -29,10 +29,10 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Data data = runtime[0];
int index = runtime[1];
Type_Integer data = runtime[0].mInteger;
int index = runtime[1].mInteger;
runtime.getContext().setLocalLong (index, *reinterpret_cast<int *> (&data));
runtime.getContext().setLocalLong (index, data);
runtime.pop();
runtime.pop();
@ -45,10 +45,10 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Data data = runtime[0];
int index = runtime[1];
Type_Float data = runtime[0].mFloat;
int index = runtime[1].mInteger;
runtime.getContext().setLocalFloat (index, *reinterpret_cast<float *> (&data));
runtime.getContext().setLocalFloat (index, data);
runtime.pop();
runtime.pop();
@ -61,8 +61,8 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int intValue = runtime.getIntegerLiteral (runtime[0]);
runtime[0] = intValue;
Type_Integer intValue = runtime.getIntegerLiteral (runtime[0].mInteger);
runtime[0].mInteger = intValue;
}
};
@ -72,8 +72,8 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
float floatValue = runtime.getFloatLiteral (runtime[0]);
runtime[0] = *reinterpret_cast<Type_Data *> (&floatValue);
Type_Float floatValue = runtime.getFloatLiteral (runtime[0].mInteger);
runtime[0].mFloat = floatValue;
}
};
@ -83,9 +83,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
int value = runtime.getContext().getLocalShort (index);
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
runtime[0].mInteger = value;
}
};
@ -95,9 +95,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
int value = runtime.getContext().getLocalLong (index);
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
runtime[0].mInteger = value;
}
};
@ -107,9 +107,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
float value = runtime.getContext().getLocalFloat (index);
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
runtime[0].mFloat = value;
}
};
@ -119,12 +119,12 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Data data = runtime[0];
int index = runtime[1];
Type_Integer data = runtime[0].mInteger;
int index = runtime[1].mInteger;
std::string name = runtime.getStringLiteral (index);
runtime.getContext().setGlobalShort (name, *reinterpret_cast<int *> (&data));
runtime.getContext().setGlobalShort (name, data);
runtime.pop();
runtime.pop();
@ -137,12 +137,12 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Data data = runtime[0];
int index = runtime[1];
Type_Integer data = runtime[0].mInteger;
int index = runtime[1].mInteger;
std::string name = runtime.getStringLiteral (index);
runtime.getContext().setGlobalLong (name, *reinterpret_cast<int *> (&data));
runtime.getContext().setGlobalLong (name, data);
runtime.pop();
runtime.pop();
@ -155,12 +155,12 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Data data = runtime[0];
int index = runtime[1];
Type_Float data = runtime[0].mFloat;
int index = runtime[1].mInteger;
std::string name = runtime.getStringLiteral (index);
runtime.getContext().setGlobalFloat (name, *reinterpret_cast<float *> (&data));
runtime.getContext().setGlobalFloat (name, data);
runtime.pop();
runtime.pop();
@ -173,10 +173,10 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
std::string name = runtime.getStringLiteral (index);
int value = runtime.getContext().getGlobalShort (name);
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
Type_Integer value = runtime.getContext().getGlobalShort (name);
runtime[0].mInteger = value;
}
};
@ -186,10 +186,10 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
std::string name = runtime.getStringLiteral (index);
int value = runtime.getContext().getGlobalLong (name);
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
Type_Integer value = runtime.getContext().getGlobalLong (name);
runtime[0].mInteger = value;
}
};
@ -199,10 +199,10 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
std::string name = runtime.getStringLiteral (index);
float value = runtime.getContext().getGlobalFloat (name);
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
Type_Float value = runtime.getContext().getGlobalFloat (name);
runtime[0].mFloat = value;
}
};
}

@ -16,14 +16,11 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
T result =
*reinterpret_cast<T *> (&runtime[1])
+
*reinterpret_cast<T *> (&runtime[0]);
T result = getData<T> (runtime[1]) + getData<T> (runtime[0]);
runtime.pop();
runtime[0] = *reinterpret_cast<Type_Data *> (&result);
getData<T> (runtime[0]) = result;
}
};
@ -34,14 +31,11 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
T result =
*reinterpret_cast<T *> (&runtime[1])
-
*reinterpret_cast<T *> (&runtime[0]);
T result = getData<T> (runtime[1]) - getData<T> (runtime[0]);
runtime.pop();
runtime[0] = *reinterpret_cast<Type_Data *> (&result);
getData<T> (runtime[0]) = result;
}
};
@ -52,14 +46,11 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
T result =
*reinterpret_cast<T *> (&runtime[1])
*
*reinterpret_cast<T *> (&runtime[0]);
T result = getData<T> (runtime[1]) * getData<T> (runtime[0]);
runtime.pop();
runtime[0] = *reinterpret_cast<Type_Data *> (&result);
getData<T> (runtime[0]) = result;
}
};
@ -70,19 +61,16 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
T left = *reinterpret_cast<T *> (&runtime[0]);
T left = getData<T> (runtime[0]);
if (left==0)
throw std::runtime_error ("division by zero");
T result =
*reinterpret_cast<T *> (&runtime[1])
/
left;
T result = getData<T> (runtime[1]) / left;
runtime.pop();
runtime[0] = *reinterpret_cast<Type_Data *> (&result);
getData<T> (runtime[0]) = result;
}
};
@ -92,7 +80,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
Type_Float value = *reinterpret_cast<Type_Float *> (&runtime[0]);
Type_Float value = runtime[0].mFloat;
if (value<0)
throw std::runtime_error (
@ -100,7 +88,7 @@ namespace Interpreter
value = std::sqrt (value);
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
runtime[0].mFloat = value;
}
};
@ -111,13 +99,11 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int result = C() (
*reinterpret_cast<T *> (&runtime[1]),
*reinterpret_cast<T *> (&runtime[0]));
int result = C() (getData<T> (runtime[1]), getData<T> (runtime[0]));
runtime.pop();
runtime[0] = *reinterpret_cast<Type_Data *> (&result);
runtime[0].mInteger = result;
}
};
}

@ -22,7 +22,7 @@ namespace Interpreter
throw std::logic_error ("message box buttons not implemented yet");
// message
int index = runtime[0];
int index = runtime[0].mInteger;
runtime.pop();
std::string message = runtime.getStringLiteral (index);
@ -44,13 +44,13 @@ namespace Interpreter
if (c=='S' || c=='s')
{
int index = runtime[0];
int index = runtime[0].mInteger;
runtime.pop();
formattedMessage += runtime.getStringLiteral (index);
}
else if (c=='g' || c=='G')
{
int value = *reinterpret_cast<const int *> (&runtime[0]);
Type_Integer value = runtime[0].mInteger;
runtime.pop();
std::ostringstream out;
@ -64,7 +64,7 @@ namespace Interpreter
++i;
}
float value = *reinterpret_cast<const float *> (&runtime[0]);
float value = runtime[0].mFloat;
runtime.pop();
std::ostringstream out;
@ -107,7 +107,7 @@ namespace Interpreter
{
double r = static_cast<double> (std::rand()) / RAND_MAX; // [0, 1)
Type_Integer limit = *reinterpret_cast<Type_Integer *> (&runtime[0]);
Type_Integer limit = runtime[0].mInteger;
if (limit<0)
throw std::runtime_error (
@ -115,7 +115,7 @@ namespace Interpreter
Type_Integer value = static_cast<Type_Integer> (r*limit); // [o, limit)
runtime[0] = *reinterpret_cast<Type_Data *> (&value);
runtime[0].mInteger = value;
}
};
@ -125,9 +125,9 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
float duration = runtime.getContext().getSecondsPassed();
Type_Float duration = runtime.getContext().getSecondsPassed();
runtime.push (*reinterpret_cast<Type_Data *> (&duration));
runtime.push (duration);
}
};
@ -167,7 +167,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
runtime.pop();
std::string id = runtime.getStringLiteral (index);
@ -181,7 +181,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
runtime.pop();
std::string id = runtime.getStringLiteral (index);
@ -195,7 +195,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
runtime.pop();
std::string id = runtime.getStringLiteral (index);

@ -68,11 +68,25 @@ namespace Interpreter
mPC = PC;
}
void Runtime::push (Type_Data data)
void Runtime::push (const Data& data)
{
mStack.push_back (data);
}
void Runtime::push (Type_Integer value)
{
Data data;
data.mInteger = value;
push (data);
}
void Runtime::push (Type_Float value)
{
Data data;
data.mFloat = value;
push (data);
}
void Runtime::pop()
{
if (mStack.empty())
@ -81,7 +95,7 @@ namespace Interpreter
mStack.resize (mStack.size()-1);
}
Type_Data& Runtime::operator[] (int Index)
Data& Runtime::operator[] (int Index)
{
if (Index<0 || Index>=static_cast<int> (mStack.size()))
throw std::runtime_error ("stack index out of range");

@ -18,7 +18,7 @@ namespace Interpreter
const Type_Code *mCode;
int mCodeSize;
int mPC;
std::vector<Type_Data> mStack;
std::vector<Data> mStack;
public:
@ -42,13 +42,19 @@ namespace Interpreter
void setPC (int PC);
///< set program counter.
void push (Type_Data data);
void push (const Data& data);
///< push data on stack
void push (Type_Integer value);
///< push integer data on stack.
void push (Type_Float value);
///< push float data on stack.
void pop();
///< pop stack
Type_Data& operator[] (int Index);
Data& operator[] (int Index);
///< Access stack member, counted from the top.
Context& getContext();

@ -13,8 +13,8 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
std::string name = runtime.getStringLiteral (runtime[0]);
runtime[0] = runtime.getContext().isScriptRunning (name);
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
runtime[0].mInteger = runtime.getContext().isScriptRunning (name);
}
};
@ -24,7 +24,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
std::string name = runtime.getStringLiteral (runtime[0]);
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
runtime.getContext().startScript (name);
}
@ -36,7 +36,7 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
std::string name = runtime.getStringLiteral (runtime[0]);
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
runtime.getContext().stopScript (name);
}

@ -12,11 +12,11 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
std::string name = runtime.getStringLiteral (runtime[0]);
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
float distance = runtime.getContext().getDistance (name);
Type_Float distance = runtime.getContext().getDistance (name);
runtime[0] = *reinterpret_cast<Type_Data *> (&distance);
runtime[0].mFloat = distance;
}
};
@ -26,15 +26,15 @@ namespace Interpreter
virtual void execute (Runtime& runtime)
{
int index = runtime[0];
int index = runtime[0].mInteger;
runtime.pop();
std::string id = runtime.getStringLiteral (index);
std::string name = runtime.getStringLiteral (runtime[0]);
std::string name = runtime.getStringLiteral (runtime[0].mInteger);
float distance = runtime.getContext().getDistance (name, id);
Type_Float distance = runtime.getContext().getDistance (name, id);
runtime[0] = *reinterpret_cast<Type_Data *> (&distance);
runtime[0].mFloat = distance;
}
};
}

@ -1,6 +1,8 @@
#ifndef INTERPRETER_TYPES_H_INCLUDED
#define INTERPRETER_TYPES_H_INCLUDED
#include <stdexcept>
namespace Interpreter
{
typedef unsigned int Type_Code; // 32 bit
@ -12,6 +14,30 @@ namespace Interpreter
typedef int Type_Integer; // 32 bit
typedef float Type_Float; // 32 bit
union Data
{
Type_Integer mInteger;
Type_Float mFloat;
};
template<typename T>
T& getData (Data& data)
{
throw std::runtime_error ("unsupported data type");
}
template<>
inline Type_Integer& getData (Data& data)
{
return data.mInteger;
}
template<>
inline Type_Float& getData (Data& data)
{
return data.mFloat;
}
}
#endif

Loading…
Cancel
Save