2019-06-17 16:35:12 +00:00
|
|
|
|
2019-05-21 10:59:15 +00:00
|
|
|
#ifndef PORYGONLANG_SCRIPT_HPP
|
|
|
|
#define PORYGONLANG_SCRIPT_HPP
|
|
|
|
|
2019-06-05 15:46:46 +00:00
|
|
|
#include <utility>
|
2019-05-21 10:59:15 +00:00
|
|
|
#include <string>
|
2019-06-23 13:58:14 +00:00
|
|
|
#include <map>
|
2019-06-06 17:01:54 +00:00
|
|
|
#include "Diagnostics/DiagnosticsHolder.hpp"
|
2019-05-21 18:59:26 +00:00
|
|
|
#include "Binder/BoundStatements/BoundStatement.hpp"
|
2019-05-23 16:50:09 +00:00
|
|
|
#include "Evaluator/Evaluator.hpp"
|
2019-05-24 17:14:30 +00:00
|
|
|
#include "Evaluator/EvalValues/EvalValue.hpp"
|
2019-05-28 15:49:03 +00:00
|
|
|
#include "Utilities/HashedString.hpp"
|
2019-08-10 09:55:45 +00:00
|
|
|
#include "ScriptOptions.hpp"
|
2019-05-21 10:59:15 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2019-06-17 16:35:12 +00:00
|
|
|
using namespace Porygon::Evaluation;
|
2019-05-21 10:59:15 +00:00
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
namespace Porygon{
|
|
|
|
class Script {
|
|
|
|
Evaluator* _evaluator;
|
2019-07-27 15:59:42 +00:00
|
|
|
map<Utilities::HashedString, EvalValuePointer>* _scriptVariables;
|
2019-08-11 10:32:18 +00:00
|
|
|
unordered_map<Utilities::HashedString, shared_ptr<ScriptType>>* _scriptTypes;
|
2019-06-24 13:33:29 +00:00
|
|
|
shared_ptr<Binder::BoundScriptStatement> _boundScript;
|
2019-08-10 14:45:15 +00:00
|
|
|
shared_ptr<const ScriptType> _returnType = nullptr;
|
2019-08-10 09:55:45 +00:00
|
|
|
ScriptOptions* _scriptOptions;
|
2019-09-07 10:12:37 +00:00
|
|
|
std::string _treeString;
|
2019-05-23 16:50:09 +00:00
|
|
|
|
2019-08-24 13:12:09 +00:00
|
|
|
explicit Script(const u16string&, ScriptOptions*);
|
2019-06-24 13:35:25 +00:00
|
|
|
Script(shared_ptr<BoundScriptStatement> boundScript, shared_ptr<Diagnostics::DiagnosticsHolder> diagnostics);
|
2019-06-17 16:35:12 +00:00
|
|
|
void Parse(const u16string& script);
|
|
|
|
public:
|
2019-06-24 13:33:29 +00:00
|
|
|
shared_ptr<Diagnostics::DiagnosticsHolder> Diagnostics;
|
|
|
|
|
2019-08-24 13:12:09 +00:00
|
|
|
static Script* Create(const u16string& script, ScriptOptions* = nullptr);
|
|
|
|
static Script* Create(const string& script, ScriptOptions* = nullptr);
|
2019-06-24 13:33:29 +00:00
|
|
|
static Script* Clone(const Script* script);
|
2019-05-23 16:50:09 +00:00
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
~Script();
|
2019-05-21 12:15:39 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
inline shared_ptr<const ScriptType> GetReturnType(){
|
2019-06-17 16:35:12 +00:00
|
|
|
return _returnType;
|
|
|
|
}
|
2019-05-23 16:50:09 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
inline void SetReturnType(const shared_ptr<const ScriptType>& t){
|
|
|
|
_returnType = t;
|
2019-06-17 16:35:12 +00:00
|
|
|
}
|
2019-06-07 13:23:13 +00:00
|
|
|
|
2019-08-10 09:55:45 +00:00
|
|
|
[[nodiscard]] inline const ScriptOptions* GetScriptOptions() const{
|
|
|
|
if (_scriptOptions == nullptr){
|
|
|
|
return ScriptOptions::GetDefaultScriptOptions();
|
|
|
|
}
|
|
|
|
return _scriptOptions;
|
|
|
|
}
|
|
|
|
|
2019-07-27 15:59:42 +00:00
|
|
|
EvalValuePointer Evaluate();
|
2019-05-23 16:50:09 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
const EvalValue* GetVariable(const u16string& key);
|
2019-06-17 16:35:12 +00:00
|
|
|
bool HasVariable(const u16string& key);
|
2019-08-11 10:32:18 +00:00
|
|
|
shared_ptr<const ScriptType> GetVariableType(const Utilities::HashedString& key){
|
|
|
|
return _scriptTypes->at(key);
|
|
|
|
}
|
2019-05-28 15:49:03 +00:00
|
|
|
|
2019-07-27 15:59:42 +00:00
|
|
|
const EvalValue* CallFunction(const u16string& key, const vector<EvalValue*>& variables);
|
2019-06-17 16:35:12 +00:00
|
|
|
bool HasFunction(const u16string& key);
|
2019-08-10 14:45:15 +00:00
|
|
|
|
|
|
|
const map<Utilities::HashedString, EvalValuePointer>* GetScriptVariables(){
|
|
|
|
return _scriptVariables;
|
|
|
|
}
|
2019-09-07 10:12:37 +00:00
|
|
|
|
|
|
|
std::string GetTreeString();
|
2019-06-17 16:35:12 +00:00
|
|
|
};
|
2019-06-05 15:46:46 +00:00
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
}
|
2019-05-21 10:59:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_SCRIPT_HPP
|