diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index d7aada989..40229475e 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -26,10 +26,10 @@ namespace MWScript MWScript::InterpreterContext& context = static_cast (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 (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 (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 (runtime.getContext()); - std::string sound = runtime.getStringLiteral (runtime[0]); + std::string sound = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - float volume = *reinterpret_cast (&runtime[0]); + Interpreter::Type_Float volume = runtime[0].mFloat; runtime.pop(); - float pitch = *reinterpret_cast (&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 (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 (runtime.getContext()); - std::string sound = runtime.getStringLiteral (runtime[0]); + std::string sound = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - float volume = *reinterpret_cast (&runtime[0]); + Interpreter::Type_Float volume = runtime[0].mFloat; runtime.pop(); - float pitch = *reinterpret_cast (&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 (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 (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 (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 (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 (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 (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 (&runtime[0]); + Interpreter::Type_Float volume = runtime[0].mFloat; runtime.pop(); - float pitch = *reinterpret_cast (&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 (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 (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 ( diff --git a/components/interpreter/controlopcodes.hpp b/components/interpreter/controlopcodes.hpp index cf9185a69..534ccc4dd 100644 --- a/components/interpreter/controlopcodes.hpp +++ b/components/interpreter/controlopcodes.hpp @@ -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) diff --git a/components/interpreter/genericopcodes.hpp b/components/interpreter/genericopcodes.hpp index 116b586e4..44ef3fc6b 100644 --- a/components/interpreter/genericopcodes.hpp +++ b/components/interpreter/genericopcodes.hpp @@ -12,7 +12,7 @@ namespace Interpreter virtual void execute (Runtime& runtime, unsigned int arg0) { - runtime.push (arg0); + runtime.push (static_cast (arg0)); } }; @@ -22,9 +22,9 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - Type_Integer data = *reinterpret_cast (&runtime[0]); + Type_Integer data = runtime[0].mInteger; Type_Float floatValue = static_cast (data); - runtime[0] = *reinterpret_cast (&floatValue); + runtime[0].mFloat = floatValue; } }; @@ -34,9 +34,9 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - Type_Float data = *reinterpret_cast (&runtime[0]); + Type_Float data = runtime[0].mFloat; Type_Integer integerValue = static_cast (data); - runtime[0] = *reinterpret_cast (&integerValue); + runtime[0].mInteger = integerValue; } }; @@ -46,9 +46,9 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - Type_Integer data = *reinterpret_cast (&runtime[0]); + Type_Integer data = runtime[0].mInteger; data = -data; - runtime[0] = *reinterpret_cast (&data); + runtime[0].mInteger = data; } }; @@ -58,9 +58,9 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - Type_Float data = *reinterpret_cast (&runtime[0]); + Type_Float data = runtime[0].mFloat; data = -data; - runtime[0] = *reinterpret_cast (&data); + runtime[0].mFloat = data; } }; @@ -70,9 +70,9 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - Type_Integer data = *reinterpret_cast (&runtime[1]); + Type_Integer data = runtime[1].mInteger; Type_Float floatValue = static_cast (data); - runtime[1] = *reinterpret_cast (&floatValue); + runtime[1].mFloat = floatValue; } }; @@ -82,9 +82,9 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - Type_Float data = *reinterpret_cast (&runtime[1]); + Type_Float data = runtime[1].mFloat; Type_Integer integerValue = static_cast (data); - runtime[1] = *reinterpret_cast (&integerValue); + runtime[1].mInteger = integerValue; } }; } diff --git a/components/interpreter/localopcodes.hpp b/components/interpreter/localopcodes.hpp index 427b4b574..ea62b7ad8 100644 --- a/components/interpreter/localopcodes.hpp +++ b/components/interpreter/localopcodes.hpp @@ -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 (&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 (&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 (&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 (&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 (&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 (&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 (&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 (&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 (&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 (&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 (&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 (&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 (&value); + Type_Float value = runtime.getContext().getGlobalFloat (name); + runtime[0].mFloat = value; } }; } diff --git a/components/interpreter/mathopcodes.hpp b/components/interpreter/mathopcodes.hpp index d569a5470..14d5d98df 100644 --- a/components/interpreter/mathopcodes.hpp +++ b/components/interpreter/mathopcodes.hpp @@ -16,14 +16,11 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - T result = - *reinterpret_cast (&runtime[1]) - + - *reinterpret_cast (&runtime[0]); + T result = getData (runtime[1]) + getData (runtime[0]); runtime.pop(); - runtime[0] = *reinterpret_cast (&result); + getData (runtime[0]) = result; } }; @@ -34,14 +31,11 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - T result = - *reinterpret_cast (&runtime[1]) - - - *reinterpret_cast (&runtime[0]); + T result = getData (runtime[1]) - getData (runtime[0]); runtime.pop(); - - runtime[0] = *reinterpret_cast (&result); + + getData (runtime[0]) = result; } }; @@ -52,14 +46,11 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - T result = - *reinterpret_cast (&runtime[1]) - * - *reinterpret_cast (&runtime[0]); + T result = getData (runtime[1]) * getData (runtime[0]); runtime.pop(); - - runtime[0] = *reinterpret_cast (&result); + + getData (runtime[0]) = result; } }; @@ -70,19 +61,16 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - T left = *reinterpret_cast (&runtime[0]); + T left = getData (runtime[0]); if (left==0) throw std::runtime_error ("division by zero"); - T result = - *reinterpret_cast (&runtime[1]) - / - left; + T result = getData (runtime[1]) / left; runtime.pop(); - - runtime[0] = *reinterpret_cast (&result); + + getData (runtime[0]) = result; } }; @@ -92,7 +80,7 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - Type_Float value = *reinterpret_cast (&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 (&value); + runtime[0].mFloat = value; } }; @@ -111,13 +99,11 @@ namespace Interpreter virtual void execute (Runtime& runtime) { - int result = C() ( - *reinterpret_cast (&runtime[1]), - *reinterpret_cast (&runtime[0])); + int result = C() (getData (runtime[1]), getData (runtime[0])); runtime.pop(); - runtime[0] = *reinterpret_cast (&result); + runtime[0].mInteger = result; } }; } diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp index 852d2d154..8d05c58da 100644 --- a/components/interpreter/miscopcodes.hpp +++ b/components/interpreter/miscopcodes.hpp @@ -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 (&runtime[0]); + Type_Integer value = runtime[0].mInteger; runtime.pop(); std::ostringstream out; @@ -64,7 +64,7 @@ namespace Interpreter ++i; } - float value = *reinterpret_cast (&runtime[0]); + float value = runtime[0].mFloat; runtime.pop(); std::ostringstream out; @@ -107,7 +107,7 @@ namespace Interpreter { double r = static_cast (std::rand()) / RAND_MAX; // [0, 1) - Type_Integer limit = *reinterpret_cast (&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 (r*limit); // [o, limit) - runtime[0] = *reinterpret_cast (&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 (&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); diff --git a/components/interpreter/runtime.cpp b/components/interpreter/runtime.cpp index 746be60d2..f3a3a905d 100644 --- a/components/interpreter/runtime.cpp +++ b/components/interpreter/runtime.cpp @@ -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 (mStack.size())) throw std::runtime_error ("stack index out of range"); diff --git a/components/interpreter/runtime.hpp b/components/interpreter/runtime.hpp index 73e90f68a..e9ba01041 100644 --- a/components/interpreter/runtime.hpp +++ b/components/interpreter/runtime.hpp @@ -18,7 +18,7 @@ namespace Interpreter const Type_Code *mCode; int mCodeSize; int mPC; - std::vector mStack; + std::vector 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(); diff --git a/components/interpreter/scriptopcodes.hpp b/components/interpreter/scriptopcodes.hpp index 84fd546fb..56502d510 100644 --- a/components/interpreter/scriptopcodes.hpp +++ b/components/interpreter/scriptopcodes.hpp @@ -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); } diff --git a/components/interpreter/spatialopcodes.hpp b/components/interpreter/spatialopcodes.hpp index d897ff69d..e37df8116 100644 --- a/components/interpreter/spatialopcodes.hpp +++ b/components/interpreter/spatialopcodes.hpp @@ -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 (&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 (&distance); + runtime[0].mFloat = distance; } }; } diff --git a/components/interpreter/types.hpp b/components/interpreter/types.hpp index 2747d1447..89529189f 100644 --- a/components/interpreter/types.hpp +++ b/components/interpreter/types.hpp @@ -1,6 +1,8 @@ #ifndef INTERPRETER_TYPES_H_INCLUDED #define INTERPRETER_TYPES_H_INCLUDED +#include + 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 + 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