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 "NumericEvalValue.hpp"
|
||||||
#include "../Iterator/NumericalKeyIterator.hpp"
|
#include "../Iterator/NumericalKeyIterator.hpp"
|
||||||
|
|
||||||
Porygon::Evaluation::Iterator * Porygon::Evaluation::TableEvalValue::GetKeyIterator() const {
|
namespace Porygon::Evaluation {
|
||||||
|
Porygon::Evaluation::Iterator *Porygon::Evaluation::TableEvalValue::GetKeyIterator() const {
|
||||||
return new TableKeyIterator(this);
|
return new TableKeyIterator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Porygon::Evaluation::EvalValue *
|
Porygon::Evaluation::EvalValue *
|
||||||
Porygon::Evaluation::TableEvalValue::UnaryOperation(Porygon::Binder::BoundUnaryOperation operation) const {
|
Porygon::Evaluation::TableEvalValue::UnaryOperation(Porygon::Binder::BoundUnaryOperation operation) const {
|
||||||
if (operation == Porygon::Binder::BoundUnaryOperation::Count){
|
if (operation == Porygon::Binder::BoundUnaryOperation::Count) {
|
||||||
return new NumericEvalValue(static_cast<int64_t>(this->_table->size()));
|
return new NumericEvalValue(static_cast<int64_t>(this->_table->size()));
|
||||||
}
|
}
|
||||||
return EvalValue::UnaryOperation(operation);
|
return EvalValue::UnaryOperation(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Porygon::Evaluation::TableEvalValue::SetIndexValue(const Porygon::Utilities::HashedString *key,
|
void Porygon::Evaluation::TableEvalValue::SetIndexValue(const Porygon::Utilities::HashedString *key,
|
||||||
const Porygon::Evaluation::EvalValue *value) const {
|
const Porygon::Evaluation::EvalValue *value) const {
|
||||||
auto insert = _table->insert({*key, value});
|
auto insert = _table->insert({*key, value});
|
||||||
if (!insert.second) {
|
if (!insert.second) {
|
||||||
_table->at(*key).ClearAssign(value);
|
_table->at(*key).ClearAssign(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericTableEvalValue::GetKeyIterator() const {
|
Porygon::Evaluation::Iterator *Porygon::Evaluation::NumericTableEvalValue::GetKeyIterator() const {
|
||||||
return new NumericalKeyIterator(this);
|
return new NumericalKeyIterator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Porygon::Evaluation::EvalValue *Porygon::Evaluation::NumericTableEvalValue::Clone() const {
|
Porygon::Evaluation::EvalValue *Porygon::Evaluation::NumericTableEvalValue::Clone() const {
|
||||||
return new NumericTableEvalValue(_table, _hash);
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,8 +4,9 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "EvalValue.hpp"
|
#include "EvalValue.hpp"
|
||||||
#include "../../Utilities/Random.hpp"
|
|
||||||
#include "../EvalValuePointer.hpp"
|
#include "../EvalValuePointer.hpp"
|
||||||
|
#include "../../Utilities/Random.hpp"
|
||||||
|
#include "../../ScriptTypes/TableScriptType.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -62,6 +63,12 @@ namespace Porygon::Evaluation {
|
||||||
return this->_table->at(*hash)->Clone();
|
return this->_table->at(*hash)->Clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
inline EvalValue* IndexValue(uint32_t hash) const {
|
||||||
|
return this->_table->at(Utilities::HashedString::CreateLookup(hash))->Clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline const EvalValue* IndexValue(const char *val) const {
|
inline const EvalValue* IndexValue(const char *val) const {
|
||||||
auto hash = Utilities::HashedString::ConstHash(val);
|
auto hash = Utilities::HashedString::ConstHash(val);
|
||||||
|
@ -92,6 +99,14 @@ namespace Porygon::Evaluation {
|
||||||
[[nodiscard]] EvalValue *UnaryOperation(Binder::BoundUnaryOperation operation) const override;
|
[[nodiscard]] EvalValue *UnaryOperation(Binder::BoundUnaryOperation operation) const override;
|
||||||
|
|
||||||
void SetIndexValue(const Utilities::HashedString *key, const EvalValue *value) 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{
|
class NumericTableEvalValue : public TableEvalValue{
|
||||||
|
@ -109,6 +124,10 @@ namespace Porygon::Evaluation {
|
||||||
[[nodiscard]] Iterator *GetKeyIterator() const final;
|
[[nodiscard]] Iterator *GetKeyIterator() const final;
|
||||||
|
|
||||||
[[nodiscard]] EvalValue *Clone() const override;
|
[[nodiscard]] EvalValue *Clone() const override;
|
||||||
|
|
||||||
|
[[nodiscard]] TableScriptType::TableType GetTableType() const final{
|
||||||
|
return TableScriptType::TableType ::Numerical;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,21 @@
|
||||||
#define PORYGONLANG_TABLESCRIPTTYPE_HPP
|
#define PORYGONLANG_TABLESCRIPTTYPE_HPP
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <variant>
|
||||||
#include "../Binder/BoundVariables/BoundVariable.hpp"
|
#include "../Binder/BoundVariables/BoundVariable.hpp"
|
||||||
#include "../Exception.hpp"
|
#include "../Exception.hpp"
|
||||||
|
|
||||||
namespace Porygon{
|
namespace Porygon{
|
||||||
|
|
||||||
class TableScriptType : public ScriptType{
|
class TableScriptType : public ScriptType{
|
||||||
|
public:
|
||||||
enum TableType{
|
enum TableType{
|
||||||
Unknown,
|
Unknown,
|
||||||
Numerical,
|
Numerical,
|
||||||
StringKeyed,
|
StringKeyed,
|
||||||
Dictionary
|
Dictionary
|
||||||
};
|
};
|
||||||
|
private:
|
||||||
using ContentTypes = unordered_map<Utilities::HashedString, shared_ptr<const ScriptType>>*;
|
using ContentTypes = unordered_map<Utilities::HashedString, shared_ptr<const ScriptType>>*;
|
||||||
using KeyValueType = std::pair<shared_ptr<const ScriptType>, 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