Include Userdata string key in userdata object for debugging
This commit is contained in:
parent
bd054b1077
commit
629adafeaf
|
@ -23,13 +23,15 @@ namespace Porygon{
|
|||
shared_ptr<Binder::BoundScriptStatement> _boundScript;
|
||||
shared_ptr<const ScriptType> _returnType = nullptr;
|
||||
ScriptOptions* _scriptOptions;
|
||||
public:
|
||||
shared_ptr<Diagnostics::DiagnosticsHolder> Diagnostics;
|
||||
private:
|
||||
std::string _treeString;
|
||||
|
||||
explicit Script(const u16string&, ScriptOptions*);
|
||||
Script(shared_ptr<BoundScriptStatement> boundScript, shared_ptr<Diagnostics::DiagnosticsHolder> diagnostics);
|
||||
void Parse(const u16string& script);
|
||||
public:
|
||||
shared_ptr<Diagnostics::DiagnosticsHolder> Diagnostics;
|
||||
|
||||
static Script* Create(const u16string& script, ScriptOptions* = nullptr);
|
||||
static Script* Create(const string& script, ScriptOptions* = nullptr);
|
||||
|
|
|
@ -158,7 +158,7 @@ namespace Porygon::StandardLibraries {
|
|||
|
||||
public:
|
||||
static UserData::UserData* CreateUserData(){
|
||||
return new UserData::UserData({
|
||||
return new UserData::UserData(new Utilities::HashedString(new u16string(u"__math__")), {
|
||||
{
|
||||
HashedString::ConstHash("abs"),
|
||||
new UserData::UserDataField(
|
||||
|
|
|
@ -8,12 +8,12 @@ namespace Porygon::UserData{
|
|||
UserData* _ud;
|
||||
uint32_t _key;
|
||||
public:
|
||||
explicit RetrievedUserData(UserData* ud) : _ud(ud), _key(0){}
|
||||
explicit RetrievedUserData(UserData* ud) : _ud(ud), _key(ud->GetIdentifier()->GetHash()){}
|
||||
explicit RetrievedUserData(uint32_t id) : _ud(nullptr), _key(id){}
|
||||
|
||||
UserData * Get();
|
||||
|
||||
inline uint32_t GetKey() const{
|
||||
[[nodiscard]] inline uint32_t GetKey() const{
|
||||
return _key;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
namespace Porygon::UserData {
|
||||
extern "C" {
|
||||
void RegisterUserDataType(uint32_t id) {
|
||||
auto ud = new UserData({});
|
||||
UserDataStorage::RegisterType(id, ud);
|
||||
void RegisterUserDataType(char16_t * key) {
|
||||
auto hashedKey = new Utilities::HashedString(new u16string(key));
|
||||
auto ud = new UserData(hashedKey, {});
|
||||
UserDataStorage::RegisterType(hashedKey->GetHash(), ud);
|
||||
}
|
||||
|
||||
void RegisterUserDataField(uint32_t typeId, uint32_t fieldId, UserDataField *field) {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Porygon::UserData {
|
||||
class UserData {
|
||||
Utilities::HashedString* _hashedString;
|
||||
std::unordered_map<uint32_t, unique_ptr<UserDataField>> _fields;
|
||||
std::mutex _mutex;
|
||||
|
||||
|
@ -31,7 +32,8 @@ namespace Porygon::UserData {
|
|||
Evaluation::EvalValue* (*_cast)(void* obj, const ScriptType* castType);
|
||||
|
||||
public:
|
||||
explicit UserData(const std::unordered_map<uint32_t, UserDataField *>& fields)
|
||||
explicit UserData(Utilities::HashedString* hashedString, const std::unordered_map<uint32_t, UserDataField *>& fields)
|
||||
: _hashedString(hashedString), _isCastable(nullptr), _cast(nullptr)
|
||||
{
|
||||
for (auto f: fields){
|
||||
_fields.insert({f.first, unique_ptr<UserDataField>(f.second)});
|
||||
|
@ -54,6 +56,12 @@ namespace Porygon::UserData {
|
|||
delete _logicalAnd;
|
||||
delete _logicalOr;
|
||||
delete _concatenation;
|
||||
|
||||
delete _hashedString;
|
||||
}
|
||||
|
||||
Utilities::HashedString* GetIdentifier(){
|
||||
return _hashedString;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
|
|
|
@ -65,6 +65,12 @@ namespace Porygon::UserData {
|
|||
}
|
||||
return CastResult ::InvalidCast;
|
||||
}
|
||||
|
||||
[[nodiscard]] string ToString() const override {
|
||||
std::stringstream s;
|
||||
s << ScriptType::ToString() << " (" << _userData->Get()->GetIdentifier()->GetDebugString() << ")";
|
||||
return s.str();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
#ifndef PORYGONLANG_USERDATATEMPLATES_HPP
|
||||
#define PORYGONLANG_USERDATATEMPLATES_HPP
|
||||
|
||||
static std::wstring_convert<std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::little_endian>, char16_t> to_16;
|
||||
Porygon::Utilities::HashedString* Convert(const char* k){
|
||||
auto conv = new u16string(to_16.from_bytes(k));
|
||||
return new Porygon::Utilities::HashedString(conv);
|
||||
}
|
||||
/*!
|
||||
\brief Begins creating an invokable function. Make sure to call PORYGON_USERDATA_END after this.
|
||||
\returns The start of an invokable function with the name __createUserData. This can be called to return a userdata object.
|
||||
*/
|
||||
#define PORYGON_USERDATA_START(type) \
|
||||
#define PORYGON_USERDATA_START(key, type) \
|
||||
using T_USERDATA = type; \
|
||||
static Porygon::UserData::UserData* __createUserData(){ \
|
||||
return new Porygon::UserData::UserData({ \
|
||||
return new Porygon::UserData::UserData( \
|
||||
Convert(#key), { \
|
||||
|
||||
/*!
|
||||
\brief Ends creation of invokable function to create userdata.
|
||||
|
@ -20,8 +26,8 @@
|
|||
\param fields The fields of the object.
|
||||
\returns an invokable static function with the name __createUserData. This can be called to generate a userdata object.
|
||||
*/
|
||||
#define PORYGON_USERDATA(type, fields) \
|
||||
PORYGON_USERDATA_START(type) \
|
||||
#define PORYGON_USERDATA(key, type, fields) \
|
||||
PORYGON_USERDATA_START(key, type) \
|
||||
fields \
|
||||
PORYGON_USERDATA_END()
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ private:
|
|||
}
|
||||
|
||||
public:
|
||||
PORYGON_USERDATA(UserDataTestObject,
|
||||
PORYGON_USERDATA(testObject, UserDataTestObject,
|
||||
PORYGON_INTEGER_FIELD(foo)
|
||||
PORYGON_READONLY_INTEGER_FIELD(readonly)
|
||||
PORYGON_INTEGER_FUNCTION(getFoo)
|
||||
|
|
Loading…
Reference in New Issue