diff --git a/sonic3air-main/Oxygen/lemonscript/source/lemon/translator/Translator.h b/sonic3air-main/Oxygen/lemonscript/source/lemon/translator/Translator.h new file mode 100644 index 00000000..00a6b05b --- /dev/null +++ b/sonic3air-main/Oxygen/lemonscript/source/lemon/translator/Translator.h @@ -0,0 +1,22 @@ +/* +* Part of the Oxygen Engine / Sonic 3 A.I.R. software distribution. +* Copyright (C) 2017-2024 by Eukaryot +* +* Published under the GNU GPLv3 open source software license, see license.txt +* or https://www.gnu.org/licenses/gpl-3.0.en.html +*/ + +#pragma once + +#include "lemon/compiler/Node.h" + + +namespace lemon +{ + class Translator + { + public: + static void translateToCpp(String& output, const BlockNode& rootNode); + static void translateToCppAndSave(std::wstring_view filename, const BlockNode& rootNode); + }; +} diff --git a/sonic3air-main/Oxygen/lemonscript/source/lemon/utility/AnyBaseValue.h b/sonic3air-main/Oxygen/lemonscript/source/lemon/utility/AnyBaseValue.h new file mode 100644 index 00000000..03324012 --- /dev/null +++ b/sonic3air-main/Oxygen/lemonscript/source/lemon/utility/AnyBaseValue.h @@ -0,0 +1,94 @@ +/* +* Part of the Oxygen Engine / Sonic 3 A.I.R. software distribution. +* Copyright (C) 2017-2024 by Eukaryot +* +* Published under the GNU GPLv3 open source software license, see license.txt +* or https://www.gnu.org/licenses/gpl-3.0.en.html +*/ + +#pragma once + +#include + + +namespace lemon +{ + + struct AnyBaseValue + { + public: + inline AnyBaseValue() {} + inline explicit AnyBaseValue(int8 value) { mUint64 = (uint64)value; } + inline explicit AnyBaseValue(uint8 value) { mUint64 = (int64)value; } + inline explicit AnyBaseValue(int16 value) { mUint64 = (uint64)value; } + inline explicit AnyBaseValue(uint16 value) { mUint64 = (int64)value; } + inline explicit AnyBaseValue(int32 value) { mUint64 = (uint64)value; } + inline explicit AnyBaseValue(uint32 value) { mUint64 = (int64)value; } + inline explicit AnyBaseValue(int64 value) { mUint64 = value; } + inline explicit AnyBaseValue(uint64 value) { mUint64 = value; } + inline explicit AnyBaseValue(bool value) { mUint64 = (uint64)value; } + inline explicit AnyBaseValue(float value) { mFloat = value; } + inline explicit AnyBaseValue(double value) { mDouble = value; } + + template T get() const { return T::INVALID; } + template void set(T value) { return T::INVALID; } + + inline void reset() { mUint64 = 0; } + + template void cast() { set(static_cast(get())); } + + private: + union + { + uint64 mUint64 = 0; + float mFloat; + double mDouble; + }; + }; + + template<> FORCE_INLINE int8 AnyBaseValue::get() const { return (int8)mUint64; } + template<> FORCE_INLINE uint8 AnyBaseValue::get() const { return (uint8)mUint64; } + template<> FORCE_INLINE int16 AnyBaseValue::get() const { return (int16)mUint64; } + template<> FORCE_INLINE uint16 AnyBaseValue::get() const { return (uint16)mUint64; } + template<> FORCE_INLINE int32 AnyBaseValue::get() const { return (int32)mUint64; } + template<> FORCE_INLINE uint32 AnyBaseValue::get() const { return (uint32)mUint64; } + template<> FORCE_INLINE int64 AnyBaseValue::get() const { return mUint64; } + template<> FORCE_INLINE uint64 AnyBaseValue::get() const { return mUint64; } + template<> FORCE_INLINE bool AnyBaseValue::get() const { return (bool)mUint64; } + template<> FORCE_INLINE float AnyBaseValue::get() const { return mFloat; } + template<> FORCE_INLINE double AnyBaseValue::get() const { return mDouble; } + template<> FORCE_INLINE AnyBaseValue AnyBaseValue::get() const { return *this; } + + template<> FORCE_INLINE void AnyBaseValue::set(int8 value) { mUint64 = (uint64)value; } + template<> FORCE_INLINE void AnyBaseValue::set(uint8 value) { mUint64 = (int64)value; } + template<> FORCE_INLINE void AnyBaseValue::set(int16 value) { mUint64 = (uint64)value; } + template<> FORCE_INLINE void AnyBaseValue::set(uint16 value) { mUint64 = (int64)value; } + template<> FORCE_INLINE void AnyBaseValue::set(int32 value) { mUint64 = (uint64)value; } + template<> FORCE_INLINE void AnyBaseValue::set(uint32 value) { mUint64 = (int64)value; } + template<> FORCE_INLINE void AnyBaseValue::set(int64 value) { mUint64 = value; } + template<> FORCE_INLINE void AnyBaseValue::set(uint64 value) { mUint64 = value; } + template<> FORCE_INLINE void AnyBaseValue::set(bool value) { mUint64 = (uint64)value; } + template<> FORCE_INLINE void AnyBaseValue::set(float value) { mFloat = value; } + template<> FORCE_INLINE void AnyBaseValue::set(double value) { mDouble = value; } + template<> FORCE_INLINE void AnyBaseValue::set(AnyBaseValue value) { *this = value; } + + + struct BaseTypeConversion + { + template + static FORCE_INLINE T convert(S value) { return AnyBaseValue(value).get(); } + }; + + template<> FORCE_INLINE int8 BaseTypeConversion::convert(int8 value) { return value; } + template<> FORCE_INLINE uint8 BaseTypeConversion::convert(uint8 value) { return value; } + template<> FORCE_INLINE int16 BaseTypeConversion::convert(int16 value) { return value; } + template<> FORCE_INLINE uint16 BaseTypeConversion::convert(uint16 value) { return value; } + template<> FORCE_INLINE int32 BaseTypeConversion::convert(int32 value) { return value; } + template<> FORCE_INLINE uint32 BaseTypeConversion::convert(uint32 value) { return value; } + template<> FORCE_INLINE int64 BaseTypeConversion::convert(int64 value) { return value; } + template<> FORCE_INLINE uint64 BaseTypeConversion::convert(uint64 value) { return value; } + template<> FORCE_INLINE float BaseTypeConversion::convert(float value) { return value; } + template<> FORCE_INLINE double BaseTypeConversion::convert(double value) { return value; } + template<> FORCE_INLINE AnyBaseValue BaseTypeConversion::convert(AnyBaseValue value) { return value; } + +} diff --git a/sonic3air-main/Oxygen/lemonscript/source/lemon/utility/FlyweightString.cpp b/sonic3air-main/Oxygen/lemonscript/source/lemon/utility/FlyweightString.cpp new file mode 100644 index 00000000..04c1773b --- /dev/null +++ b/sonic3air-main/Oxygen/lemonscript/source/lemon/utility/FlyweightString.cpp @@ -0,0 +1,78 @@ +/* +* Part of the Oxygen Engine / Sonic 3 A.I.R. software distribution. +* Copyright (C) 2017-2024 by Eukaryot +* +* Published under the GNU GPLv3 open source software license, see license.txt +* or https://www.gnu.org/licenses/gpl-3.0.en.html +*/ + +#include "lemon/pch.h" +#include "lemon/utility/FlyweightString.h" + + +namespace lemon +{ + namespace detail + { + FlyweightStringManager::FlyweightStringManager() + { + mAllocPool.setPageSize(0x20000); + } + } + + + void FlyweightString::set(uint64 hash) + { + const auto it = mManager.mEntryMap.find(hash); + mEntry = (it == mManager.mEntryMap.end()) ? nullptr : it->second; + } + + void FlyweightString::set(uint64 hash, std::string_view name) + { + using Entry = detail::FlyweightStringManager::Entry; + + Entry*& entry = mManager.mEntryMap[hash]; + if (nullptr == entry) + { + // Allocate enough memory to hold both the Entry struct and the string content + const size_t requiredSize = sizeof(Entry) + name.length(); + uint8* entryPointer = mManager.mAllocPool.allocateMemory(requiredSize); + + // Initialize the entry and data + mEntry = new (static_cast(entryPointer)) Entry(); + uint8* contentPointer = entryPointer + sizeof(Entry); + memcpy(contentPointer, name.data(), name.length()); + + mEntry->mHash = hash; + mEntry->mString = std::string_view((const char*)contentPointer, name.length()); + entry = mEntry; + } + else + { + mEntry = entry; + } + } + + void FlyweightString::set(std::string_view name) + { + set(name.empty() ? 0 : rmx::getMurmur2_64(name), name); + } + + void FlyweightString::serialize(VectorBinarySerializer& serializer) + { + if (serializer.isReading()) + { + const std::string_view stringView = serializer.readStringView(0xffff); + set(rmx::getMurmur2_64(stringView), stringView); + } + else + { + serializer.write(getString(), 0xffff); + } + } + + void FlyweightString::write(VectorBinarySerializer& serializer) const + { + serializer.write(getString(), 0xffff); + } +}