Work to add C style entry points to library that allow most functionality
This commit is contained in:
@@ -69,8 +69,8 @@ shared_ptr<StringEvalValue> Evaluator::EvaluateStringBinary(BoundBinaryExpressio
|
||||
throw;
|
||||
std::ostringstream strs;
|
||||
auto left = this -> EvaluateStringExpression(expression->GetLeft());
|
||||
strs << left->EvaluateString();
|
||||
strs << *left->EvaluateString();
|
||||
auto right = this -> EvaluateExpression(expression->GetRight());
|
||||
strs << right->EvaluateString();
|
||||
strs << *right->EvaluateString();
|
||||
return make_shared<StringEvalValue>(strs.str());
|
||||
}
|
||||
46
src/Evaluator/EvalValues/EvalValue.cpp
Normal file
46
src/Evaluator/EvalValues/EvalValue.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#import "EvalValue.hpp"
|
||||
#include <cstring>
|
||||
|
||||
extern "C" {
|
||||
TypeClass GetEvalValueTypeClass(EvalValue* v){
|
||||
return v->GetType().get()->GetClass();
|
||||
}
|
||||
|
||||
ScriptType* GetEvalValueType(EvalValue* v){
|
||||
return v->GetType().get();
|
||||
}
|
||||
|
||||
int64_t EvaluateEvalValueInteger(EvalValue* v){
|
||||
return v->EvaluateInteger();
|
||||
}
|
||||
|
||||
double EvaluateEvalValueFloat(EvalValue* v){
|
||||
return v->EvaluateFloat();
|
||||
}
|
||||
|
||||
bool EvaluateEvalValueBool(EvalValue* v){
|
||||
return v->EvaluateBool();
|
||||
}
|
||||
|
||||
const char* EvaluateEvalValueString(EvalValue* v){
|
||||
return v->EvaluateString() -> c_str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef TESTS_BUILD
|
||||
#include <catch.hpp>
|
||||
#include "../src/Script.hpp"
|
||||
|
||||
|
||||
TEST_CASE( "Evaluate String", "[integration]" ) {
|
||||
auto script = Script::Create("\"foo bar\"");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
script->Evaluate();
|
||||
auto lastValue = script->GetLastValue();
|
||||
REQUIRE(std::strcmp(EvaluateEvalValueString(lastValue), "foo bar") == 0);
|
||||
delete script;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
virtual bool EvaluateBool(){
|
||||
throw EvaluationException("Can't evaluate this EvalValue as bool.");
|
||||
}
|
||||
virtual std::string EvaluateString(){
|
||||
virtual std::string* EvaluateString(){
|
||||
throw EvaluationException("Can't evaluate this EvalValue as string.");
|
||||
}
|
||||
};
|
||||
@@ -62,12 +62,6 @@ public:
|
||||
return false;
|
||||
return this->EvaluateBool() == b->EvaluateBool();
|
||||
};
|
||||
|
||||
std::string EvaluateString() final{
|
||||
std::ostringstream strs;
|
||||
strs << _value;
|
||||
return strs.str();
|
||||
}
|
||||
};
|
||||
|
||||
#endif //PORYGONLANG_EVALVALUE_HPP
|
||||
|
||||
@@ -42,12 +42,6 @@ public:
|
||||
return _value;
|
||||
}
|
||||
|
||||
std::string EvaluateString() final{
|
||||
std::ostringstream strs;
|
||||
strs << _value;
|
||||
return strs.str();
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
return make_shared<IntegerEvalValue>(_value);
|
||||
}
|
||||
@@ -70,12 +64,6 @@ public:
|
||||
return _value;
|
||||
}
|
||||
|
||||
std::string EvaluateString() final{
|
||||
std::ostringstream strs;
|
||||
strs << _value;
|
||||
return strs.str();
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
return make_shared<FloatEvalValue>(_value);
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ public:
|
||||
bool operator ==(EvalValue* b) final{
|
||||
if (b->GetType()->GetClass() != TypeClass::String)
|
||||
return false;
|
||||
return this->_value == b->EvaluateString();
|
||||
return this->_value == *b->EvaluateString();
|
||||
};
|
||||
|
||||
string EvaluateString() final{
|
||||
return _value;
|
||||
string* EvaluateString() final{
|
||||
return &_value;
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> Clone() final{
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include "Evaluator.hpp"
|
||||
@@ -36,7 +40,7 @@ void Evaluator::EvaluateBlockStatement(BoundBlockStatement* statement) {
|
||||
|
||||
void Evaluator::EvaluateExpressionStatement(BoundExpressionStatement *statement) {
|
||||
// Save new value
|
||||
this->_scriptData->_lastValue = this -> EvaluateExpression(statement->GetExpression());
|
||||
this->_lastValue = this -> EvaluateExpression(statement->GetExpression());
|
||||
}
|
||||
|
||||
void Evaluator::EvaluateAssignmentStatement(BoundAssignmentStatement *statement) {
|
||||
@@ -169,4 +173,5 @@ shared_ptr<EvalValue> Evaluator::EvaluateFunctionCallExpression(BoundExpression*
|
||||
this->EvaluateBlockStatement(function->GetInnerBlock().get());
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ using namespace std;
|
||||
|
||||
class Evaluator {
|
||||
shared_ptr<EvalValue> _result;
|
||||
shared_ptr<EvalValue> _lastValue;
|
||||
|
||||
Script* _scriptData;
|
||||
EvaluationScope* _evaluationScope;
|
||||
@@ -57,7 +58,9 @@ public:
|
||||
return _evaluationScope;
|
||||
}
|
||||
|
||||
|
||||
EvalValue* GetLastValue(){
|
||||
return _lastValue.get();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user