Initial work on standard library
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -49,7 +49,7 @@ namespace Porygon::Evaluation{
|
||||
return new BooleanEvalValue(b);
|
||||
}
|
||||
static EvalValue* Create(const string& s){
|
||||
return new StringEvalValue(Utilities::StringUtils::StringToU16String(s));
|
||||
return new StringEvalValue(Utilities::StringUtils::ToUTF8(s));
|
||||
}
|
||||
static EvalValue* Create(u16string s){
|
||||
return new StringEvalValue(std::move(s));
|
||||
|
||||
25
src/Evaluator/EvalValues/NilEvalValue.hpp
Normal file
25
src/Evaluator/EvalValues/NilEvalValue.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef PORYGONLANG_NILEVALVALUE_HPP
|
||||
#define PORYGONLANG_NILEVALVALUE_HPP
|
||||
|
||||
#include "EvalValue.hpp"
|
||||
|
||||
namespace Porygon::Evaluation{
|
||||
class NilEvalValue : public EvalValue{
|
||||
const TypeClass GetTypeClass() const final{
|
||||
return TypeClass ::Nil;
|
||||
}
|
||||
const bool operator==(EvalValue *b) const final{
|
||||
return b->GetTypeClass() == TypeClass ::Nil;
|
||||
}
|
||||
|
||||
const shared_ptr<EvalValue> Clone() const final{
|
||||
return make_shared<NilEvalValue>();
|
||||
}
|
||||
|
||||
const std::size_t GetHashCode() const final{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //PORYGONLANG_NILEVALVALUE_HPP
|
||||
@@ -11,14 +11,14 @@ namespace Porygon::Evaluation {
|
||||
class EvaluationException : public std::exception {
|
||||
string _message;
|
||||
public:
|
||||
explicit EvaluationException(string message) {
|
||||
_message = std::move(message);
|
||||
explicit EvaluationException(const string& message) {
|
||||
_message = defaultErrorText +message;
|
||||
}
|
||||
|
||||
const string defaultErrorText = "An evaluation exception occurred: ";
|
||||
|
||||
const char *what() const noexcept final {
|
||||
return (defaultErrorText + _message).c_str();
|
||||
return _message.c_str();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
#include "EvaluationScope.hpp"
|
||||
#include "../../StandardLibraries/StaticScope.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace Porygon::Evaluation {
|
||||
@@ -29,8 +30,11 @@ namespace Porygon::Evaluation {
|
||||
}
|
||||
|
||||
shared_ptr<EvalValue> EvaluationScope::GetVariable(const BoundVariableKey *key) {
|
||||
if (key->GetScopeId() == 0) {
|
||||
auto scopeId = key -> GetScopeId();
|
||||
if (scopeId== 0) {
|
||||
return _scriptScope->at(key->GetIdentifier());
|
||||
} else if(scopeId == -2){
|
||||
return StandardLibraries::StaticScope::GetVariable(key->GetIdentifier());
|
||||
} else {
|
||||
return _localScope[key->GetHash()];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user