forked from Xeeynamo/sonic-hybrid-rsdk
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
sonic3air-main/Oxygen/lemonscript/source/lemon/translator/Translator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; | ||
} |
94 changes: 94 additions & 0 deletions
94
sonic3air-main/Oxygen/lemonscript/source/lemon/utility/AnyBaseValue.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <rmxbase.h> | ||
|
||
|
||
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<typename T> T get() const { return T::INVALID; } | ||
template<typename T> void set(T value) { return T::INVALID; } | ||
|
||
inline void reset() { mUint64 = 0; } | ||
|
||
template<typename S, typename T> void cast() { set<T>(static_cast<T>(get<S>())); } | ||
|
||
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<typename S, typename T> | ||
static FORCE_INLINE T convert(S value) { return AnyBaseValue(value).get<T>(); } | ||
}; | ||
|
||
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; } | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
sonic3air-main/Oxygen/lemonscript/source/lemon/utility/FlyweightString.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void*>(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); | ||
} | ||
} |