Extern support for getting data from Table EvalValues
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
74d23530a1
commit
8dcf31cb40
|
@ -3,31 +3,52 @@
|
|||
#include "NumericEvalValue.hpp"
|
||||
#include "../Iterator/NumericalKeyIterator.hpp"
|
||||
|
||||
Porygon::Evaluation::Iterator * Porygon::Evaluation::TableEvalValue::GetKeyIterator() const {
|
||||
return new TableKeyIterator(this);
|
||||
}
|
||||
|
||||
Porygon::Evaluation::EvalValue *
|
||||
Porygon::Evaluation::TableEvalValue::UnaryOperation(Porygon::Binder::BoundUnaryOperation operation) const {
|
||||
if (operation == Porygon::Binder::BoundUnaryOperation::Count){
|
||||
return new NumericEvalValue(static_cast<int64_t>(this->_table->size()));
|
||||
namespace Porygon::Evaluation {
|
||||
Porygon::Evaluation::Iterator *Porygon::Evaluation::TableEvalValue::GetKeyIterator() const {
|
||||
return new TableKeyIterator(this);
|
||||
}
|
||||
return EvalValue::UnaryOperation(operation);
|
||||
}
|
||||
|
||||
void Porygon::Evaluation::TableEvalValue::SetIndexValue(const Porygon::Utilities::HashedString *key,
|
||||
const Porygon::Evaluation::EvalValue *value) const {
|
||||
auto insert = _table->insert({*key, value});
|
||||
if (!insert.second) {
|
||||
_table->at(*key).ClearAssign(value);
|
||||
Porygon::Evaluation::EvalValue *
|
||||
Porygon::Evaluation::TableEvalValue::UnaryOperation(Porygon::Binder::BoundUnaryOperation operation) const {
|
||||
if (operation == Porygon::Binder::BoundUnaryOperation::Count) {
|
||||
return new NumericEvalValue(static_cast<int64_t>(this->_table->size()));
|
||||
}
|
||||
return EvalValue::UnaryOperation(operation);
|
||||
}
|
||||
|
||||
void Porygon::Evaluation::TableEvalValue::SetIndexValue(const Porygon::Utilities::HashedString *key,
|
||||
const Porygon::Evaluation::EvalValue *value) const {
|
||||
auto insert = _table->insert({*key, value});
|
||||
if (!insert.second) {
|
||||
_table->at(*key).ClearAssign(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericTableEvalValue::GetKeyIterator() const {
|
||||
return new NumericalKeyIterator(this);
|
||||
}
|
||||
|
||||
Porygon::Evaluation::EvalValue *Porygon::Evaluation::NumericTableEvalValue::Clone() const {
|
||||
return new NumericTableEvalValue(_table, _hash);
|
||||
}
|
||||
|
||||
extern "C"{
|
||||
TableScriptType::TableType GetTableType(TableEvalValue* table){
|
||||
return table->GetTableType();
|
||||
}
|
||||
|
||||
size_t GetTableLength(TableEvalValue* table){
|
||||
return table->GetLength();
|
||||
}
|
||||
|
||||
EvalValue* IndexTableHash(TableEvalValue* table, uint32_t hash){
|
||||
return table->IndexValue(hash);
|
||||
}
|
||||
|
||||
EvalValue* IndexTableObj(TableEvalValue* table, EvalValue* key){
|
||||
return table->IndexValue(key->GetHashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericTableEvalValue::GetKeyIterator() const {
|
||||
return new NumericalKeyIterator(this);
|
||||
}
|
||||
|
||||
Porygon::Evaluation::EvalValue *Porygon::Evaluation::NumericTableEvalValue::Clone() const {
|
||||
return new NumericTableEvalValue(_table, _hash);
|
||||
}
|
||||
}
|
|
@ -4,8 +4,9 @@
|
|||
#include <utility>
|
||||
#include <map>
|
||||
#include "EvalValue.hpp"
|
||||
#include "../../Utilities/Random.hpp"
|
||||
#include "../EvalValuePointer.hpp"
|
||||
#include "../../Utilities/Random.hpp"
|
||||
#include "../../ScriptTypes/TableScriptType.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -62,6 +63,12 @@ namespace Porygon::Evaluation {
|
|||
return this->_table->at(*hash)->Clone();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
inline EvalValue* IndexValue(uint32_t hash) const {
|
||||
return this->_table->at(Utilities::HashedString::CreateLookup(hash))->Clone();
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
inline const EvalValue* IndexValue(const char *val) const {
|
||||
auto hash = Utilities::HashedString::ConstHash(val);
|
||||
|
@ -92,6 +99,14 @@ namespace Porygon::Evaluation {
|
|||
[[nodiscard]] EvalValue *UnaryOperation(Binder::BoundUnaryOperation operation) const override;
|
||||
|
||||
void SetIndexValue(const Utilities::HashedString *key, const EvalValue *value) const override;
|
||||
|
||||
[[nodiscard]] virtual TableScriptType::TableType GetTableType() const{
|
||||
return TableScriptType::TableType ::StringKeyed;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t GetLength() const{
|
||||
return _table->size();
|
||||
}
|
||||
};
|
||||
|
||||
class NumericTableEvalValue : public TableEvalValue{
|
||||
|
@ -109,6 +124,10 @@ namespace Porygon::Evaluation {
|
|||
[[nodiscard]] Iterator *GetKeyIterator() const final;
|
||||
|
||||
[[nodiscard]] EvalValue *Clone() const override;
|
||||
|
||||
[[nodiscard]] TableScriptType::TableType GetTableType() const final{
|
||||
return TableScriptType::TableType ::Numerical;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,19 +3,21 @@
|
|||
#define PORYGONLANG_TABLESCRIPTTYPE_HPP
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include "../Binder/BoundVariables/BoundVariable.hpp"
|
||||
#include "../Exception.hpp"
|
||||
|
||||
namespace Porygon{
|
||||
|
||||
class TableScriptType : public ScriptType{
|
||||
public:
|
||||
enum TableType{
|
||||
Unknown,
|
||||
Numerical,
|
||||
StringKeyed,
|
||||
Dictionary
|
||||
};
|
||||
|
||||
private:
|
||||
using ContentTypes = unordered_map<Utilities::HashedString, shared_ptr<const ScriptType>>*;
|
||||
using KeyValueType = std::pair<shared_ptr<const ScriptType>, shared_ptr<const ScriptType>>;
|
||||
|
||||
|
@ -173,6 +175,7 @@ namespace Porygon{
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue