2010-06-28 21:49:48 +02:00
|
|
|
#ifndef INTERPRETER_GENERICOPCODES_H_INCLUDED
|
|
|
|
#define INTERPRETER_GENERICOPCODES_H_INCLUDED
|
|
|
|
|
|
|
|
#include "opcodes.hpp"
|
|
|
|
#include "runtime.hpp"
|
|
|
|
|
|
|
|
namespace Interpreter
|
|
|
|
{
|
|
|
|
class OpPushInt : public Opcode1
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Runtime& runtime, unsigned int arg0) override { runtime.push(static_cast<Type_Integer>(arg0)); }
|
2010-06-28 21:49:48 +02:00
|
|
|
};
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2010-06-28 21:49:48 +02:00
|
|
|
class OpIntToFloat : public Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Runtime& runtime) override
|
2010-06-28 21:49:48 +02:00
|
|
|
{
|
2010-07-14 15:28:55 +02:00
|
|
|
Type_Integer data = runtime[0].mInteger;
|
2010-06-28 21:49:48 +02:00
|
|
|
Type_Float floatValue = static_cast<Type_Float>(data);
|
2010-07-14 15:28:55 +02:00
|
|
|
runtime[0].mFloat = floatValue;
|
2010-06-28 21:49:48 +02:00
|
|
|
}
|
|
|
|
};
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2010-06-29 10:36:42 +02:00
|
|
|
class OpFloatToInt : public Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Runtime& runtime) override
|
2010-06-29 10:36:42 +02:00
|
|
|
{
|
2010-07-14 15:28:55 +02:00
|
|
|
Type_Float data = runtime[0].mFloat;
|
2010-06-29 10:36:42 +02:00
|
|
|
Type_Integer integerValue = static_cast<Type_Integer>(data);
|
2010-07-14 15:28:55 +02:00
|
|
|
runtime[0].mInteger = integerValue;
|
2010-06-29 10:36:42 +02:00
|
|
|
}
|
|
|
|
};
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2010-06-29 12:05:22 +02:00
|
|
|
class OpNegateInt : public Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Runtime& runtime) override
|
2010-06-29 12:05:22 +02:00
|
|
|
{
|
2010-07-14 15:28:55 +02:00
|
|
|
Type_Integer data = runtime[0].mInteger;
|
2010-06-29 12:05:22 +02:00
|
|
|
data = -data;
|
2010-07-14 15:28:55 +02:00
|
|
|
runtime[0].mInteger = data;
|
2010-06-29 12:05:22 +02:00
|
|
|
}
|
|
|
|
};
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2010-06-29 12:05:22 +02:00
|
|
|
class OpNegateFloat : public Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Runtime& runtime) override
|
2010-06-29 12:05:22 +02:00
|
|
|
{
|
2010-07-14 15:28:55 +02:00
|
|
|
Type_Float data = runtime[0].mFloat;
|
2010-06-29 12:05:22 +02:00
|
|
|
data = -data;
|
2010-07-14 15:28:55 +02:00
|
|
|
runtime[0].mFloat = data;
|
2010-06-29 12:05:22 +02:00
|
|
|
}
|
2010-06-29 16:11:19 +02:00
|
|
|
};
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2010-06-29 16:11:19 +02:00
|
|
|
class OpIntToFloat1 : public Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Runtime& runtime) override
|
2010-06-29 16:11:19 +02:00
|
|
|
{
|
2010-07-14 15:28:55 +02:00
|
|
|
Type_Integer data = runtime[1].mInteger;
|
2010-06-29 16:11:19 +02:00
|
|
|
Type_Float floatValue = static_cast<Type_Float>(data);
|
2010-07-14 15:28:55 +02:00
|
|
|
runtime[1].mFloat = floatValue;
|
2010-06-29 16:11:19 +02:00
|
|
|
}
|
|
|
|
};
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2010-06-29 16:11:19 +02:00
|
|
|
class OpFloatToInt1 : public Opcode0
|
|
|
|
{
|
|
|
|
public:
|
2020-10-16 22:18:54 +04:00
|
|
|
void execute(Runtime& runtime) override
|
2010-06-29 16:11:19 +02:00
|
|
|
{
|
2010-07-14 15:28:55 +02:00
|
|
|
Type_Float data = runtime[1].mFloat;
|
2010-06-29 16:11:19 +02:00
|
|
|
Type_Integer integerValue = static_cast<Type_Integer>(data);
|
2010-07-14 15:28:55 +02:00
|
|
|
runtime[1].mInteger = integerValue;
|
2010-06-29 16:11:19 +02:00
|
|
|
}
|
|
|
|
};
|
2010-06-28 21:49:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|