started templating
Some checks failed
Microsoft C++ Code Analysis / Analyze (push) Waiting to run
CodeQL / Analyze (${{ matrix.language }}) (autobuild, c-cpp) (push) Has been cancelled

This commit is contained in:
Dennis Eichhorn 2025-03-21 01:08:09 +00:00
parent 17b803a0b6
commit 4f1cbd98f9
348 changed files with 2748 additions and 1303 deletions

View File

@ -7,8 +7,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ANIMATION_H
#define TOS_ANIMATION_H
#ifndef COMS_ANIMATION_H
#define COMS_ANIMATION_H
#include <math.h>
#include "../stdlib/Types.h"

View File

@ -7,8 +7,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ANIMATION_EASE_TYPE_H
#define TOS_ANIMATION_EASE_TYPE_H
#ifndef COMS_ANIMATION_EASE_TYPE_H
#define COMS_ANIMATION_EASE_TYPE_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_CPU_INFO_C
#define TOS_ARCHITECTURE_CPU_INFO_C
#ifndef COMS_ARCHITECTURE_CPU_INFO_C
#define COMS_ARCHITECTURE_CPU_INFO_C
#include "CpuInfo.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_CPU_INFO_H
#define TOS_ARCHITECTURE_CPU_INFO_H
#ifndef COMS_ARCHITECTURE_CPU_INFO_H
#define COMS_ARCHITECTURE_CPU_INFO_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_INTRINSICS_H
#define TOS_ARCHITECTURE_INTRINSICS_H
#ifndef COMS_ARCHITECTURE_INTRINSICS_H
#define COMS_ARCHITECTURE_INTRINSICS_H
#if ARM
#include "arm/Intrinsics.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_ARM_CPU_INFO_C
#define TOS_ARCHITECTURE_ARM_CPU_INFO_C
#ifndef COMS_ARCHITECTURE_ARM_CPU_INFO_C
#define COMS_ARCHITECTURE_ARM_CPU_INFO_C
#include <stdio.h>
#include <stdint.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_ARM_INTRINSICS_ARM_H
#define TOS_ARCHITECTURE_ARM_INTRINSICS_ARM_H
#ifndef COMS_ARCHITECTURE_ARM_INTRINSICS_ARM_H
#define COMS_ARCHITECTURE_ARM_INTRINSICS_ARM_H
#include <arm_sve.h>
#include <arm_acle.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_ARM_NEON_UTILS_H
#define TOS_ARCHITECTURE_ARM_NEON_UTILS_H
#ifndef COMS_ARCHITECTURE_ARM_NEON_UTILS_H
#define COMS_ARCHITECTURE_ARM_NEON_UTILS_H
#include <stdlib.h>
#include "../../../../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_ARM_SVE_UTILS_H
#define TOS_ARCHITECTURE_ARM_SVE_UTILS_H
#ifndef COMS_ARCHITECTURE_ARM_SVE_UTILS_H
#define COMS_ARCHITECTURE_ARM_SVE_UTILS_H
#include <stdlib.h>
#include "../../../../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_X86_CPU_INFO_C
#define TOS_ARCHITECTURE_X86_CPU_INFO_C
#ifndef COMS_ARCHITECTURE_X86_CPU_INFO_C
#define COMS_ARCHITECTURE_X86_CPU_INFO_C
#include <stdio.h>
#include <stdint.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_X86_INTRINSICS_H
#define TOS_ARCHITECTURE_X86_INTRINSICS_H
#ifndef COMS_ARCHITECTURE_X86_INTRINSICS_H
#define COMS_ARCHITECTURE_X86_INTRINSICS_H
#include <immintrin.h>
#include <xmmintrin.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_STDLIB_SIMD_F32_H
#define TOS_STDLIB_SIMD_F32_H
#ifndef COMS_STDLIB_SIMD_F32_H
#define COMS_STDLIB_SIMD_F32_H
#include <immintrin.h>
#include <xmmintrin.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_STDLIB_SIMD_F64_H
#define TOS_STDLIB_SIMD_F64_H
#ifndef COMS_STDLIB_SIMD_F64_H
#define COMS_STDLIB_SIMD_F64_H
#include <immintrin.h>
#include <xmmintrin.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_TOS_STDLIB_SIMD_I16_H
#define TOS_TOS_STDLIB_SIMD_I16_H
#ifndef COMS_TOS_STDLIB_SIMD_I16_H
#define COMS_TOS_STDLIB_SIMD_I16_H
#include <immintrin.h>
#include <xmmintrin.h>
@ -242,30 +242,6 @@ inline int16_32 operator*(int16_32 a, int16_32 b)
return simd;
}
inline int16_8 operator/(int16_8 a, int16_8 b)
{
int16_8 simd;
simd.s = _mm_div_epi16(a.s, b.s);
return simd;
}
inline int16_16 operator/(int16_16 a, int16_16 b)
{
int16_16 simd;
simd.s = _mm256_div_epi16(a.s, b.s);
return simd;
}
inline int16_32 operator/(int16_32 a, int16_32 b)
{
int16_32 simd;
simd.s = _mm512_div_epi16(a.s, b.s);
return simd;
}
inline int16_8 operator^(int16_8 a, int16_8 b)
{
int16_8 simd;
@ -353,27 +329,6 @@ inline int16_32 &operator*=(int16_32 &a, int16_32 b)
return a;
}
inline int16_8 &operator/=(int16_8 &a, int16_8 b)
{
a.s = (a / b).s;
return a;
}
inline int16_16 &operator/=(int16_16 &a, int16_16 b)
{
a.s = (a / b).s;
return a;
}
inline int16_32 &operator/=(int16_32 &a, int16_32 b)
{
a.s = (a / b).s;
return a;
}
inline int16_8 &operator^=(int16_8 &a, int16_8 b)
{
a = a ^ b;

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_TOS_STDLIB_SIMD_I32_H
#define TOS_TOS_STDLIB_SIMD_I32_H
#ifndef COMS_TOS_STDLIB_SIMD_I32_H
#define COMS_TOS_STDLIB_SIMD_I32_H
#include <immintrin.h>
#include <xmmintrin.h>
@ -1582,25 +1582,11 @@ bool str_compare_avx512(const char* str1, const char* str2) {
}
void
endian_swap(const int* val, int* result, int32 size, int32 steps)
endian_swap(const int32* val, int32* result, int32 size, int32 steps)
{
int32 i = 0;
if (steps == 16) {
const __m512i mask_512 = _mm512_setr_epi8(
3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12,
19, 18, 17, 16, 23, 22, 21, 20, 27, 26, 25, 24, 31, 30, 29, 28,
35, 34, 33, 32, 39, 38, 37, 36, 43, 42, 41, 40, 47, 46, 45, 44,
51, 50, 49, 48, 55, 54, 53, 60, 59, 58, 57, 56, 64, 63, 62, 61
);
for (i = 0; i <= size - steps; i += steps) {
__m512i vec = _mm512_load_si512((const __m512i *) (val + i));
vec = _mm512_shuffle_epi8(vec, mask_512);
_mm512_storeu_si512((__m512i *) (result + i), vec);
}
} else if (steps == 8) {
if (steps >= 8) {
const __m256i mask_256 = _mm256_setr_epi8(
3, 2, 1, 0, 7, 6, 5, 4,
11, 10, 9, 8, 15, 14, 13, 12,
@ -1639,6 +1625,122 @@ endian_swap(const int* val, int* result, int32 size, int32 steps)
}
}
void
endian_swap(const uint32* val, uint32* result, int32 size, int32 steps)
{
int32 i = 0;
if (steps >= 8) {
const __m256i mask_256 = _mm256_setr_epi8(
3, 2, 1, 0, 7, 6, 5, 4,
11, 10, 9, 8, 15, 14, 13, 12,
19, 18, 17, 16, 23, 22, 21, 20,
27, 26, 25, 24, 31, 30, 29, 28
);
for (i = 0; i <= size - steps; i += steps) {
__m256i vec = _mm256_load_si256((const __m256i *) (val + i));
vec = _mm256_shuffle_epi8(vec, mask_256);
_mm256_storeu_si256((__m256i *) (result + i), vec);
}
} else if (steps == 4) {
const __m128i mask_128 = _mm_setr_epi8(
3, 2, 1, 0,
7, 6, 5, 4,
11, 10, 9, 8,
15, 14, 13, 12
);
for (i = 0; i <= size - steps; i += steps) {
__m128i vec = _mm_load_si128((__m128i *) (const __m128i *) (val + i));
vec = _mm_shuffle_epi8(vec, mask_128);
_mm_storeu_si128((__m128i *) (result + i), vec);
}
}
for (; i < size; ++i) {
uint32 v = ((uint32 *) val)[i];
((uint32 *) result)[i] = ((v << 24)
| ((v & 0xFF00) << 8)
| ((v >> 8) & 0xFF00)
| (v >> 24));
}
}
void endian_swap(const int16* val, int16* result, int32 size, int32 steps)
{
int32 i = 0;
if (steps >= 8) {
const __m256i mask_256 = _mm256_setr_epi8(
1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14,
17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30
);
for (i = 0; i <= size - steps; i += steps) {
__m256i vec = _mm256_load_si256((const __m256i *) (val + i));
vec = _mm256_shuffle_epi8(vec, mask_256);
_mm256_storeu_si256((__m256i *) (result + i), vec);
}
} else if (steps == 4) {
const __m128i mask_128 = _mm_setr_epi8(
1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
);
for (i = 0; i <= size - steps; i += steps) {
__m128i vec = _mm_load_si128((const __m128i *) (val + i));
vec = _mm_shuffle_epi8(vec, mask_128);
_mm_storeu_si128((__m128i *) (result + i), vec);
}
}
// Handle remaining elements
for (; i < size; ++i) {
uint16 v = ((uint16 *) val)[i];
((int16 *) result)[i] = ((v << 8) | (v >> 8));
}
}
void endian_swap(const uint16* val, uint16* result, int32 size, int32 steps)
{
int32 i = 0;
if (steps >= 8) {
const __m256i mask_256 = _mm256_setr_epi8(
1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14,
17, 16, 19, 18, 21, 20, 23, 22, 25, 24, 27, 26, 29, 28, 31, 30
);
for (i = 0; i <= size - steps; i += steps) {
__m256i vec = _mm256_load_si256((const __m256i *) (val + i));
vec = _mm256_shuffle_epi8(vec, mask_256);
_mm256_storeu_si256((__m256i *) (result + i), vec);
}
} else if (steps == 4) {
const __m128i mask_128 = _mm_setr_epi8(
1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14
);
for (i = 0; i <= size - steps; i += steps) {
__m128i vec = _mm_load_si128((const __m128i *) (val + i));
vec = _mm_shuffle_epi8(vec, mask_128);
_mm_storeu_si128((__m128i *) (result + i), vec);
}
}
// Handle remaining elements
for (; i < size; ++i) {
uint16 v = ((uint16 *) val)[i];
((uint16 *) result)[i] = ((v << 8) | (v >> 8));
}
}
#if _WIN32 || __LITTLE_ENDIAN__
#define SWAP_ENDIAN_LITTLE_SIMD(val, result, size, steps) ((void)0)
#define SWAP_ENDIAN_BIG_SIMD(val, result, size, steps) endian_swap((val), (result), (size), (steps))

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_TOS_STDLIB_SIMD_I64_H
#define TOS_TOS_STDLIB_SIMD_I64_H
#ifndef COMS_TOS_STDLIB_SIMD_I64_H
#define COMS_TOS_STDLIB_SIMD_I64_H
#include <immintrin.h>
#include <xmmintrin.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_TOS_STDLIB_SIMD_I8_H
#define TOS_TOS_STDLIB_SIMD_I8_H
#ifndef COMS_TOS_STDLIB_SIMD_I8_H
#define COMS_TOS_STDLIB_SIMD_I8_H
#include <immintrin.h>
#include <xmmintrin.h>
@ -278,30 +278,6 @@ inline int8_64 operator*(int8_64 a, int8_64 b)
return simd;
}
inline int8_16 operator/(int8_16 a, int8_16 b)
{
int8_16 simd;
simd.s = _mm_div_epi8(a.s, b.s);
return simd;
}
inline int8_32 operator/(int8_32 a, int8_32 b)
{
int8_32 simd;
simd.s = _mm256_div_epi8(a.s, b.s);
return simd;
}
inline int8_64 operator/(int8_64 a, int8_64 b)
{
int8_64 simd;
simd.s = _mm512_div_epi8(a.s, b.s);
return simd;
}
inline int8_16 operator^(int8_16 a, int8_16 b)
{
int8_16 simd;
@ -389,27 +365,6 @@ inline int8_64 &operator*=(int8_64 &a, int8_64 b)
return a;
}
inline int8_16 &operator/=(int8_16 &a, int8_16 b)
{
a.s = (a / b).s;
return a;
}
inline int8_32 &operator/=(int8_32 &a, int8_32 b)
{
a.s = (a / b).s;
return a;
}
inline int8_64 &operator/=(int8_64 &a, int8_64 b)
{
a.s = (a / b).s;
return a;
}
inline int8_16 &operator^=(int8_16 &a, int8_16 b)
{
a = a ^ b;

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_STDLIB_SIMD_SVML_H
#define TOS_STDLIB_SIMD_SVML_H
#ifndef COMS_STDLIB_SIMD_SVML_H
#define COMS_STDLIB_SIMD_SVML_H
#include <immintrin.h>
#include <xmmintrin.h>
@ -18,7 +18,7 @@
#include "math.h"
inline __m128i _mm_div_epi32(__m128i a, __m128i b) {
alignas(16) int32_t a_array[4], b_array[4], result[4];
alignas(16) int32 a_array[4], b_array[4], result[4];
_mm_storeu_si128((__m128i*) a_array, a);
_mm_storeu_si128((__m128i*) b_array, b);
@ -31,7 +31,7 @@
}
inline __m256i _mm256_div_epi32(__m256i a, __m256i b) {
alignas(32) int32_t a_array[8], b_array[8], result[8];
alignas(32) int32 a_array[8], b_array[8], result[8];
_mm256_storeu_si256((__m256i*) a_array, a);
_mm256_storeu_si256((__m256i*) b_array, b);
@ -44,7 +44,7 @@
}
inline __m512i _mm512_div_epi32(__m512i a, __m512i b) {
alignas(64) int32_t a_array[16], b_array[16], result[16];
alignas(64) int32 a_array[16], b_array[16], result[16];
_mm512_storeu_si512((__m512i*) a_array, a);
_mm512_storeu_si512((__m512i*) b_array, b);

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ARCHITECTURE_X86_UTILS_H
#define TOS_ARCHITECTURE_X86_UTILS_H
#ifndef COMS_ARCHITECTURE_X86_UTILS_H
#define COMS_ARCHITECTURE_X86_UTILS_H
#include <stdlib.h>
#include "../../../../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ASSET_H
#define TOS_ASSET_H
#ifndef COMS_ASSET_H
#define COMS_ASSET_H
#include "../stdlib/Types.h"
#include "AssetType.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ASSET_ARCHIVE_H
#define TOS_ASSET_ARCHIVE_H
#ifndef COMS_ASSET_ARCHIVE_H
#define COMS_ASSET_ARCHIVE_H
#include "../stdlib/Types.h"
#include "../utils/StringUtils.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ASSET_MANAGEMENT_SYSTEM_H
#define TOS_ASSET_MANAGEMENT_SYSTEM_H
#ifndef COMS_ASSET_MANAGEMENT_SYSTEM_H
#define COMS_ASSET_MANAGEMENT_SYSTEM_H
#include <string.h>
#include "../stdlib/Types.h"
@ -29,7 +29,7 @@ struct AssetComponent {
uint64 asset_count;
// @question Do we want to add a mutex to assets. This way we don't have to lock the entire ams.
pthread_mutex_t mutex;
coms_pthread_mutex_t mutex;
};
struct AssetManagementSystem {
@ -55,7 +55,7 @@ void ams_component_create(AssetComponent* ac, BufferMemory* buf, int32 chunk_siz
LOG_1("Create AMS Component for %n assets and %n B", {{LOG_DATA_INT32, &count}, {LOG_DATA_UINT32, &chunk_size}});
chunk_init(&ac->asset_memory, buf, count, chunk_size, 64);
pthread_mutex_init(&ac->mutex, NULL);
coms_pthread_mutex_init(&ac->mutex, NULL);
}
inline
@ -71,13 +71,13 @@ void ams_component_create(AssetComponent* ac, byte* buf, int32 chunk_size, int32
ac->asset_memory.memory = buf;
ac->asset_memory.free = (uint64 *) (ac->asset_memory.memory + ac->asset_memory.chunk_size * count);
pthread_mutex_init(&ac->mutex, NULL);
coms_pthread_mutex_init(&ac->mutex, NULL);
}
inline
void ams_component_free(AssetComponent* ac)
{
pthread_mutex_destroy(&ac->mutex);
coms_pthread_mutex_destroy(&ac->mutex);
}
inline
@ -400,15 +400,15 @@ Asset* thrd_ams_reserve_asset(AssetManagementSystem* ams, byte type, const char*
AssetComponent* ac = &ams->asset_components[type];
uint16 elements = ams_calculate_chunks(ac, size, overhead);
pthread_mutex_lock(&ams->asset_components[type].mutex);
coms_pthread_mutex_lock(&ams->asset_components[type].mutex);
int32 free_data = chunk_reserve(&ac->asset_memory, elements);
if (free_data < 0) {
pthread_mutex_unlock(&ams->asset_components[type].mutex);
coms_pthread_mutex_unlock(&ams->asset_components[type].mutex);
ASSERT_SIMPLE(free_data >= 0);
return NULL;
}
pthread_mutex_unlock(&ams->asset_components[type].mutex);
coms_pthread_mutex_unlock(&ams->asset_components[type].mutex);
byte* asset_data = chunk_get_element(&ac->asset_memory, free_data, true);
@ -514,15 +514,15 @@ Asset* thrd_ams_insert_asset(AssetManagementSystem* ams, Asset* asset_temp, cons
{
AssetComponent* ac = &ams->asset_components[asset_temp->component_id];
pthread_mutex_lock(&ams->asset_components[asset_temp->component_id].mutex);
coms_pthread_mutex_lock(&ams->asset_components[asset_temp->component_id].mutex);
int32 free_data = chunk_reserve(&ac->asset_memory, asset_temp->size);
if (free_data < 0) {
pthread_mutex_unlock(&ams->asset_components[asset_temp->component_id].mutex);
coms_pthread_mutex_unlock(&ams->asset_components[asset_temp->component_id].mutex);
ASSERT_SIMPLE(free_data >= 0);
return NULL;
}
pthread_mutex_unlock(&ams->asset_components[asset_temp->component_id].mutex);
coms_pthread_mutex_unlock(&ams->asset_components[asset_temp->component_id].mutex);
byte* asset_data = chunk_get_element(&ac->asset_memory, free_data);
memcpy(asset_data, asset_temp->self, sizeof(Asset));

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ASSET_TYPE_H
#define TOS_ASSET_TYPE_H
#ifndef COMS_ASSET_TYPE_H
#define COMS_ASSET_TYPE_H
enum AssetType : byte {
ASSET_TYPE_GENERAL,

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_AUDIO_C
#define TOS_AUDIO_C
#ifndef COMS_AUDIO_C
#define COMS_AUDIO_C
#include "../utils/StringUtils.h"
#include "../memory/RingMemory.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_AUDIO_H
#define TOS_AUDIO_H
#ifndef COMS_AUDIO_H
#define COMS_AUDIO_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_AUDIO_MIXER_H
#define TOS_AUDIO_MIXER_H
#ifndef COMS_AUDIO_MIXER_H
#define COMS_AUDIO_MIXER_H
#include "../stdlib/Types.h"
#include "Audio.h"
@ -71,7 +71,7 @@ enum AudioMixerState {
struct AudioMixer {
ChunkMemory audio_instances;
AudioMixerState state_old;
atomic_64 int32 state_new;
alignas(8) atomic_64 int32 state_new;
uint64 effect;

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_AUDIO_SETTING_H
#define TOS_AUDIO_SETTING_H
#ifndef COMS_AUDIO_SETTING_H
#define COMS_AUDIO_SETTING_H
#include "../stdlib/Types.h"
#include "../math/matrix/MatrixFloat32.h"

View File

@ -7,8 +7,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_AUDIO_QOA_H
#define TOS_AUDIO_QOA_H
#ifndef COMS_AUDIO_QOA_H
#define COMS_AUDIO_QOA_H
#include "../stdlib/Types.h"
#include "../utils/EndianUtils.h"

View File

@ -7,8 +7,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_AUDIO_QOA_H
#define TOS_AUDIO_QOA_H
#ifndef COMS_AUDIO_QOA_H
#define COMS_AUDIO_QOA_H
#include "../stdlib/Types.h"
#include "../utils/EndianUtils.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_AUDIO_WAV_H
#define TOS_AUDIO_WAV_H
#ifndef COMS_AUDIO_WAV_H
#define COMS_AUDIO_WAV_H
#include <string.h>
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_AUTH_H
#define TOS_AUTH_H
#ifndef COMS_AUTH_H
#define COMS_AUTH_H
#include <stdio.h>
#include <stdlib.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_CAMERA_H
#define TOS_CAMERA_H
#ifndef COMS_CAMERA_H
#define COMS_CAMERA_H
#include "../stdlib/Types.h"
#include "../math/matrix/MatrixFloat32.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_CAMERA_MOVEMENT_H
#define TOS_CAMERA_MOVEMENT_H
#ifndef COMS_CAMERA_MOVEMENT_H
#define COMS_CAMERA_MOVEMENT_H
enum CameraMovement {
CAMERA_MOVEMENT_NONE,

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COLOR_VISION_DEFICIENCY_H
#define TOS_COLOR_VISION_DEFICIENCY_H
#ifndef COMS_COLOR_VISION_DEFICIENCY_H
#define COMS_COLOR_VISION_DEFICIENCY_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_APP_COMMAND_BUFFER_C
#define TOS_APP_COMMAND_BUFFER_C
#ifndef COMS_APP_COMMAND_BUFFER_C
#define COMS_APP_COMMAND_BUFFER_C
/**
* The AppCmdBuffer by itself doesn't do much, it simply takes in commands and executes them.
@ -38,7 +38,7 @@ inline
void cmd_buffer_create(AppCmdBuffer* cb, BufferMemory* buf, int32 commands_count)
{
chunk_init(&cb->commands, buf, commands_count, sizeof(Command), 64);
pthread_mutex_init(&cb->mutex, NULL);
coms_pthread_mutex_init(&cb->mutex, NULL);
LOG_1("Created AppCmdBuffer: %n B", {{LOG_DATA_UINT64, &cb->commands.size}});
}
@ -181,10 +181,10 @@ Asset* cmd_font_load_async(AppCmdBuffer* __restrict cb, Command* __restrict cmd)
inline
void thrd_cmd_insert(AppCmdBuffer* __restrict cb, Command* __restrict cmd_temp)
{
pthread_mutex_lock(&cb->mutex);
coms_pthread_mutex_lock(&cb->mutex);
int32 index = chunk_reserve(&cb->commands, 1);
if (index < 0) {
pthread_mutex_unlock(&cb->mutex);
coms_pthread_mutex_unlock(&cb->mutex);
ASSERT_SIMPLE(false);
return;
@ -196,7 +196,7 @@ void thrd_cmd_insert(AppCmdBuffer* __restrict cb, Command* __restrict cmd_temp)
Command* cmd = (Command *) chunk_get_element(&cb->commands, index);
memcpy(cmd, cmd_temp, sizeof(Command));
pthread_mutex_unlock(&cb->mutex);
coms_pthread_mutex_unlock(&cb->mutex);
}
inline
@ -697,9 +697,9 @@ void cmd_iterate(AppCmdBuffer* cb)
// This shouldn't happen since the command buffer shouldn't fill up in just 1-3 frames
void thrd_cmd_iterate(AppCmdBuffer* cb)
{
pthread_mutex_lock(&cb->mutex);
coms_pthread_mutex_lock(&cb->mutex);
cmd_iterate(cb);
pthread_mutex_unlock(&cb->mutex);
coms_pthread_mutex_unlock(&cb->mutex);
}
#endif

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_APP_COMMAND_BUFFER_H
#define TOS_APP_COMMAND_BUFFER_H
#ifndef COMS_APP_COMMAND_BUFFER_H
#define COMS_APP_COMMAND_BUFFER_H
#include "../stdlib/Types.h"
#include "../memory/ChunkMemory.h"
@ -29,7 +29,7 @@ struct AppCmdBuffer {
ChunkMemory commands;
int32 last_element;
pthread_mutex_t mutex;
coms_pthread_mutex_t mutex;
// Application data for cmd access
// The list below depends on what kind of systems our command buffer needs access to

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COMMAND_H
#define TOS_COMMAND_H
#ifndef COMS_COMMAND_H
#define COMS_COMMAND_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COMPILER_COMPILER_UTILS_H
#define TOS_COMPILER_COMPILER_UTILS_H
#ifndef COMS_COMPILER_COMPILER_UTILS_H
#define COMS_COMPILER_COMPILER_UTILS_H
#include "../utils/TestUtils.h"

View File

@ -6,12 +6,14 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COMPILER_GCC_ATOMIC_H
#define TOS_COMPILER_GCC_ATOMIC_H
#ifndef COMS_COMPILER_GCC_ATOMIC_H
#define COMS_COMPILER_GCC_ATOMIC_H
#include "../../stdlib/Types.h"
#include "CompilerUtils.h"
#include <stdatomic.h>
typedef union { f32 f; int32 l; } _atomic_32;
typedef union { f64 f; int64 l; } _atomic_64;
FORCE_INLINE void atomic_set_relaxed(void** target, void* value) noexcept { __atomic_store_n(target, value, __ATOMIC_RELAXED); }
FORCE_INLINE void* atomic_get_relaxed(void** target) noexcept { return __atomic_load_n(target, __ATOMIC_RELAXED); }
@ -43,8 +45,32 @@ FORCE_INLINE void atomic_add_relaxed(volatile int32* value, int32 increment) noe
FORCE_INLINE void atomic_sub_relaxed(volatile int32* value, int32 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_RELAXED); }
FORCE_INLINE void atomic_add_relaxed(volatile int64* value, int64 increment) noexcept { __atomic_add_fetch(value, increment, __ATOMIC_RELAXED); }
FORCE_INLINE void atomic_sub_relaxed(volatile int64* value, int64 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_RELAXED); }
FORCE_INLINE f32 atomic_compare_exchange_weak_relaxed(volatile f32* value, f32* expected, f32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return *expected; }
FORCE_INLINE f64 atomic_compare_exchange_weak_relaxed(volatile f64* value, f64* expected, f64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return *expected; }
FORCE_INLINE f32 atomic_compare_exchange_weak_relaxed(volatile f32* value, f32* expected, f32 desired) noexcept {
volatile _atomic_32* value_as_union = (volatile _atomic_32*)value;
_atomic_32* expected_as_union = (_atomic_32*)expected;
_atomic_32 desired_as_union;
desired_as_union.f = desired;
__atomic_compare_exchange_n(
&value_as_union->l, &expected_as_union->l, desired_as_union.l, 0,
__ATOMIC_RELAXED, __ATOMIC_RELAXED
);
return expected_as_union->f;
}
FORCE_INLINE f64 atomic_compare_exchange_weak_relaxed(volatile f64* value, f64* expected, f64 desired) noexcept {
volatile _atomic_64* value_as_union = (volatile _atomic_64*)value;
_atomic_64* expected_as_union = (_atomic_64*)expected;
_atomic_64 desired_as_union;
desired_as_union.f = desired;
__atomic_compare_exchange_n(
&value_as_union->l, &expected_as_union->l, desired_as_union.l, 0,
__ATOMIC_RELAXED, __ATOMIC_RELAXED
);
return expected_as_union->f;
}
FORCE_INLINE int32 atomic_compare_exchange_weak_relaxed(volatile int32* value, int32* expected, int32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return *expected; }
FORCE_INLINE int64 atomic_compare_exchange_weak_relaxed(volatile int64* value, int64* expected, int64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED); return *expected; }
FORCE_INLINE int8 atomic_fetch_add_relaxed(volatile int8* value, int8 operand) noexcept { return __atomic_add_fetch(value, operand, __ATOMIC_RELAXED); }
@ -110,12 +136,7 @@ FORCE_INLINE void atomic_or_relaxed(volatile int32* value, int32 mask) noexcept
FORCE_INLINE void atomic_or_relaxed(volatile uint64* value, uint64 mask) noexcept { __atomic_fetch_or(value, mask, __ATOMIC_RELAXED); }
FORCE_INLINE void atomic_or_relaxed(volatile int64* value, int64 mask) noexcept { __atomic_fetch_or(value, mask, __ATOMIC_RELAXED); }
FORCE_INLINE void atomic_set_acquire(void** target, void* value) noexcept { __atomic_store_n(target, value, __ATOMIC_ACQUIRE); }
FORCE_INLINE void* atomic_get_acquire(void** target) noexcept { return __atomic_load_n(target, __ATOMIC_ACQUIRE); }
FORCE_INLINE void atomic_set_acquire(volatile int8* value, int8 new_value) noexcept { __atomic_store_n(value, new_value, __ATOMIC_ACQUIRE); }
FORCE_INLINE void atomic_set_acquire(volatile int16* value, int16 new_value) noexcept { __atomic_store_n(value, new_value, __ATOMIC_ACQUIRE); }
FORCE_INLINE void atomic_set_acquire(volatile int32* value, int32 new_value) noexcept { __atomic_store_n(value, new_value, __ATOMIC_ACQUIRE); }
FORCE_INLINE void atomic_set_acquire(volatile int64* value, int64 new_value) noexcept { __atomic_store_n(value, new_value, __ATOMIC_ACQUIRE); }
FORCE_INLINE int8 atomic_fetch_set_acquire(volatile int8* value, int8 new_value) noexcept { return __atomic_exchange_n(value, new_value, __ATOMIC_ACQUIRE); }
FORCE_INLINE int16 atomic_fetch_set_acquire(volatile int16* value, int16 new_value) noexcept { return __atomic_exchange_n(value, new_value, __ATOMIC_ACQUIRE); }
FORCE_INLINE int32 atomic_fetch_set_acquire(volatile int32* value, int32 new_value) noexcept { return __atomic_exchange_n(value, new_value, __ATOMIC_ACQUIRE); }
@ -140,8 +161,32 @@ FORCE_INLINE void atomic_add_acquire(volatile int32* value, int32 increment) noe
FORCE_INLINE void atomic_sub_acquire(volatile int32* value, int32 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_ACQUIRE); }
FORCE_INLINE void atomic_add_acquire(volatile int64* value, int64 increment) noexcept { __atomic_add_fetch(value, increment, __ATOMIC_ACQUIRE); }
FORCE_INLINE void atomic_sub_acquire(volatile int64* value, int64 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_ACQUIRE); }
FORCE_INLINE f32 atomic_compare_exchange_weak_acquire(volatile f32* value, f32* expected, f32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return *expected; }
FORCE_INLINE f64 atomic_compare_exchange_weak_acquire(volatile f64* value, f64* expected, f64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return *expected; }
FORCE_INLINE f32 atomic_compare_exchange_weak_acquire(volatile f32* value, f32* expected, f32 desired) noexcept {
volatile _atomic_32* value_as_union = (volatile _atomic_32*)value;
_atomic_32* expected_as_union = (_atomic_32*)expected;
_atomic_32 desired_as_union;
desired_as_union.f = desired;
__atomic_compare_exchange_n(
&value_as_union->l, &expected_as_union->l, desired_as_union.l, 0,
__ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE
);
return expected_as_union->f;
}
FORCE_INLINE f64 atomic_compare_exchange_weak_acquire(volatile f64* value, f64* expected, f64 desired) noexcept {
volatile _atomic_64* value_as_union = (volatile _atomic_64*)value;
_atomic_64* expected_as_union = (_atomic_64*)expected;
_atomic_64 desired_as_union;
desired_as_union.f = desired;
__atomic_compare_exchange_n(
&value_as_union->l, &expected_as_union->l, desired_as_union.l, 0,
__ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE
);
return expected_as_union->f;
}
FORCE_INLINE int32 atomic_compare_exchange_weak_acquire(volatile int32* value, int32* expected, int32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return *expected; }
FORCE_INLINE int64 atomic_compare_exchange_weak_acquire(volatile int64* value, int64* expected, int64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); return *expected; }
FORCE_INLINE int8 atomic_fetch_add_acquire(volatile int8* value, int8 operand) noexcept { return __atomic_add_fetch(value, operand, __ATOMIC_ACQUIRE); }
@ -237,8 +282,32 @@ FORCE_INLINE void atomic_add_release(volatile int32* value, int32 increment) noe
FORCE_INLINE void atomic_sub_release(volatile int32* value, int32 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_RELEASE); }
FORCE_INLINE void atomic_add_release(volatile int64* value, int64 increment) noexcept { __atomic_add_fetch(value, increment, __ATOMIC_RELEASE); }
FORCE_INLINE void atomic_sub_release(volatile int64* value, int64 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_RELEASE); }
FORCE_INLINE f32 atomic_compare_exchange_weak_release(volatile f32* value, f32* expected, f32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELEASE, __ATOMIC_RELEASE); return *expected; }
FORCE_INLINE f64 atomic_compare_exchange_weak_release(volatile f64* value, f64* expected, f64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELEASE, __ATOMIC_RELEASE); return *expected; }
FORCE_INLINE f32 atomic_compare_exchange_weak_release(volatile f32* value, f32* expected, f32 desired) noexcept {
volatile _atomic_32* value_as_union = (volatile _atomic_32*)value;
_atomic_32* expected_as_union = (_atomic_32*)expected;
_atomic_32 desired_as_union;
desired_as_union.f = desired;
__atomic_compare_exchange_n(
&value_as_union->l, &expected_as_union->l, desired_as_union.l, 0,
__ATOMIC_RELEASE, __ATOMIC_RELEASE
);
return expected_as_union->f;
}
FORCE_INLINE f64 atomic_compare_exchange_weak_release(volatile f64* value, f64* expected, f64 desired) noexcept {
volatile _atomic_64* value_as_union = (volatile _atomic_64*)value;
_atomic_64* expected_as_union = (_atomic_64*)expected;
_atomic_64 desired_as_union;
desired_as_union.f = desired;
__atomic_compare_exchange_n(
&value_as_union->l, &expected_as_union->l, desired_as_union.l, 0,
__ATOMIC_RELEASE, __ATOMIC_RELEASE
);
return expected_as_union->f;
}
FORCE_INLINE int32 atomic_compare_exchange_weak_release(volatile int32* value, int32* expected, int32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELEASE, __ATOMIC_RELEASE); return *expected; }
FORCE_INLINE int64 atomic_compare_exchange_weak_release(volatile int64* value, int64* expected, int64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_RELEASE, __ATOMIC_RELEASE); return *expected; }
FORCE_INLINE int8 atomic_fetch_add_release(volatile int8* value, int8 operand) noexcept { return __atomic_add_fetch(value, operand, __ATOMIC_RELEASE); }
@ -334,8 +403,32 @@ FORCE_INLINE void atomic_add_acquire_release(volatile int32* value, int32 increm
FORCE_INLINE void atomic_sub_acquire_release(volatile int32* value, int32 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_SEQ_CST); }
FORCE_INLINE void atomic_add_acquire_release(volatile int64* value, int64 increment) noexcept { __atomic_add_fetch(value, increment, __ATOMIC_SEQ_CST); }
FORCE_INLINE void atomic_sub_acquire_release(volatile int64* value, int64 decrement) noexcept { __atomic_sub_fetch(value, decrement, __ATOMIC_SEQ_CST); }
FORCE_INLINE f32 atomic_compare_exchange_weak_acquire_release(volatile f32* value, f32* expected, f32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return *expected; }
FORCE_INLINE f64 atomic_compare_exchange_weak_acquire_release(volatile f64* value, f64* expected, f64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return *expected; }
FORCE_INLINE f32 atomic_compare_exchange_weak_acquire_release(volatile f32* value, f32* expected, f32 desired) noexcept {
volatile _atomic_32* value_as_union = (volatile _atomic_32*)value;
_atomic_32* expected_as_union = (_atomic_32*)expected;
_atomic_32 desired_as_union;
desired_as_union.f = desired;
__atomic_compare_exchange_n(
&value_as_union->l, &expected_as_union->l, desired_as_union.l, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST
);
return expected_as_union->f;
}
FORCE_INLINE f64 atomic_compare_exchange_weak_acquire_release(volatile f64* value, f64* expected, f64 desired) noexcept {
volatile _atomic_64* value_as_union = (volatile _atomic_64*)value;
_atomic_64* expected_as_union = (_atomic_64*)expected;
_atomic_64 desired_as_union;
desired_as_union.f = desired;
__atomic_compare_exchange_n(
&value_as_union->l, &expected_as_union->l, desired_as_union.l, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST
);
return expected_as_union->f;
}
FORCE_INLINE int32 atomic_compare_exchange_weak_acquire_release(volatile int32* value, int32* expected, int32 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return *expected; }
FORCE_INLINE int64 atomic_compare_exchange_weak_acquire_release(volatile int64* value, int64* expected, int64 desired) noexcept { __atomic_compare_exchange_n(value, expected, desired, 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); return *expected; }
FORCE_INLINE int8 atomic_fetch_add_acquire_release(volatile int8* value, int8 operand) noexcept { return __atomic_add_fetch(value, operand, __ATOMIC_SEQ_CST); }
@ -409,5 +502,4 @@ FORCE_INLINE void atomic_or_acquire_release(volatile int64* value, int64 mask) n
// These are much faster and could accomplish what you are doing
#define atomic_fence_release() __atomic_thread_fence(__ATOMIC_RELEASE)
#endif

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COMPILER_GCC_COMPILER_UTILS_H
#define TOS_COMPILER_GCC_COMPILER_UTILS_H
#ifndef COMS_COMPILER_GCC_COMPILER_UTILS_H
#define COMS_COMPILER_GCC_COMPILER_UTILS_H
#include "../../utils/TestUtils.h"
@ -22,10 +22,10 @@
#define UNREACHABLE() __builtin_unreachable()
#endif
#define FORCE_INLINE __attribute__((always_inline))
#define FORCE_INLINE __attribute__((always_inline)) inline
#include <unistd.h>
#define compiler_debug_print(message) while (*message++) { write(STDOUT_FILENO, (message), 1); }
#define compiler_debug_print(message) ({ const char* message_temp = message; while (*message_temp) { write(STDOUT_FILENO, (message_temp++), 1); } })
#define compiler_popcount_32(data) __builtin_popcount((data))
#define compiler_popcount_64(data) __builtin_popcountl((data))
@ -42,7 +42,7 @@ int32 compiler_find_first_bit_r2l(uint64 mask) noexcept {
}
#if __LITTLE_ENDIAN__
return return 63 - __builtin_clzll(mask);
return 63 - __builtin_clzll(mask);
#else
return __builtin_ctzll(mask);
#endif
@ -66,7 +66,7 @@ int32 compiler_find_first_bit_l2r(uint64 mask) noexcept {
}
#if __LITTLE_ENDIAN__
return return 63 - __builtin_clzll(mask);
return 63 - __builtin_clzll(mask);
#else
return __builtin_ctzll(mask);
#endif

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COMPILER_MSVC_COMPILER_UTILS_H
#define TOS_COMPILER_MSVC_COMPILER_UTILS_H
#ifndef COMS_COMPILER_MSVC_COMPILER_UTILS_H
#define COMS_COMPILER_MSVC_COMPILER_UTILS_H
#include "../../utils/TestUtils.h"
#include <basetsd.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COMPRESSION_HUFFMAN_H
#define TOS_COMPRESSION_HUFFMAN_H
#ifndef COMS_COMPRESSION_HUFFMAN_H
#define COMS_COMPRESSION_HUFFMAN_H
#include <stdio.h>
#include <string.h>
@ -146,7 +146,7 @@ inline
void huffman_dump(const Huffman* hf, byte* out)
{
// dump the char -> code relations as relative indices
for (int32 i = 0; i < ARRAY_COUNT(hf->code); ++i) {
for (uint32 i = 0; i < ARRAY_COUNT(hf->code); ++i) {
*((int64 *) out) = hf->code[i]
? SWAP_ENDIAN_LITTLE(hf->code[i] - hf->buffer)
: SWAP_ENDIAN_LITTLE(-1);
@ -162,7 +162,7 @@ inline
void huffman_load(Huffman* hf, const byte* in)
{
// load the char -> code relations and convert relative indices to pointers
for (int32 i = 0; i < ARRAY_COUNT(hf->code); ++i) {
for (uint32 i = 0; i < ARRAY_COUNT(hf->code); ++i) {
int64 value = SWAP_ENDIAN_LITTLE(*((int64 *) in));
in += sizeof(value);

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COMPRESSION_LZP_H
#define TOS_COMPRESSION_LZP_H
#ifndef COMS_COMPRESSION_LZP_H
#define COMS_COMPRESSION_LZP_H
#include <stdio.h>
#include <string.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_COMPRESSION_RLE_H
#define TOS_COMPRESSION_RLE_H
#ifndef COMS_COMPRESSION_RLE_H
#define COMS_COMPRESSION_RLE_H
#include <stdio.h>
#include <string.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_DATABASE_H
#define TOS_DATABASE_H
#ifndef COMS_DATABASE_H
#define COMS_DATABASE_H
#include "../stdlib/Types.h"
#include "../../EngineDependencies/sqlite/src/sqlite3.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_DATABASE_CONNECTION_H
#define TOS_DATABASE_CONNECTION_H
#ifndef COMS_DATABASE_CONNECTION_H
#define COMS_DATABASE_CONNECTION_H
#include "../stdlib/Types.h"
#include "../../EngineDependencies/sqlite/src/sqlite3.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_DATABASE_TYPE_H
#define TOS_DATABASE_TYPE_H
#ifndef COMS_DATABASE_TYPE_H
#define COMS_DATABASE_TYPE_H
enum DatabaseType {
DB_TYPE_SQLITE,

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ENCRYPTION_CEASAR_H
#define TOS_ENCRYPTION_CEASAR_H
#ifndef COMS_ENCRYPTION_CEASAR_H
#define COMS_ENCRYPTION_CEASAR_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ENCRYPTION_XOR_H
#define TOS_ENCRYPTION_XOR_H
#ifndef COMS_ENCRYPTION_XOR_H
#define COMS_ENCRYPTION_XOR_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ANIMATION_ENTITY_H
#define TOS_ANIMATION_ENTITY_H
#ifndef COMS_ANIMATION_ENTITY_H
#define COMS_ANIMATION_ENTITY_H
#include "../stdlib/Types.h"
#include "../animation/AnimationEaseType.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ENTITY_CURSOR_H
#define TOS_ENTITY_CURSOR_H
#ifndef COMS_ENTITY_CURSOR_H
#define COMS_ENTITY_CURSOR_H
#include "Entity.h"
#include "AnimationEntityComponent.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ENTITY_H
#define TOS_ENTITY_H
#ifndef COMS_ENTITY_H
#define COMS_ENTITY_H
#include "../stdlib/Types.h"
#include "../stdlib/HashMap.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ENTITY_COMPONENT_SYSTEM_H
#define TOS_ENTITY_COMPONENT_SYSTEM_H
#ifndef COMS_ENTITY_COMPONENT_SYSTEM_H
#define COMS_ENTITY_COMPONENT_SYSTEM_H
#include <string.h>
#include "../stdlib/Types.h"
@ -34,8 +34,8 @@ struct EntityComponentSystem {
uint64 component_count;
// @question Do we want to add a mutex to assets. This way we don't have to lock the entire ams.
pthread_mutex_t* entity_mutex;
pthread_mutex_t* component_mutex;
coms_pthread_mutex_t* entity_mutex;
coms_pthread_mutex_t* component_mutex;
};
inline
@ -54,7 +54,7 @@ void ecs_entity_type_create(ChunkMemory* ec, BufferMemory* buf, int32 chunk_size
ASSERT_SIMPLE(chunk_size);
chunk_init(ec, buf, count, chunk_size, 64);
//pthread_mutex_init(&ec->mutex, NULL);
//coms_pthread_mutex_init(&ec->mutex, NULL);
}
inline
@ -63,7 +63,7 @@ void ecs_component_type_create(ChunkMemory* ec, BufferMemory* buf, int32 chunk_s
ASSERT_SIMPLE(chunk_size);
chunk_init(ec, buf, count, chunk_size, 64);
//pthread_mutex_init(&ec->mutex, NULL);
//coms_pthread_mutex_init(&ec->mutex, NULL);
}
Entity* ecs_get_entity(EntityComponentSystem* ecs, int32 entity_id)

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_ENTITY_SIZE_H
#define TOS_ENTITY_SIZE_H
#ifndef COMS_ENTITY_SIZE_H
#define COMS_ENTITY_SIZE_H
enum EntitySize {
ENTITY_SIZE_32,

View File

@ -1,5 +1,5 @@
#ifndef TOS_ENVIRONMENT_GLOBE_H
#define TOS_ENVIRONMENT_GLOBE_H
#ifndef COMS_ENVIRONMENT_GLOBE_H
#define COMS_ENVIRONMENT_GLOBE_H
#include "../stdlib/Types.h"
#include <math.h>

View File

@ -1,5 +1,5 @@
#ifndef TOS_ENVIRONMENT_UNIVERSE_H
#define TOS_ENVIRONMENT_UNIVERSE_H
#ifndef COMS_ENVIRONMENT_UNIVERSE_H
#define COMS_ENVIRONMENT_UNIVERSE_H
#include "../stdlib/Types.h"

View File

@ -1,5 +1,5 @@
#ifndef TOS_ERROR_HAMMING_CODES_H
#define TOS_ERROR_HAMMING_CODES_H
#ifndef COMS_ERROR_HAMMING_CODES_H
#define COMS_ERROR_HAMMING_CODES_H
#include "../stdlib/Types.h"
#include "../utils/BitUtils.h"

View File

@ -1,5 +1,5 @@
#ifndef TOS_FONT_H
#define TOS_FONT_H
#ifndef COMS_FONT_H
#define COMS_FONT_H
#include "../stdlib/Types.h"
#include "../memory/BufferMemory.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_ANTI_ALIASING_H
#define TOS_GPUAPI_ANTI_ALIASING_H
#ifndef COMS_GPUAPI_ANTI_ALIASING_H
#define COMS_GPUAPI_ANTI_ALIASING_H
enum AntiAliasingType : byte {
ANTI_ALIASING_TYPE_NONE,

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_TYPE_H
#define TOS_GPUAPI_TYPE_H
#ifndef COMS_GPUAPI_TYPE_H
#define COMS_GPUAPI_TYPE_H
enum GpuApiType {
GPU_API_TYPE_NONE,

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_ATTRIBUTE_TYPE_H
#define TOS_GPUAPI_ATTRIBUTE_TYPE_H
#ifndef COMS_GPUAPI_ATTRIBUTE_TYPE_H
#define COMS_GPUAPI_ATTRIBUTE_TYPE_H
#include "../stdlib/Types.h"
#include "../compiler/CompilerUtils.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_RENDER_UTILS_H
#define TOS_GPUAPI_RENDER_UTILS_H
#ifndef COMS_GPUAPI_RENDER_UTILS_H
#define COMS_GPUAPI_RENDER_UTILS_H
#include <stdio.h>
#include <string.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_SHADER_TYPE_H
#define TOS_GPUAPI_SHADER_TYPE_H
#ifndef COMS_GPUAPI_SHADER_TYPE_H
#define COMS_GPUAPI_SHADER_TYPE_H
enum ShaderType {
SHADER_TYPE_NONE,

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_DIRECTX_APP_CMD_BUFFER_H
#define TOS_GPUAPI_DIRECTX_APP_CMD_BUFFER_H
#ifndef COMS_GPUAPI_DIRECTX_APP_CMD_BUFFER_H
#define COMS_GPUAPI_DIRECTX_APP_CMD_BUFFER_H
#include "../../stdlib/Types.h"
#include "../../log/PerformanceProfiler.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_DIRECTX_UTILS_H
#define TOS_GPUAPI_DIRECTX_UTILS_H
#ifndef COMS_GPUAPI_DIRECTX_UTILS_H
#define COMS_GPUAPI_DIRECTX_UTILS_H
#include "../../stdlib/Types.h"
#include <windows.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_DIRECT3D_FRAMES_IN_FLIGHT_CONTAINER_H
#define TOS_GPUAPI_DIRECT3D_FRAMES_IN_FLIGHT_CONTAINER_H
#ifndef COMS_GPUAPI_DIRECT3D_FRAMES_IN_FLIGHT_CONTAINER_H
#define COMS_GPUAPI_DIRECT3D_FRAMES_IN_FLIGHT_CONTAINER_H
#include "../../stdlib/Types.h"
#include <d3d12.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_DIRECT3D_SHADER_H
#define TOS_GPUAPI_DIRECT3D_SHADER_H
#ifndef COMS_GPUAPI_DIRECT3D_SHADER_H
#define COMS_GPUAPI_DIRECT3D_SHADER_H
#include "../../stdlib/Types.h"
#include <d3d12.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_DIRECTX_SHADER_UTILS_H
#define TOS_GPUAPI_DIRECTX_SHADER_UTILS_H
#ifndef COMS_GPUAPI_DIRECTX_SHADER_UTILS_H
#define COMS_GPUAPI_DIRECTX_SHADER_UTILS_H
#include <windows.h>
#include <d3d12.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_APP_CMD_BUFFER_H
#define TOS_GPUAPI_OPENGL_APP_CMD_BUFFER_H
#ifndef COMS_GPUAPI_OPENGL_APP_CMD_BUFFER_H
#define COMS_GPUAPI_OPENGL_APP_CMD_BUFFER_H
#include "../../stdlib/Types.h"
#include "../../log/PerformanceProfiler.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_FRAMES_IN_FLIGHT_CONTAINER_H
#define TOS_GPUAPI_OPENGL_FRAMES_IN_FLIGHT_CONTAINER_H
#ifndef COMS_GPUAPI_OPENGL_FRAMES_IN_FLIGHT_CONTAINER_H
#define COMS_GPUAPI_OPENGL_FRAMES_IN_FLIGHT_CONTAINER_H
#include "../../stdlib/Types.h"
#include "OpenglUtils.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_H
#define TOS_GPUAPI_OPENGL_H
#ifndef COMS_GPUAPI_OPENGL_H
#define COMS_GPUAPI_OPENGL_H
// Some apis require a different sign for various operations (left/right)
#define GPU_API_SIGN -1

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_DEFINES_H
#define TOS_GPUAPI_OPENGL_DEFINES_H
#ifndef COMS_GPUAPI_OPENGL_DEFINES_H
#define COMS_GPUAPI_OPENGL_DEFINES_H
#include <stdint.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_DESCRIPTOR_SET_LAYOUT_BINDING_H
#define TOS_GPUAPI_OPENGL_DESCRIPTOR_SET_LAYOUT_BINDING_H
#ifndef COMS_GPUAPI_OPENGL_DESCRIPTOR_SET_LAYOUT_BINDING_H
#define COMS_GPUAPI_OPENGL_DESCRIPTOR_SET_LAYOUT_BINDING_H
#include "../../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_LINUX_H
#define TOS_GPUAPI_OPENGL_LINUX_H
#ifndef COMS_GPUAPI_OPENGL_LINUX_H
#define COMS_GPUAPI_OPENGL_LINUX_H
typedef void type_glTexImage2DMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations);
typedef void type_glBindFramebuffer(GLenum target, GLuint framebuffer);

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_UTILS_H
#define TOS_GPUAPI_OPENGL_UTILS_H
#ifndef COMS_GPUAPI_OPENGL_UTILS_H
#define COMS_GPUAPI_OPENGL_UTILS_H
#include "../../stdlib/Types.h"
#include "../../memory/RingMemory.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_WIN32_H
#define TOS_GPUAPI_OPENGL_WIN32_H
#ifndef COMS_GPUAPI_OPENGL_WIN32_H
#define COMS_GPUAPI_OPENGL_WIN32_H
#include <windows.h>
#include "../../platform/win32/Window.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_SHADER_H
#define TOS_GPUAPI_OPENGL_SHADER_H
#ifndef COMS_GPUAPI_OPENGL_SHADER_H
#define COMS_GPUAPI_OPENGL_SHADER_H
#include "../../stdlib/Types.h"
#include "OpenglDescriptorSetLayoutBinding.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_OPENGL_SHADER_UTILS_H
#define TOS_GPUAPI_OPENGL_SHADER_UTILS_H
#ifndef COMS_GPUAPI_OPENGL_SHADER_UTILS_H
#define COMS_GPUAPI_OPENGL_SHADER_UTILS_H
#include "../../stdlib/Types.h"
#include "../../memory/RingMemory.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_VULKAN_APP_CMD_BUFFER_H
#define TOS_GPUAPI_VULKAN_APP_CMD_BUFFER_H
#ifndef COMS_GPUAPI_VULKAN_APP_CMD_BUFFER_H
#define COMS_GPUAPI_VULKAN_APP_CMD_BUFFER_H
#include "../../stdlib/Types.h"
#include "../../log/PerformanceProfiler.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_VULKAN_FRAMES_IN_FLIGHT_CONTAINER_H
#define TOS_GPUAPI_VULKAN_FRAMES_IN_FLIGHT_CONTAINER_H
#ifndef COMS_GPUAPI_VULKAN_FRAMES_IN_FLIGHT_CONTAINER_H
#define COMS_GPUAPI_VULKAN_FRAMES_IN_FLIGHT_CONTAINER_H
#include "../../stdlib/Types.h"
#include <vulkan/vulkan.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_VULKAN_SHADER_H
#define TOS_GPUAPI_VULKAN_SHADER_H
#ifndef COMS_GPUAPI_VULKAN_SHADER_H
#define COMS_GPUAPI_VULKAN_SHADER_H
#include "../../stdlib/Types.h"
#include <vulkan/vulkan.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_VULKAN_SHADER_UTILS_H
#define TOS_GPUAPI_VULKAN_SHADER_UTILS_H
#ifndef COMS_GPUAPI_VULKAN_SHADER_UTILS_H
#define COMS_GPUAPI_VULKAN_SHADER_UTILS_H
#include <vulkan/vulkan.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_GPUAPI_VULKAN_UTILS_H
#define TOS_GPUAPI_VULKAN_UTILS_H
#ifndef COMS_GPUAPI_VULKAN_UTILS_H
#define COMS_GPUAPI_VULKAN_UTILS_H
#if _WIN32
#ifndef VK_USE_PLATFORM_WIN32_KHR

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_HASH_CRC_H
#define TOS_HASH_CRC_H
#ifndef COMS_HASH_CRC_H
#define COMS_HASH_CRC_H
#include "../stdlib/Types.h"
#include "../architecture/Intrinsics.h"

View File

@ -6,18 +6,18 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_HASH_GENERAL_H
#define TOS_HASH_GENERAL_H
#ifndef COMS_HASH_GENERAL_H
#define COMS_HASH_GENERAL_H
#include "../stdlib/Types.h"
inline constexpr
inline
uint64 hash_djb2(const char* key) noexcept
{
uint64 hash = 5381;
int32 c;
while ((c = *key++)) {
while (((c = *key++))) {
hash = ((hash << 5) + hash) + c;
}
@ -30,7 +30,7 @@ uint64 hash_sdbm(const byte* key) noexcept
uint64 hash = 0;
int32 c;
while (c = *key++) {
while ((c = *key++)) {
hash = c + (hash << 6) + (hash << 16) - hash;
}
@ -43,7 +43,7 @@ uint64 hash_lose_lose(const byte* key) noexcept
uint64 hash = 0;
int32 c;
while (c = *key++) {
while ((c = *key++)) {
hash += c;
}
@ -116,7 +116,7 @@ uint32 hash_ejb(const char* str) noexcept
}
#define ROTL32(x, r) ((x) << (r)) | ((x) >> (32 - (r)))
inline constexpr
inline
uint32 hash_murmur3_32(const byte* key, size_t len, uint32 seed = 0) noexcept
{
uint32 h = seed;
@ -290,13 +290,13 @@ uint64 hash_murmur3_64(const void* key, size_t len, uint64 seed = 0) noexcept
// Seeded hash functions
////////////////////////////////////
inline constexpr
inline
uint64 hash_djb2_seeded(const char* key, int32 seed) noexcept
{
uint64 hash = 5381;
int32 c;
while ((c = *key++)) {
while (((c = *key++))) {
hash = ((hash << 5) + hash) + c;
}
@ -309,7 +309,7 @@ uint64 hash_sdbm_seeded(const char* key, int32 seed) noexcept
uint64 hash = 0;
int32 c;
while (c = *key++) {
while ((c = *key++)) {
hash = c + (hash << 6) + (hash << 16) - hash;
}
@ -322,7 +322,7 @@ uint64 hash_lose_lose_seeded(const char* key, int32 seed) noexcept
uint64 hash = 0;
int32 c;
while (c = *key++) {
while ((c = *key++)) {
hash += c;
}

View File

@ -0,0 +1,30 @@
/**
* Jingga
*
* @copyright Jingga
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef COMS_HTML_TEMPLATE_H
#define COMS_HTML_TEMPLATE_H
#include "../../stdlib/Types.h"
struct HtmlTemplate {
};
bool html_template_load_txt() {
}
void html_template_save_bin() {
}
void html_template_load_bin() {
}
#endif

View File

@ -0,0 +1,159 @@
/**
* Jingga
*
* @copyright Jingga
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef COMS_HTML_TEMPLATE_CACHE_H
#define COMS_HTML_TEMPLATE_CACHE_H
#include "../../stdlib/Types.h"
#include "../../stdlib/PerfectHashMap.h"
#include "../../memory/RingMemory.h"
#include "../../system/FileUtils.cpp"
#include "../../html/template/HtmlTemplateInterpreter.h"
struct HtmlTemplateCache {
// Contains the offsets into the cache
PerfectHashMap hm;
// the layout of the cache is as follows:
// * Perfect hash map memory which contains the offsets into this cache where the root AST node per template can be found (hash_entries)
// * Per template memory:
// * minified template string (64 byte aligned)
// * AST, with it's own values or alternatively a pointer into the template string depending on the data (32 byte aligned for EVERY AST node)
byte* cache;
// Total cache size
uint32 cache_size;
// Current position
uint32 cache_pos;
};
static
void html_template_find(const char* path, va_list args) {
char** paths = va_arg(args, char**);
uint32* path_count = va_arg(args, uint32*);
uint32* max_path_count = va_arg(args, uint32*);
RingMemory* ring = va_arg(args, RingMemory*);
if (path_count == max_path_count) {
uint32 old_max_path_count = *max_path_count;
*max_path_count += 1000;
char* new_paths = (char *) ring_get_memory(ring, (*max_path_count) * 256 * sizeof(char), 8, true);
memcpy(new_paths, *paths, old_max_path_count * 256 * sizeof(char));
*paths = new_paths;
}
str_copy_short(paths[*path_count], path, 256);
++(*path_count);
}
void html_template_cache_init(HtmlTemplateCache* cache, const char* basedir, BufferMemory* buf, RingMemory* ring) {
uint32 max_path_count = 1000;
uint32 path_count = 0;
char* paths = (char *) ring_get_memory(ring, max_path_count * 256 * sizeof(char), 8, true);
iterate_directory(basedir, ".tpl.html", html_template_find, &paths, &path_count, &max_path_count, ring);
perfect_hashmap_create(&cache->hm, path_count, sizeof(uint32), buf);
perfect_hashmap_prepare(&cache->hm, (const char**) paths, path_count, 10000, ring);
}
bool html_template_in_control_structure(const char* str, const char** controls, int32 control_length) {
for (int32 i = 0; i < control_length; ++i) {
if (str_compare(controls[i], str) == 0) {
return true;
}
}
return false;
}
void html_template_cache_load(HtmlTemplateCache* cache, const char* key, const char* str) {
char* minified = (char *) ROUND_TO_NEAREST((uintptr_t) cache->cache + (uintptr_t) cache->cache_pos, 64);
char* minified_start = minified;
static const char* CONTROL_STRUCTURE_START[] = {
"'", "\"", "<code", "<pre", "<input", "<textarea",
};
static const char* CONTROL_STRUCTURE_END[] = {
"'", "\"", "</code>", "</pre>", "/>", "</textarea>",
};
// Remove empty content to reduce template size
// We could handle this inside the lexer but the lexer itself often uses pointers into the template
// The lexer would also have to create additional tokens in that case whenever it "splits" the template due to empty text
// All-in-all let's consider this a pre-pass that we might want to move to the lexer in the future but I don't think so
int32 in_control_structure = 0;
while (*str) {
if (!in_control_structure && str_is_empty(*str)) {
++str;
str_skip_empty(&str);
}
if (!in_control_structure
&& html_template_in_control_structure(str, CONTROL_STRUCTURE_START, ARRAY_COUNT(CONTROL_STRUCTURE_START))
) {
++in_control_structure;
} else if (in_control_structure
&& html_template_in_control_structure(str, CONTROL_STRUCTURE_END, ARRAY_COUNT(CONTROL_STRUCTURE_END))
) {
--in_control_structure;
}
*minified++ = *str++;
}
cache->cache_pos += ((uintptr_t) minified - (uintptr_t) minified_start);
HtmlTemplateToken current_token = html_template_token_next((const char**) &minified_start, HTML_TEMPLATE_CONTEXT_FLAG_HTML);
HtmlTemplateContextStack context_stack = {};
HtmlTemplateContext initial_context = {};
pushContext(&context_stack, initial_context);
// @todo Instead of doing this, we want to use the cache.memory
// For this to work we need to pass the current memory position however into this function
byte* memory_start = cache->cache + cache->cache_pos;
byte* memory = memory_start;
HtmlTemplateASTNode* ast = html_template_statement_parse(
(const char**) &minified_start,
&current_token,
&context_stack,
current_token.type == TOKEN_CODE_START
? HTML_TEMPLATE_CONTEXT_FLAG_TEMPLATE
: HTML_TEMPLATE_CONTEXT_FLAG_HTML,
&memory
);
cache->cache_pos += ((uintptr_t) memory - (uintptr_t) memory_start);
ASSERT_SIMPLE(((uintptr_t) ast) % 64 == 0);
perfect_hashmap_insert(&cache->hm, key, (int32) ((uintptr_t) ast - (uintptr_t) cache->cache));
// @todo This belongs to wherever we want to output the user specified template
//interpret(ast, &context_stack);
}
static
void html_template_cache_iter(const char* path, va_list args) {
HtmlTemplateCache* cache = va_arg(args, HtmlTemplateCache*);
RingMemory* ring = va_arg(args, RingMemory*);
FileBody file = {};
file_read(path, &file, ring);
html_template_cache_load(cache, path, (const char *) file.content);
}
void html_template_cache_load_all(HtmlTemplateCache* cache, const char* basedir, RingMemory* ring) {
iterate_directory(basedir, ".tpl.html", html_template_cache_iter, cache, ring);
}
#endif

View File

@ -0,0 +1,42 @@
/**
* Jingga
*
* @copyright Jingga
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef COMS_HTML_TEMPLATE_CONTEXT_H
#define COMS_HTML_TEMPLATE_CONTEXT_H
#include "../../stdlib/Types.h"
#include "../../utils/TestUtils.h"
struct HtmlTemplateContext {
int32 scope_level;
int32 loop_nesting_level;
};
#define MAX_STACK_SIZE 2400
struct HtmlTemplateContextStack {
HtmlTemplateContext stack[MAX_STACK_SIZE];
int32 top;
};
void pushContext(HtmlTemplateContextStack* stack, HtmlTemplateContext context) {
ASSERT_SIMPLE(stack->top < MAX_STACK_SIZE);
stack->stack[stack->top++] = context;
}
HtmlTemplateContext popContext(HtmlTemplateContextStack* stack) {
ASSERT_SIMPLE(stack->top > 0);
return stack->stack[--stack->top];
}
HtmlTemplateContext peekContext(HtmlTemplateContextStack* stack) {
ASSERT_SIMPLE(stack->top > 0);
return stack->stack[stack->top - 1];
}
#endif

View File

@ -0,0 +1,297 @@
/**
* Jingga
*
* @copyright Jingga
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef COMS_HTML_TEMPLATE_INTERPRETER_H
#define COMS_HTML_TEMPLATE_INTERPRETER_H
#include "HtmlTemplateContext.h"
#include "HtmlTemplateParser.h"
#include "../../utils/StringUtils.h"
#define MAX_VARIABLES 1000
enum HtmlTemplateValueType : byte {
VALUE_BOOL,
VALUE_INTEGER64,
VALUE_FLOAT64,
VALUE_STRING
};
struct HtmlTemplateValue {
HtmlTemplateValueType type;
int32 value_length;
union {
bool boolValue;
int64 int64Value;
f64 f64Value;
char* ptrValue;
};
};
enum HtmlTemplateVariableType : byte {
VAR_BOOL,
VAR_INTEGER64,
VAR_FLOAT64,
VAR_STRING
};
struct HtmlTemplateVariable {
char name[32];
HtmlTemplateVariableType type;
int32 value_length;
union {
bool boolValue;
int64 int64Value;
f64 f64Value;
char* ptrValue;
};
};
HtmlTemplateVariable symbol_table[MAX_VARIABLES];
int32 symbol_table_size = 0;
HtmlTemplateValue html_template_variable_get(const char* name, HtmlTemplateContextStack*) {
for (int32 i = 0; i < symbol_table_size; i++) {
if (str_compare(symbol_table[i].name, name) == 0) {
HtmlTemplateValue result;
switch (symbol_table[i].type) {
case VAR_BOOL: {
result.type = VALUE_BOOL;
result.boolValue = symbol_table[i].boolValue;
} break;
case VAR_INTEGER64: {
result.type = VALUE_INTEGER64;
result.int64Value = symbol_table[i].int64Value;
} break;
case VAR_FLOAT64: {
result.type = VALUE_FLOAT64;
result.f64Value = symbol_table[i].f64Value;
} break;
case VAR_STRING: {
result.type = VALUE_STRING;
result.ptrValue = symbol_table[i].ptrValue;
result.value_length = symbol_table[i].value_length;
} break;
default: {
UNREACHABLE();
}
}
return result;
}
}
printf("Error: Variable %s not found\n", name);
exit(1);
}
void html_template_variable_set(const char* name, HtmlTemplateValue value, HtmlTemplateContextStack*) {
for (int32 i = 0; i < symbol_table_size; i++) {
if (str_compare(symbol_table[i].name, name) == 0) {
switch (value.type) {
case VALUE_BOOL: {
symbol_table[i].type = VAR_BOOL;
symbol_table[i].boolValue = value.boolValue;
} break;
case VALUE_INTEGER64: {
symbol_table[i].type = VAR_INTEGER64;
symbol_table[i].int64Value = value.int64Value;
} break;
case VALUE_FLOAT64: {
symbol_table[i].type = VAR_FLOAT64;
symbol_table[i].f64Value = value.f64Value;
} break;
case VALUE_STRING: {
symbol_table[i].type = VAR_STRING;
symbol_table[i].ptrValue = value.ptrValue;
symbol_table[i].value_length = value.value_length;
} break;
default:
UNREACHABLE();
}
return;
}
}
// If the variable doesn't exist, add it to the symbol table
if (symbol_table_size < MAX_VARIABLES) {
str_copy_short(symbol_table[symbol_table_size].name, name);
switch (value.type) {
case VALUE_BOOL: {
symbol_table[symbol_table_size].type = VAR_BOOL;
symbol_table[symbol_table_size].boolValue = value.boolValue;
} break;
case VALUE_INTEGER64: {
symbol_table[symbol_table_size].type = VAR_INTEGER64;
symbol_table[symbol_table_size].int64Value = value.int64Value;
} break;
case VALUE_FLOAT64: {
symbol_table[symbol_table_size].type = VAR_FLOAT64;
symbol_table[symbol_table_size].f64Value = value.f64Value;
} break;
case VALUE_STRING: {
symbol_table[symbol_table_size].type = VAR_STRING;
symbol_table[symbol_table_size].ptrValue = value.ptrValue;
symbol_table[symbol_table_size].value_length = value.value_length;
} break;
default:
UNREACHABLE();
}
++symbol_table_size;
} else {
printf("Error: Symbol table overflow\n");
exit(1);
}
}
HtmlTemplateValue html_template_expression_eval(HtmlTemplateASTNode* node, HtmlTemplateContextStack* context_stack) {
HtmlTemplateValue result;
switch (node->type) {
case NODE_INTEGER64:
result.type = VALUE_INTEGER64;
result.int64Value = node->int64Value;
return result;
case NODE_FLOAT64:
result.type = VALUE_FLOAT64;
result.f64Value = node->f64Value;
return result;
case NODE_IDENTIFIER:
return html_template_variable_get(node->ptrValue, context_stack);
case NODE_STRING:
result.type = VALUE_STRING;
result.ptrValue = node->ptrValue;
result.value_length = node->value_length;
return result;
case NODE_BINOP: {
HtmlTemplateValue leftValue = html_template_expression_eval(node->left, context_stack);
HtmlTemplateValue rightValue = html_template_expression_eval(node->right, context_stack);
if (leftValue.type == VALUE_INTEGER64 && rightValue.type == VALUE_INTEGER64) {
result.type = VALUE_INTEGER64;
if (str_compare(node->ptrValue, "+") == 0) {
result.int64Value = leftValue.int64Value + rightValue.int64Value;
} else if (str_compare(node->ptrValue, "-") == 0) {
result.int64Value = leftValue.int64Value - rightValue.int64Value;
} else if (str_compare(node->ptrValue, "*") == 0) {
result.int64Value = leftValue.int64Value * rightValue.int64Value;
} else if (str_compare(node->ptrValue, "/") == 0) {
result.int64Value = leftValue.int64Value / rightValue.int64Value;
} else {
exit(1);
}
return result;
} else if (leftValue.type == VALUE_FLOAT64 || rightValue.type == VALUE_FLOAT64) {
// Promote to double if either operand is a double
result.type = VALUE_FLOAT64;
double left = (leftValue.type == VALUE_FLOAT64) ? leftValue.f64Value : (f64)leftValue.int64Value;
f64 right = (rightValue.type == VALUE_FLOAT64) ? rightValue.f64Value : (f64)rightValue.int64Value;
if (str_compare(node->ptrValue, "+") == 0) {
result.f64Value = left + right;
} else if (str_compare(node->ptrValue, "-") == 0) {
result.f64Value = left - right;
} else if (str_compare(node->ptrValue, "*") == 0) {
result.f64Value = left * right;
} else if (str_compare(node->ptrValue, "/") == 0) {
result.f64Value = left / right;
} else {
exit(1);
}
return result;
} else {
printf("Error: Incompatible types for binary operation\n");
exit(1);
}
}
default:
printf("Error: Unknown node type in expression\n");
exit(1);
}
}
bool html_template_condition_eval(HtmlTemplateASTNode *node, HtmlTemplateContextStack *context_stack) {
if (node->type == NODE_BINOP) {
HtmlTemplateValue leftValue = html_template_expression_eval(node->left, context_stack);
HtmlTemplateValue rightValue = html_template_expression_eval(node->right, context_stack);
if (leftValue.type == VALUE_INTEGER64 && rightValue.type == VALUE_INTEGER64) {
// Integer comparison
if (str_compare(node->ptrValue, ">") == 0) {
return leftValue.int64Value > rightValue.int64Value;
} else if (str_compare(node->ptrValue, "<") == 0) {
return leftValue.int64Value < rightValue.int64Value;
} else if (str_compare(node->ptrValue, "==") == 0) {
return leftValue.int64Value == rightValue.int64Value;
} else if (str_compare(node->ptrValue, "!=") == 0) {
return leftValue.int64Value != rightValue.int64Value;
} else if (str_compare(node->ptrValue, ">=") == 0) {
return leftValue.int64Value >= rightValue.int64Value;
} else if (str_compare(node->ptrValue, "<=") == 0) {
return leftValue.int64Value <= rightValue.int64Value;
} else {
exit(1);
}
} else if (leftValue.type == VALUE_FLOAT64 || rightValue.type == VALUE_FLOAT64) {
// Promote to double for comparison
f64 left = (leftValue.type == VALUE_FLOAT64) ? leftValue.f64Value : (f64)leftValue.int64Value;
f64 right = (rightValue.type == VALUE_FLOAT64) ? rightValue.f64Value : (f64)rightValue.int64Value;
if (str_compare(node->ptrValue, ">") == 0) {
return left > right;
} else if (str_compare(node->ptrValue, "<") == 0) {
return left < right;
} else if (str_compare(node->ptrValue, "==") == 0) {
return left == right;
} else if (str_compare(node->ptrValue, "!=") == 0) {
return left != right;
} else if (str_compare(node->ptrValue, ">=") == 0) {
return left >= right;
} else if (str_compare(node->ptrValue, "<=") == 0) {
return left <= right;
} else {
exit(1);
}
} else {
printf("Error: Incompatible types for comparison\n");
exit(1);
}
} else {
printf("Error: Expected a binary operation in condition\n");
exit(1);
}
}
// @todo should take in a buffer for template output
// @performance, what if there is no template data, just html? -> a simple pointer to the resource data should be created?!
// This would maybe allow us to also return files in the future
void html_template_interpret(HtmlTemplateASTNode *node, HtmlTemplateContextStack *context_stack) {
switch (node->type) {
case NODE_ASSIGN:
// Handle assignment
break;
case NODE_IF:
// Handle if statement
html_template_interpret(node->left, context_stack); // Condition
html_template_interpret(node->right, context_stack); // Body
break;
case NODE_FOR:
// Handle for loop
html_template_interpret(node->left, context_stack); // Init
while (html_template_condition_eval(node->right->left, context_stack)) { // Condition
html_template_interpret(node->right->right, context_stack); // Body
html_template_interpret(node->right->left->right, context_stack); // Update
}
break;
default:
break;
}
}
#endif

View File

@ -0,0 +1,272 @@
/**
* Jingga
*
* @copyright Jingga
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef COMS_HTML_TEMPLATE_LEXER_H
#define COMS_HTML_TEMPLATE_LEXER_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "../../stdlib/Types.h"
#include "../../utils/StringUtils.h"
enum HtmlTemplateTokenType : byte {
TOKEN_HTML,
TOKEN_BOOL,
TOKEN_INTEGER64,
TOKEN_FLOAT64,
TOKEN_IDENTIFIER,
TOKEN_ASSIGN, // =
TOKEN_INCREMENT, // ++
TOKEN_DECREMENT, // --
TOKEN_ADD_ASSIGN, // +=
TOKEN_SUBTRACT_ASSIGN, // -=
TOKEN_MULTIPLY_ASSIGN, // *=
TOKEN_DIVIDE_ASSIGN, // /=
TOKEN_EQUALS, // ==
TOKEN_UNEQUAL, // !=
TOKEN_GREATER, // >
TOKEN_GREATER_EQUAL, // >=
TOKEN_LESSER, // <
TOKEN_LESSER_EQUAL, // <=
TOKEN_PLUS,
TOKEN_MINUS,
TOKEN_MULTIPLY,
TOKEN_DIVIDE,
TOKEN_COLON, // :
TOKEN_QUESTION, // ?
TOKEN_EXCLAMATION, // !
TOKEN_CODE_START, // <?
TOKEN_CODE_END, // ?>
TOKEN_LBRACK, // [
TOKEN_RBRACK, // ]
TOKEN_LPAREN, // (
TOKEN_RPAREN, // )
TOKEN_LBRACE, // {
TOKEN_RBRACE, // }
TOKEN_SEMICOLON, // ;
TOKEN_STRING, // "..."
TOKEN_WHILE,
TOKEN_ENDWHILE,
TOKEN_IF,
TOKEN_ENDIF,
TOKEN_ELSEIF,
TOKEN_ELSE,
TOKEN_FOR,
TOKEN_ENDFOR,
TOKEN_FOREACH,
TOKEN_ENDFOREACH,
TOKEN_EOF,
TOKEN_UNKNOWN
};
#define HTML_TEMPLATE_TOKEN_VALUE_SIZE 127
struct HtmlTemplateToken {
HtmlTemplateTokenType type;
// Normally we would actually store the value instead of a pointer
// However, since html templates can have long sections without any template code and only html
// We would rather use pointers compared to huge arrays for value storage
const char* value;
size_t length;
};
enum HtmlTemplateContextFlag {
HTML_TEMPLATE_CONTEXT_FLAG_HTML,
HTML_TEMPLATE_CONTEXT_FLAG_TEMPLATE,
};
HtmlTemplateToken html_template_token_next(const char** input, HtmlTemplateContextFlag context_flag) {
str_skip_empty(input);
HtmlTemplateToken token = { TOKEN_HTML, *input, 0 };
if (**input == '\0') {
token.type = TOKEN_EOF;
} else if (context_flag == HTML_TEMPLATE_CONTEXT_FLAG_HTML) {
// We might be in html mode or template mode
// Depending on the mode we must handle chars differently
if ((**input == '<' && **input == '?')) {
token.type = TOKEN_CODE_START;
token.length = 2;
*input += 2;
} else {
token.type = TOKEN_HTML;
// Move input along until EOF or template code is found
while (**input != '\0' && (**input != '<' || **input != '?')) {
++(*input);
++token.length;
}
}
} else if (**input == '"') {
++(*input);
token.type = TOKEN_STRING;
token.value = *input;
while (**input != '"' && **input != '\0') {
++(*input);
++token.length;
}
if (**input == '"') {
++(*input);
}
} else if (str_is_num(**input)) {
token.type = TOKEN_INTEGER64;
while (str_is_num(**input) || **input == '.') {
if (**input == '.') {
token.type = TOKEN_FLOAT64;
}
++(*input);
++token.length;
}
} else if (str_is_alpha(**input)) {
while (str_is_alphanum(**input)) {
++(*input);
++token.length;
}
if (str_compare(token.value, "if") == 0) {
token.type = TOKEN_IF;
} else if (str_compare(token.value, "endif") == 0) {
token.type = TOKEN_ENDIF;
} else if (str_compare(token.value, "elseif") == 0) {
token.type = TOKEN_ELSEIF;
} else if (str_compare(token.value, "else") == 0) {
token.type = TOKEN_ELSE;
} else if (str_compare(token.value, "for") == 0) {
token.type = TOKEN_FOR;
} else if (str_compare(token.value, "endfor") == 0) {
token.type = TOKEN_ENDFOR;
} else if (str_compare(token.value, "while") == 0) {
token.type = TOKEN_WHILE;
} else if (str_compare(token.value, "endwhile") == 0) {
token.type = TOKEN_ENDWHILE;
} else if (str_compare(token.value, "foreach") == 0) {
token.type = TOKEN_FOREACH;
} else if (str_compare(token.value, "endforeach") == 0) {
token.type = TOKEN_ENDFOREACH;
} else {
token.type = TOKEN_IDENTIFIER;
}
} else {
token.length = 1;
switch (**input) {
case '=': {
if (*input[1] == '=') {
token.type = TOKEN_EQUALS;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_ASSIGN;
}
} break;
case '!': {
if (*input[1] == '=') {
token.type = TOKEN_UNEQUAL;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_EXCLAMATION;
}
} break;
case ':': token.type = TOKEN_COLON; break;
case '?': {
if (*input[1] == '>') {
token.type = TOKEN_CODE_END;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_QUESTION;
}
} break;
case '>': {
if (*input[1] == '=') {
token.type = TOKEN_GREATER_EQUAL;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_GREATER;
}
} break;
case '<': {
if (*input[1] == '=') {
token.type = TOKEN_LESSER_EQUAL;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_LESSER;
}
} break;
case '+': {
if (*input[1] == '=') {
token.type = TOKEN_ADD_ASSIGN;
token.length = 2;
++(*input);
} else if (*input[1] == '+') {
token.type = TOKEN_INCREMENT;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_PLUS;
}
} break;
case '-': {
if (*input[1] == '=') {
token.type = TOKEN_SUBTRACT_ASSIGN;
token.length = 2;
++(*input);
} else if (*input[1] == '-') {
token.type = TOKEN_DECREMENT;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_MINUS;
}
} break;
case '*': {
if (*input[1] == '=') {
token.type = TOKEN_MULTIPLY_ASSIGN;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_MULTIPLY;
}
} break;
case '/': {
if (*input[1] == '=') {
token.type = TOKEN_DIVIDE_ASSIGN;
token.length = 2;
++(*input);
} else {
token.type = TOKEN_DIVIDE;
}
} break;
case '[': token.type = TOKEN_LBRACK; break;
case ']': token.type = TOKEN_RBRACK; break;
case '(': token.type = TOKEN_LPAREN; break;
case ')': token.type = TOKEN_RPAREN; break;
case '{': token.type = TOKEN_LBRACE; break;
case '}': token.type = TOKEN_RBRACE; break;
case ';': token.type = TOKEN_SEMICOLON; break;
default: token.type = TOKEN_UNKNOWN; break;
}
++(*input);
}
return token;
}
#endif

View File

@ -0,0 +1,246 @@
/**
* Jingga
*
* @copyright Jingga
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef COMS_HTML_TEMPLATE_PARSER_H
#define COMS_HTML_TEMPLATE_PARSER_H
#include "HtmlTemplateLexer.h"
#include "HtmlTemplateContext.h"
enum HtmlTemplateNodeType : byte {
NODE_BINOP,
NODE_PTR,
NODE_IDENTIFIER,
NODE_BOOL,
NODE_INTEGER64,
NODE_FLOAT64,
NODE_ASSIGN, // =
NODE_INCREMENT, // ++
NODE_DECREMENT, // --
NODE_ADD_ASSIGN, // +=
NODE_SUBTRACT_ASSIGN, // -=
NODE_MULTIPLY_ASSIGN, // *=
NODE_DIVIDE_ASSIGN, // /=
NODE_EQUALS, // ==
NODE_UNEQUAL, // !=
NODE_GREATER, // >
NODE_GREATER_EQUAL, // >=
NODE_LESSER, // <
NODE_LESSER_EQUAL, // <=
NODE_PLUS,
NODE_MINUS,
NODE_MULTIPLY,
NODE_DIVIDE,
NODE_COLON, // :
NODE_QUESTION, // ?
NODE_EXCLAMATION, // !
NODE_CODE_START, // <?
NODE_CODE_END, // ?>
NODE_LBRACK, // [
NODE_RBRACK, // ]
NODE_LPAREN, // (
NODE_RPAREN, // )
NODE_LBRACE, // {
NODE_RBRACE, // }
NODE_SEMICOLON, // ;
NODE_STRING, // "..."
NODE_WHILE,
NODE_ENDWHILE,
NODE_IF,
NODE_ENDIF,
NODE_ELSEIF,
NODE_ELSE,
NODE_FOR,
NODE_ENDFOR,
NODE_FOREACH,
NODE_ENDFOREACH,
};
struct HtmlTemplateASTNode {
HtmlTemplateASTNode* left;
HtmlTemplateASTNode* right;
HtmlTemplateNodeType type;
uint32 value_length;
union {
bool boolValue;
int64 int64Value;
f64 f64Value;
char* ptrValue;
};
};
HtmlTemplateASTNode* html_template_node_create(HtmlTemplateNodeType type, HtmlTemplateToken* token, byte** memory) {
*memory = (byte *) ROUND_TO_NEAREST((uintptr_t) memory, 32);
HtmlTemplateASTNode* node = (HtmlTemplateASTNode *) *memory;
*memory = (byte *) ROUND_TO_NEAREST((uintptr_t) (memory + sizeof(HtmlTemplateASTNode)), 32);
node->type = type;
node->left = NULL;
node->right = NULL;
node->value_length = token->length;
// @question instead of handling the parsing below, why not handle it here for known types such as int, float, bool, string
memcpy(&node->int64Value, token->value, sizeof(uintptr_t));
return node;
}
HtmlTemplateASTNode* html_template_factor_parse(const char**, HtmlTemplateToken*, HtmlTemplateContextFlag, byte**);
HtmlTemplateASTNode* html_template_term_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextFlag context_flag, byte** memory) {
// @bug This is wrong
HtmlTemplateASTNode* left = html_template_factor_parse(input, token_current, context_flag, memory);
while (token_current->type == TOKEN_MULTIPLY || token_current->type == TOKEN_DIVIDE) {
HtmlTemplateToken* old = token_current;
*token_current = html_template_token_next(input, context_flag);
HtmlTemplateASTNode* right = html_template_factor_parse(input, token_current, context_flag, memory);
// @bug This is wrong
left = html_template_node_create(NODE_BINOP, old, memory);
left->left = left;
left->right = right;
}
return left;
}
HtmlTemplateASTNode* html_template_expression_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextFlag context_flag, byte** memory) {
HtmlTemplateASTNode* left = html_template_term_parse(input, token_current, context_flag, memory);
while (token_current->type == TOKEN_PLUS || token_current->type == TOKEN_MINUS) {
HtmlTemplateToken* old = token_current;
*token_current = html_template_token_next(input, context_flag);
HtmlTemplateASTNode* right = html_template_term_parse(input, token_current, context_flag, memory);
left = html_template_node_create(NODE_BINOP, old, memory);
left->left = left;
left->right = right;
}
return left;
}
HtmlTemplateASTNode* html_template_factor_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextFlag context_flag, byte** memory) {
// @performance Consider to order the token types in a smart way and perform range check here
// @todo use switch
if (token_current->type == TOKEN_INTEGER64) {
HtmlTemplateASTNode* node = html_template_node_create(NODE_INTEGER64, token_current, memory);
*token_current = html_template_token_next(input, context_flag);
// @todo parse string representation of int
return node;
} else if (token_current->type == TOKEN_FLOAT64) {
HtmlTemplateASTNode* node = html_template_node_create(NODE_FLOAT64, token_current, memory);
*token_current = html_template_token_next(input, context_flag);
// @todo parse string representation of float
return node;
} else if (token_current->type == TOKEN_STRING) {
HtmlTemplateASTNode* node = html_template_node_create(NODE_STRING, token_current, memory);
*token_current = html_template_token_next(input, context_flag);
return node;
} else if (token_current->type == TOKEN_IDENTIFIER) {
HtmlTemplateASTNode* node = html_template_node_create(NODE_IDENTIFIER, token_current, memory);
*token_current = html_template_token_next(input, context_flag);
return node;
} else if (token_current->type == TOKEN_LPAREN) {
*token_current = html_template_token_next(input, context_flag); // Consume '('
HtmlTemplateASTNode* node = html_template_expression_parse(input, token_current, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume ')'
return node;
} else if (token_current->type == TOKEN_LBRACK) {
*token_current = html_template_token_next(input, context_flag); // Consume '['
HtmlTemplateASTNode* node = html_template_expression_parse(input, token_current, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume ']'
return node;
} else if (token_current->type == TOKEN_LBRACE) {
*token_current = html_template_token_next(input, context_flag); // Consume '{'
HtmlTemplateASTNode* node = html_template_expression_parse(input, token_current, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume '}'
return node;
}
ASSERT_SIMPLE(false);
return NULL;
}
HtmlTemplateASTNode* html_template_statement_parse(const char**, HtmlTemplateToken*, HtmlTemplateContextStack*, HtmlTemplateContextFlag, byte**);
HtmlTemplateASTNode* html_template_assignment_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextFlag context_flag, byte** memory) {
/*HtmlTemplateASTNode* left =*/ html_template_node_create(NODE_IDENTIFIER, token_current, memory);
*token_current = html_template_token_next(input, context_flag); // Consume identifier
*token_current = html_template_token_next(input, context_flag); // Consume '='
/*HtmlTemplateASTNode* right =*/ html_template_expression_parse(input, token_current, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume ';'
return html_template_node_create(NODE_ASSIGN, {}, memory);
}
HtmlTemplateASTNode* html_template_parse_if(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextStack* contextStack, HtmlTemplateContextFlag context_flag, byte** memory) {
HtmlTemplateContext newContext = peekContext(contextStack);
++newContext.scope_level;
pushContext(contextStack, newContext);
*token_current = html_template_token_next(input, context_flag); // Consume 'if'
*token_current = html_template_token_next(input, context_flag); // Consume '('
HtmlTemplateASTNode* condition = html_template_expression_parse(input, token_current, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume ')'
*token_current = html_template_token_next(input, context_flag); // Consume '{'
HtmlTemplateASTNode* body = html_template_statement_parse(input, token_current, contextStack, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume '}'
popContext(contextStack);
HtmlTemplateASTNode* ifNode = html_template_node_create(NODE_IF, {}, memory);
ifNode->left = condition; // Condition
ifNode->right = body; // Body
return ifNode;
}
HtmlTemplateASTNode* html_template_parse_for(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextStack* contextStack, HtmlTemplateContextFlag context_flag, byte** memory) {
HtmlTemplateContext newContext = peekContext(contextStack);
++newContext.scope_level;
++newContext.loop_nesting_level;
pushContext(contextStack, newContext);
*token_current = html_template_token_next(input, context_flag); // Consume 'for'
*token_current = html_template_token_next(input, context_flag); // Consume '('
HtmlTemplateASTNode* init = html_template_assignment_parse(input, token_current, context_flag, memory);
HtmlTemplateASTNode* condition = html_template_expression_parse(input, token_current, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume ';'
HtmlTemplateASTNode* update = html_template_assignment_parse(input, token_current, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume ')'
*token_current = html_template_token_next(input, context_flag); // Consume '{'
HtmlTemplateASTNode* body = html_template_statement_parse(input, token_current, contextStack, context_flag, memory);
*token_current = html_template_token_next(input, context_flag); // Consume '}'
popContext(contextStack);
HtmlTemplateASTNode* forNode = html_template_node_create(NODE_FOR, {}, memory);
forNode->left = init; // Initialization
forNode->right = html_template_node_create(NODE_BINOP, {}, memory);
forNode->right->left = condition; // Condition
forNode->right->right = update; // Update
forNode->right->right->right = body; // Body
return forNode;
}
HtmlTemplateASTNode* html_template_statement_parse(const char** input, HtmlTemplateToken* token_current, HtmlTemplateContextStack* contextStack, HtmlTemplateContextFlag context_flag, byte** memory) {
if (token_current->type == TOKEN_ASSIGN) {
return html_template_assignment_parse(input, token_current, context_flag, memory);
} else if (token_current->type == TOKEN_IF) {
return html_template_parse_if(input, token_current, contextStack, context_flag, memory);
} else if (token_current->type == TOKEN_FOR) {
return html_template_parse_for(input, token_current, contextStack, context_flag, memory);
} else {
exit(1);
}
}
#endif

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_IMAGE_BITMAP_H
#define TOS_IMAGE_BITMAP_H
#ifndef COMS_IMAGE_BITMAP_H
#define COMS_IMAGE_BITMAP_H
#include <stdio.h>
#include <string.h>
@ -108,16 +108,16 @@ struct DIB_BITMAPV3INFOHEADER {
};
struct TOS_CIEXYZ {
struct COMS_CIEXYZ {
int32 ciexyzX;
int32 ciexyzY;
int32 ciexyzZ;
};
struct TOS_CIEXYZTRIPLE {
TOS_CIEXYZ ciexyzRed;
TOS_CIEXYZ ciexyzGreen;
TOS_CIEXYZ ciexyzBlue;
struct COMS_CIEXYZTRIPLE {
COMS_CIEXYZ ciexyzRed;
COMS_CIEXYZ ciexyzGreen;
COMS_CIEXYZ ciexyzBlue;
};
#define DIB_BITMAP_TYPE_BITMAPV4HEADER 108
@ -139,7 +139,7 @@ struct DIB_BITMAPV4HEADER {
int32 bV4BlueMask;
int32 bV4AlphaMask;
int32 bV4CSType;
TOS_CIEXYZTRIPLE bV4Endpoints;
COMS_CIEXYZTRIPLE bV4Endpoints;
int32 bV4GammaRed;
int32 bV4GammaGreen;
int32 bV4GammaBlue;
@ -164,7 +164,7 @@ struct DIB_BITMAPV5HEADER {
int32 bV5BlueMask;
int32 bV5AlphaMask;
int32 bV5CSType;
TOS_CIEXYZTRIPLE bV5Endpoints;
COMS_CIEXYZTRIPLE bV5Endpoints;
int32 bV5GammaRed;
int32 bV5GammaGreen;
int32 bV5GammaBlue;

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_IMAGE_C
#define TOS_IMAGE_C
#ifndef COMS_IMAGE_C
#define COMS_IMAGE_C
#include "../utils/StringUtils.h"
#include "../memory/RingMemory.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_IMAGE_H
#define TOS_IMAGE_H
#ifndef COMS_IMAGE_H
#define COMS_IMAGE_H
#include "../stdlib/Types.h"

View File

@ -11,8 +11,8 @@
* zlib: https://www.ietf.org/rfc/rfc1950.txt
* deflate: https://www.ietf.org/rfc/rfc1951.txt
*/
#ifndef TOS_IMAGE_PNG_H
#define TOS_IMAGE_PNG_H
#ifndef COMS_IMAGE_PNG_H
#define COMS_IMAGE_PNG_H
#include <string.h>
#include "../stdlib/Types.h"

View File

@ -7,8 +7,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_IMAGE_QOI_H
#define TOS_IMAGE_QOI_H
#ifndef COMS_IMAGE_QOI_H
#define COMS_IMAGE_QOI_H
#include "../stdlib/Types.h"
#include <string.h>

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_IMAGE_TGA_H
#define TOS_IMAGE_TGA_H
#ifndef COMS_IMAGE_TGA_H
#define COMS_IMAGE_TGA_H
#include <string.h>
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_IMAGE_DEFAULT_COLORS_H
#define TOS_IMAGE_DEFAULT_COLORS_H
#ifndef COMS_IMAGE_DEFAULT_COLORS_H
#define COMS_IMAGE_DEFAULT_COLORS_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_PLATFORM_WIN32_INPUT_CONTROLLER_CONTROLLER_INPUT_H
#define TOS_PLATFORM_WIN32_INPUT_CONTROLLER_CONTROLLER_INPUT_H
#ifndef COMS_PLATFORM_WIN32_INPUT_CONTROLLER_CONTROLLER_INPUT_H
#define COMS_PLATFORM_WIN32_INPUT_CONTROLLER_CONTROLLER_INPUT_H
#include "../stdlib/Types.h"

View File

@ -6,8 +6,8 @@
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef TOS_PLATFORM_WIN32_INPUT_CONTROLLER_TYPE_H
#define TOS_PLATFORM_WIN32_INPUT_CONTROLLER_TYPE_H
#ifndef COMS_PLATFORM_WIN32_INPUT_CONTROLLER_TYPE_H
#define COMS_PLATFORM_WIN32_INPUT_CONTROLLER_TYPE_H
#include "../stdlib/Types.h"

Some files were not shown because too many files have changed in this diff Show More