mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-30 05:47:57 +03:00
Imported Upstream version 0.26.0
This commit is contained in:
commit
9a2b6c69b6
1398 changed files with 212217 additions and 0 deletions
112
components/interpreter/mathopcodes.hpp
Normal file
112
components/interpreter/mathopcodes.hpp
Normal file
|
@ -0,0 +1,112 @@
|
|||
#ifndef INTERPRETER_MATHOPCODES_H_INCLUDED
|
||||
#define INTERPRETER_MATHOPCODES_H_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cmath>
|
||||
|
||||
#include "opcodes.hpp"
|
||||
#include "runtime.hpp"
|
||||
|
||||
namespace Interpreter
|
||||
{
|
||||
template<typename T>
|
||||
class OpAddInt : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
T result = getData<T> (runtime[1]) + getData<T> (runtime[0]);
|
||||
|
||||
runtime.pop();
|
||||
|
||||
getData<T> (runtime[0]) = result;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class OpSubInt : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
T result = getData<T> (runtime[1]) - getData<T> (runtime[0]);
|
||||
|
||||
runtime.pop();
|
||||
|
||||
getData<T> (runtime[0]) = result;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class OpMulInt : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
T result = getData<T> (runtime[1]) * getData<T> (runtime[0]);
|
||||
|
||||
runtime.pop();
|
||||
|
||||
getData<T> (runtime[0]) = result;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class OpDivInt : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
T left = getData<T> (runtime[0]);
|
||||
|
||||
if (left==0)
|
||||
throw std::runtime_error ("division by zero");
|
||||
|
||||
T result = getData<T> (runtime[1]) / left;
|
||||
|
||||
runtime.pop();
|
||||
|
||||
getData<T> (runtime[0]) = result;
|
||||
}
|
||||
};
|
||||
|
||||
class OpSquareRoot : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
Type_Float value = runtime[0].mFloat;
|
||||
|
||||
if (value<0)
|
||||
throw std::runtime_error (
|
||||
"square root of negative number (we aren't that imaginary)");
|
||||
|
||||
value = std::sqrt (value);
|
||||
|
||||
runtime[0].mFloat = value;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename C>
|
||||
class OpCompare : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
int result = C() (getData<T> (runtime[1]), getData<T> (runtime[0]));
|
||||
|
||||
runtime.pop();
|
||||
|
||||
runtime[0].mInteger = result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue