64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
#include "EvalValue.hpp"
|
|
#include "NumericEvalValue.hpp"
|
|
#include "StringEvalValue.hpp"
|
|
#include <cstring>
|
|
|
|
namespace Porygon::Evaluation {
|
|
|
|
extern "C" {
|
|
Porygon::TypeClass GetEvalValueTypeClass(EvalValue *v) {
|
|
return v->GetTypeClass();
|
|
}
|
|
|
|
int64_t EvaluateEvalValueInteger(EvalValue *v) {
|
|
return v->EvaluateInteger();
|
|
}
|
|
|
|
double EvaluateEvalValueFloat(EvalValue *v) {
|
|
return v->EvaluateFloat();
|
|
}
|
|
|
|
bool EvaluateEvalValueBool(EvalValue *v) {
|
|
return v->EvaluateBool();
|
|
}
|
|
|
|
const char16_t *EvaluateEvalValueString(EvalValue *v) {
|
|
return v->EvaluateString()->c_str();
|
|
}
|
|
|
|
EvalValue *CreateIntegerEvalValue(long l) {
|
|
return new IntegerEvalValue(l);
|
|
}
|
|
|
|
EvalValue *CreateFloatEvalValue(double d) {
|
|
return new FloatEvalValue(d);
|
|
}
|
|
|
|
EvalValue *CreateBoolEvalValue(bool b) {
|
|
return new BooleanEvalValue(b);
|
|
}
|
|
|
|
EvalValue *CreateStringEvalValue(const char16_t *s) {
|
|
return new StringEvalValue(s);
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifdef TESTS_BUILD
|
|
#include <catch.hpp>
|
|
#include "../src/Script.hpp"
|
|
|
|
|
|
TEST_CASE( "Evaluate String", "[integration]" ) {
|
|
auto script = Porygon::Script::Create(u"\"foo bar\"");
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
script->Evaluate();
|
|
auto lastValue = script->GetLastValue();
|
|
auto s = u16string(EvaluateEvalValueString(lastValue));
|
|
REQUIRE(s == u"foo bar");
|
|
delete script;
|
|
}
|
|
|
|
|
|
#endif
|