From 1fca44fcfcc67560421ea7a64ac9a0784dc98b2e Mon Sep 17 00:00:00 2001 From: krzosa Date: Fri, 3 Jan 2025 22:14:34 +0100 Subject: [PATCH] misc --- src/app/app_wasm.c | 20 +++--- src/app/app_win32.c | 16 ++--- src/app/app_win32_opengl.c | 18 +++--- src/core/core.h | 21 +++++- src/core/core_arena.h | 10 +-- src/core/core_ctx.h | 2 +- src/core/core_lexer.c | 8 +-- src/core/core_lexer.h | 128 ++++++++++++++++++++----------------- src/core/core_math.h | 12 ++-- src/core/core_type_info.h | 120 +++++++++++++++++----------------- src/gfx2d/gfx2d.c | 3 +- 11 files changed, 190 insertions(+), 168 deletions(-) diff --git a/src/app/app_wasm.c b/src/app/app_wasm.c index 2592e3e..57df9b9 100644 --- a/src/app/app_wasm.c +++ b/src/app/app_wasm.c @@ -37,17 +37,17 @@ while (true) { */ -glb_wasm_export char wasm_temp_buff1[128] = {[127] = 0x13}; -glb_wasm_export i32 wasm_temp_buff1_len = 127; -glb_wasm_export char wasm_temp_buff2[128] = {[127] = 0x13}; -glb_wasm_export i32 wasm_temp_buff2_len = 127; +gb_wasm_export char wasm_temp_buff1[128] = {[127] = 0x13}; +gb_wasm_export i32 wasm_temp_buff1_len = 127; +gb_wasm_export char wasm_temp_buff2[128] = {[127] = 0x13}; +gb_wasm_export i32 wasm_temp_buff2_len = 127; -global f64 wasm_dpr; -global f64 wasm_delta_time; -global f64 wasm_time; -global f64 wasm_last_time; -global f64 wasm_app_init_time; -global app_event_list_t wasm_event_list; +gb f64 wasm_dpr; +gb f64 wasm_delta_time; +gb f64 wasm_time; +gb f64 wasm_last_time; +gb f64 wasm_app_init_time; +gb app_event_list_t wasm_event_list; typedef struct wasm_cached_t wasm_cached_t; struct wasm_cached_t { diff --git a/src/app/app_win32.c b/src/app/app_win32.c index 0edff4d..c2cc44a 100644 --- a/src/app/app_win32.c +++ b/src/app/app_win32.c @@ -5,19 +5,17 @@ #include "app.gen.c" #include "app_win32_opengl.c" -#include - #pragma comment(linker, "/subsystem:windows") #pragma comment(lib, "gdi32.lib") #pragma comment(lib, "user32.lib") #pragma comment(lib, "winmm.lib") -b32 w32_good_scheduling; -WNDCLASSW w32_wc; -HWND w32_window_handle; -HDC w32_dc; -b32 w32_quit_app; +gb b32 w32_good_scheduling; +gb WNDCLASSW w32_wc; +gb HWND w32_window_handle; +gb HDC w32_dc; +gb b32 w32_quit_app; fn v2f64_t w32_get_window_size(HWND window) { RECT window_rect; @@ -45,8 +43,8 @@ fn f64 w32_get_dpr(HWND window_handle) { /////////////////////////////// // event processing -app_event_list_t w32_event_list; -ma_arena_t *w32_event_arena; +gb app_event_list_t w32_event_list; +gb ma_arena_t *w32_event_arena; fn void w32_push_event(app_event_t event) { app_event_t *ev = ma_push_type(w32_event_arena, app_event_t); diff --git a/src/app/app_win32_opengl.c b/src/app/app_win32_opengl.c index 571c1b0..ed0f729 100644 --- a/src/app/app_win32_opengl.c +++ b/src/app/app_win32_opengl.c @@ -52,17 +52,17 @@ typedef BOOL MU_wglSwapIntervalEXT(int interval); #define WGL_SAMPLE_BUFFERS_ARB 0x2041 #define WGL_SAMPLES_ARB 0x2042 -global MU_wglChoosePixelFormatARB *wglChoosePixelFormatARB; -global MU_wglCreateContextAttribsARB *wglCreateContextAttribsARB; -global MU_wglSwapIntervalEXT *wglSwapIntervalEXT; +gb MU_wglChoosePixelFormatARB *wglChoosePixelFormatARB; +gb MU_wglCreateContextAttribsARB *wglCreateContextAttribsARB; +gb MU_wglSwapIntervalEXT *wglSwapIntervalEXT; -global MU_glGetProcAddress *wgl_get_proc_address; -global void *(*gl_get_proc_address)(const char *str); -global HMODULE opengl_hmodule; +gb MU_glGetProcAddress *wgl_get_proc_address; +gb void *(*gl_get_proc_address)(const char *str); +gb HMODULE opengl_hmodule; -global HGLRC(*mu_wglCreateContext)(HDC unnamedParam1); -global BOOL(*mu_wglMakeCurrent)(HDC unnamedParam1, HGLRC unnamedParam2); -global BOOL(*mu_wglDeleteContext)(HGLRC unnamedParam1); +gb HGLRC(*mu_wglCreateContext)(HDC unnamedParam1); +gb BOOL(*mu_wglMakeCurrent)(HDC unnamedParam1, HGLRC unnamedParam2); +gb BOOL(*mu_wglDeleteContext)(HGLRC unnamedParam1); // compares src string with dstlen characters from dst, returns 1 if they are equal, 0 if not fn int w32_are_strings_equal(const char *src, const char *dst, size_t dstlen) { diff --git a/src/core/core.h b/src/core/core.h index 98a9b7d..8825190 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -26,11 +26,11 @@ typedef double f64; #endif #define fn -#define global +#define gb #define locl #if PLATFORM_WASM -#define glb_wasm_export __attribute__((visibility("default"))) +#define gb_wasm_export __attribute__((visibility("default"))) #define fn_wasm_export __attribute__((visibility("default"))) #define fn_wasm_import #endif @@ -77,6 +77,23 @@ typedef double f64; #define SWAP(t, a, b) do { t PASTE(temp__, __LINE__) = a; a = b; b = PASTE(temp__, __LINE__); } while(0) #define CODE(...) #__VA_ARGS__ +#if PLATFORM_CL || (PLATFORM_CLANG && PLATFORM_WINDOWS) + #pragma section(".rdata$", read) + #define gb_read_only __declspec(allocate(".rdata$")) +#elif PLATFORM_CLANG && PLATFORM_LINUX + #define gb_read_only __attribute__((section(".rodata"))) +#else + #define gb_read_only +#endif + +#if PLATFORM_CL + #define fn_force_inline __forceinline +#elif PLATFORM_CLANG || PLATFORM_GCC + #define fn_force_inline __attribute__((always_inline)) +#else + #define fn_force_inline +#endif + #ifndef FILE_AND_LINE_GCC_FORMAT #define FILE_AND_LINE __FILE__"("STRINGIFY(__LINE__)")" #else diff --git a/src/core/core_arena.h b/src/core/core_arena.h index f60faeb..ad7907d 100644 --- a/src/core/core_arena.h +++ b/src/core/core_arena.h @@ -15,7 +15,7 @@ struct ma_arena_t { typedef struct ma_temp_t ma_temp_t; struct ma_temp_t { ma_arena_t *arena; - usize len; + usize len; }; // @@ -30,8 +30,8 @@ fn void *ma_push_size(ma_arena_t *arena, usize size); fn void *ma_push_size_ex(ma_arena_t *arena, usize size); fn ma_arena_t *ma_push_arena(ma_arena_t *allocator, usize size); fn void ma_push_arena_ex(ma_arena_t *allocator, ma_arena_t *result, usize size); -#define ma_push_type(arena, Type) (Type *)ma_push_size((arena), sizeof(Type)) -#define ma_push_array(arena, Type, count) (Type *)ma_push_size((arena), sizeof(Type) * (count)) +#define ma_push_type(arena, Type) (Type *)ma_push_size((arena), sizeof(Type)) +#define ma_push_array(arena, Type, count) (Type *)ma_push_size((arena), sizeof(Type) * (count)) // // pop @@ -50,5 +50,5 @@ fn void ma_end_temp(ma_temp_t temp); fn ma_temp_t ma_begin_scratch_ex(ma_arena_t **conflicts, int conflict_count); fn ma_temp_t ma_begin_scratch(void); fn ma_temp_t ma_begin_scratch1(ma_arena_t *conflict); -#define ma_end_scratch(x) ma_end_temp(x) -#define ma_scratch_scope(x) for (ma_temp_t x = ma_begin_scratch(); x.arena; (ma_end_temp(x), x.arena = 0)) \ No newline at end of file +#define ma_end_scratch(x) ma_end_temp(x) +#define ma_scratch_scope(x) for (ma_temp_t x = ma_begin_scratch(); x.arena; (ma_end_temp(x), x.arena = 0)) \ No newline at end of file diff --git a/src/core/core_ctx.h b/src/core/core_ctx.h index d5b49e2..9a08c24 100644 --- a/src/core/core_ctx.h +++ b/src/core/core_ctx.h @@ -5,7 +5,7 @@ struct thread_ctx_t { // I probably want to discourage using it implicitly like: tcx.perm, instead just pass it around // to functions that allocate pernament memory. temp and scratch very nicely create reusable code - // perm is basically global state so it would be nice to annotate which functions are reusable + // perm is basically gb state so it would be nice to annotate which functions are reusable // and which functions have state ma_arena_t _perm; diff --git a/src/core/core_lexer.c b/src/core/core_lexer.c index 30a44a7..6995dcb 100644 --- a/src/core/core_lexer.c +++ b/src/core/core_lexer.c @@ -257,7 +257,7 @@ fn lex_array_t lex_tokens(ma_arena_t *arena, char *file_name, s8_t stream) { return token_array; } -global s8_t global_lex_kind_simple_strings[] = { +gb_read_only s8_t lex_kind_simple_strings[] = { #define X(KIND, STR, SIMPLE) s8_const_lit(SIMPLE), LEX_KIND_XLIST #undef X @@ -265,10 +265,10 @@ global s8_t global_lex_kind_simple_strings[] = { fn s8_t lex_kind_to_simple_s8(lex_kind_t kind) { assert(kind >= 0 && kind < lex_kind_count); - return global_lex_kind_simple_strings[kind]; + return lex_kind_simple_strings[kind]; } -global s8_t global_lex_kind_strings[] = { +gb_read_only s8_t lex_kind_strings[] = { #define X(KIND, STR, SIMPLE) s8_const_lit(STR), LEX_KIND_XLIST #undef X @@ -276,7 +276,7 @@ global s8_t global_lex_kind_strings[] = { fn s8_t lex_kind_to_s8(lex_kind_t kind) { assert(kind >= 0 && kind < lex_kind_count); - return global_lex_kind_strings[kind]; + return lex_kind_strings[kind]; } fn lex_t *parser_next(parser_t *par) { diff --git a/src/core/core_lexer.h b/src/core/core_lexer.h index bc65443..de3dd9a 100644 --- a/src/core/core_lexer.h +++ b/src/core/core_lexer.h @@ -1,63 +1,63 @@ typedef enum lex_kind_t lex_kind_t; enum lex_kind_t { #define LEX_KIND_XLIST\ - X(eof, "end of file", "---")\ - X(error, "error", "---")\ - X(integer, "integer", "---")\ - X(real, "real", "---")\ - X(ident, "identifier", "---")\ - X(string, "string", "---")\ - X(comment, "comment", "---")\ - X(open_brace, "'{' open brace", "{")\ - X(close_brace, "'}' close brace", "}")\ - X(open_paren, "'(' open parenthesis", "(")\ - X(close_paren, "')' close parenthesis", ")")\ - X(open_bracket, "'[' open bracket", "[")\ - X(close_bracket, "']' close bracket", "]")\ - X(plus, "'+' plus", "+")\ - X(minus, "'-' minus", "-")\ - X(divide, "'/' division sign", "/")\ - X(multiply, "'*' multiplication sign", "*")\ - X(modulo, "'%' modulo", "%")\ - X(or, "'||' logical or", "||")\ - X(and, "'&&' logical and", "&&")\ - X(negation, "'!' logical negation", "!")\ - X(bit_negation, "'~' bit negation", "~")\ - X(bit_left_shift, "'<<' bit left shift", "<<")\ - X(bit_right_shift, "'>>' bit right shift", ">>")\ - X(bit_or, "'|' bit or", "|")\ - X(bit_and, "'&' bit and", "&")\ - X(bit_xor, "'^' bit xor", "^")\ - X(decrement, "'--' decrement", "--")\ - X(increment, "'++' increment", "++")\ - X(post_decrement, "'--' post decrement", "--")\ - X(post_increment, "'++' post increment", "++")\ - X(assign, "'=' assignment", "=")\ - X(divide_assign, "'/=' divide assignment", "/=")\ - X(multiply_assign, "'*=' multiply assignment", "*=")\ - X(plus_assign, "'+=' plus assignment", "+=")\ - X(minus_assign, "'-=' minus assignment", "-=")\ - X(modulo_assign, "'%=' modulo assignment", "%=")\ - X(bit_and_assign, "&=", "&=")\ - X(bit_or_assign, "'|=' bit or assignment", "|=")\ - X(bit_xor_assign, "'^=' bit xor assignment", "^=")\ - X(bit_left_shift_assign, "'<<=' bit left shift assignment", "<<=")\ - X(bit_right_shift_assign, "'>>=' bit right shift assignment", ">>=")\ - X(equals, "'==' equals sign", "==")\ - X(not_equals, "'!=' not equals sign", "!=")\ - X(lesser, "'<' lesser then", "<")\ - X(greater, "'>' greater then", ">")\ - X(lesser_or_equal, "'<=' lesser then or equal", "<=")\ - X(greater_or_equal, "'>=' greater then or equal", ">=")\ - X(comma, "',' comma", ",")\ - X(dot, "'.' dot", ".")\ - X(three_dots, "'...' three dots", "...")\ - X(semicolon, "';' semicolon", ";")\ - X(colon, "':' colon", ":")\ - X(arrow, "'->' arrow", "->")\ - X(question, "'?' question mark", "?")\ + X(lex_kind_eof , "end of file" , "---" )\ + X(lex_kind_error , "error" , "---" )\ + X(lex_kind_integer , "integer" , "---" )\ + X(lex_kind_real , "real" , "---" )\ + X(lex_kind_ident , "identifier" , "---" )\ + X(lex_kind_string , "string" , "---" )\ + X(lex_kind_comment , "comment" , "---" )\ + X(lex_kind_open_brace , "'{' open brace" , "{" )\ + X(lex_kind_close_brace , "'}' close brace" , "}" )\ + X(lex_kind_open_paren , "'(' open parenthesis" , "(" )\ + X(lex_kind_close_paren , "')' close parenthesis" , ")" )\ + X(lex_kind_open_bracket , "'[' open bracket" , "[" )\ + X(lex_kind_close_bracket , "']' close bracket" , "]" )\ + X(lex_kind_plus , "'+' plus" , "+" )\ + X(lex_kind_minus , "'-' minus" , "-" )\ + X(lex_kind_divide , "'/' division sign" , "/" )\ + X(lex_kind_multiply , "'*' multiplication sign" , "*" )\ + X(lex_kind_modulo , "'%' modulo" , "%" )\ + X(lex_kind_or , "'||' logical or" , "||" )\ + X(lex_kind_and , "'&&' logical and" , "&&" )\ + X(lex_kind_negation , "'!' logical negation" , "!" )\ + X(lex_kind_bit_negation , "'~' bit negation" , "~" )\ + X(lex_kind_bit_left_shift , "'<<' bit left shift" , "<<" )\ + X(lex_kind_bit_right_shift , "'>>' bit right shift" , ">>" )\ + X(lex_kind_bit_or , "'|' bit or" , "|" )\ + X(lex_kind_bit_and , "'&' bit and" , "&" )\ + X(lex_kind_bit_xor , "'^' bit xor" , "^" )\ + X(lex_kind_decrement , "'--' decrement" , "--" )\ + X(lex_kind_increment , "'++' increment" , "++" )\ + X(lex_kind_post_decrement , "'--' post decrement" , "--" )\ + X(lex_kind_post_increment , "'++' post increment" , "++" )\ + X(lex_kind_assign , "'=' assignment" , "=" )\ + X(lex_kind_divide_assign , "'/=' divide assignment" , "/=" )\ + X(lex_kind_multiply_assign , "'*=' multiply assignment" , "*=" )\ + X(lex_kind_plus_assign , "'+=' plus assignment" , "+=" )\ + X(lex_kind_minus_assign , "'-=' minus assignment" , "-=" )\ + X(lex_kind_modulo_assign , "'%=' modulo assignment" , "%=" )\ + X(lex_kind_bit_and_assign , "'&=' bit and assignment" , "&=" )\ + X(lex_kind_bit_or_assign , "'|=' bit or assignment" , "|=" )\ + X(lex_kind_bit_xor_assign , "'^=' bit xor assignment" , "^=" )\ + X(lex_kind_bit_left_shift_assign , "'<<=' bit left shift assignment" , "<<=" )\ + X(lex_kind_bit_right_shift_assign , "'>>=' bit right shift assignment" , ">>=" )\ + X(lex_kind_equals , "'==' equals sign" , "==" )\ + X(lex_kind_not_equals , "'!=' not equals sign" , "!=" )\ + X(lex_kind_lesser , "'<' lesser then" , "<" )\ + X(lex_kind_greater , "'>' greater then" , ">" )\ + X(lex_kind_lesser_or_equal , "'<=' lesser then or equal" , "<=" )\ + X(lex_kind_greater_or_equal , "'>=' greater then or equal" , ">=" )\ + X(lex_kind_comma , "',' comma" , "," )\ + X(lex_kind_dot , "'.' dot" , "." )\ + X(lex_kind_three_dots , "'...' three dots" , "..." )\ + X(lex_kind_semicolon , "';' semicolon" , ";" )\ + X(lex_kind_colon , "':' colon" , ":" )\ + X(lex_kind_arrow , "'->' arrow" , "->" )\ + X(lex_kind_question , "'?' question mark" , "?" )\ - #define X(KIND, STR, SIMPLE) lex_kind_##KIND, + #define X(KIND, STR, SIMPLE) KIND, LEX_KIND_XLIST #undef X @@ -66,8 +66,17 @@ enum lex_kind_t { typedef enum lex_suffix_t lex_suffix_t; enum lex_suffix_t { - #define LEX_SUFFIX_XLIST X(none) X(f) X(d) X(u) X(ul) X(ull) X(l) X(ll) - #define X(KIND) lex_suffix_##KIND, + #define LEX_SUFFIX_XLIST\ + X(lex_suffix_none) \ + X(lex_suffix_f) \ + X(lex_suffix_d) \ + X(lex_suffix_u) \ + X(lex_suffix_ul) \ + X(lex_suffix_ull) \ + X(lex_suffix_l) \ + X(lex_suffix_ll) \ + + #define X(KIND) KIND, LEX_SUFFIX_XLIST #undef X @@ -120,8 +129,7 @@ struct parser_t { lex_t *at; }; -#define parser_make(ARENA, TOKEN) &(parser_t){.arena = ARENA, .at = TOKEN} - +#define parser_make(ARENA, TOKEN) &(parser_t){.arena = ARENA, .at = TOKEN} fn lex_t *parser_next(parser_t *par); fn lex_t *parser_match(parser_t *par, lex_kind_t kind); fn lex_t *parser_matchi(parser_t *par, s8_t str); diff --git a/src/core/core_math.h b/src/core/core_math.h index 4206daf..15290d4 100644 --- a/src/core/core_math.h +++ b/src/core/core_math.h @@ -205,9 +205,9 @@ union r3i64_t { #define rgba_macro_const(r, g, b, a) { r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f } -global v4f32_t primary_color_global = rgba_macro_const(245, 238, 230, 255); -global v4f32_t secondary_color_global = rgba_macro_const(255, 248, 227, 255); -global v4f32_t accent1_color_global = rgba_macro_const(243, 215, 202, 255); -global v4f32_t accent2_color_global = rgba_macro_const(230, 164, 180, 255); -global v4f32_t white_color_global = rgba_macro_const(255, 255, 255, 255); -global v4f32_t black_color_global = rgba_macro_const(0, 0, 0, 255); +gb_read_only v4f32_t primary_color_global = rgba_macro_const(245, 238, 230, 255); +gb_read_only v4f32_t secondary_color_global = rgba_macro_const(255, 248, 227, 255); +gb_read_only v4f32_t accent1_color_global = rgba_macro_const(243, 215, 202, 255); +gb_read_only v4f32_t accent2_color_global = rgba_macro_const(230, 164, 180, 255); +gb_read_only v4f32_t white_color_global = rgba_macro_const(255, 255, 255, 255); +gb_read_only v4f32_t black_color_global = rgba_macro_const(0, 0, 0, 255); diff --git a/src/core/core_type_info.h b/src/core/core_type_info.h index cc61043..e5a1b5c 100644 --- a/src/core/core_type_info.h +++ b/src/core/core_type_info.h @@ -69,47 +69,47 @@ fn type_member_t *ti_get_member(s8_t name, type_t *type); #define DEFINE_STRUCT(x) type_t type__##x = {type_kind_struct, s8_const_lit(#x), sizeof(x), .members = members__##x, .count = lengthof(members__##x)} #define POINTER(x) (type_t){type_kind_pointer, s8_const_lit(#x "*"), sizeof(void *), .base = &type__##x} -global type_t type__i8 = {type_kind_i8, s8_const_lit("i8"), sizeof(i8)}; -global type_t type__i16 = {type_kind_i16, s8_const_lit("i16"), sizeof(i16)}; -global type_t type__i32 = {type_kind_i32, s8_const_lit("i32"), sizeof(i32)}; -global type_t type__i64 = {type_kind_i64, s8_const_lit("i64"), sizeof(i64)}; -global type_t type__u8 = {type_kind_u8, s8_const_lit("u8"), sizeof(u8)}; -global type_t type__u16 = {type_kind_u16, s8_const_lit("u16"), sizeof(u16)}; -global type_t type__u32 = {type_kind_u32, s8_const_lit("u32"), sizeof(u32)}; -global type_t type__u64 = {type_kind_u64, s8_const_lit("u64"), sizeof(u64)}; -global type_t type__b8 = {type_kind_b8, s8_const_lit("b8"), sizeof(b8)}; -global type_t type__b16 = {type_kind_b16, s8_const_lit("b16"), sizeof(b16)}; -global type_t type__b32 = {type_kind_b32, s8_const_lit("b32"), sizeof(b32)}; -global type_t type__b64 = {type_kind_b64, s8_const_lit("b64"), sizeof(b64)}; -global type_t type__f32 = {type_kind_f32, s8_const_lit("f32"), sizeof(f32)}; -global type_t type__f64 = {type_kind_f64, s8_const_lit("f64"), sizeof(f64)}; -global type_t type__isize = {type_kind_isize, s8_const_lit("isize"), sizeof(isize)}; -global type_t type__usize = {type_kind_usize, s8_const_lit("usize"), sizeof(usize)}; -global type_t type__int = {type_kind_int, s8_const_lit("int"), sizeof(int)}; -global type_t type__char = {type_kind_char, s8_const_lit("char"), sizeof(char)}; +gb_read_only type_t type__i8 = {type_kind_i8, s8_const_lit("i8"), sizeof(i8)}; +gb_read_only type_t type__i16 = {type_kind_i16, s8_const_lit("i16"), sizeof(i16)}; +gb_read_only type_t type__i32 = {type_kind_i32, s8_const_lit("i32"), sizeof(i32)}; +gb_read_only type_t type__i64 = {type_kind_i64, s8_const_lit("i64"), sizeof(i64)}; +gb_read_only type_t type__u8 = {type_kind_u8, s8_const_lit("u8"), sizeof(u8)}; +gb_read_only type_t type__u16 = {type_kind_u16, s8_const_lit("u16"), sizeof(u16)}; +gb_read_only type_t type__u32 = {type_kind_u32, s8_const_lit("u32"), sizeof(u32)}; +gb_read_only type_t type__u64 = {type_kind_u64, s8_const_lit("u64"), sizeof(u64)}; +gb_read_only type_t type__b8 = {type_kind_b8, s8_const_lit("b8"), sizeof(b8)}; +gb_read_only type_t type__b16 = {type_kind_b16, s8_const_lit("b16"), sizeof(b16)}; +gb_read_only type_t type__b32 = {type_kind_b32, s8_const_lit("b32"), sizeof(b32)}; +gb_read_only type_t type__b64 = {type_kind_b64, s8_const_lit("b64"), sizeof(b64)}; +gb_read_only type_t type__f32 = {type_kind_f32, s8_const_lit("f32"), sizeof(f32)}; +gb_read_only type_t type__f64 = {type_kind_f64, s8_const_lit("f64"), sizeof(f64)}; +gb_read_only type_t type__isize = {type_kind_isize, s8_const_lit("isize"), sizeof(isize)}; +gb_read_only type_t type__usize = {type_kind_usize, s8_const_lit("usize"), sizeof(usize)}; +gb_read_only type_t type__int = {type_kind_int, s8_const_lit("int"), sizeof(int)}; +gb_read_only type_t type__char = {type_kind_char, s8_const_lit("char"), sizeof(char)}; -global type_t type__s8_t = { type_kind_struct, s8_const_lit("s8_t"), sizeof(s8_t), .count = 2, +gb_read_only type_t type__s8_t = { type_kind_struct, s8_const_lit("s8_t"), sizeof(s8_t), .count = 2, .members = (type_member_t[]){ {s8_const_lit("str"), &POINTER(char), .offset = offsetof(s8_t, str)}, {s8_const_lit("len"), &type__i64, .offset = offsetof(s8_t, len)}, } }; -global type_t type__s16_t = { type_kind_struct, s8_const_lit("s16_t"), sizeof(s16_t), .count = 2, +gb_read_only type_t type__s16_t = { type_kind_struct, s8_const_lit("s16_t"), sizeof(s16_t), .count = 2, .members = (type_member_t[]){ {s8_const_lit("str"), &POINTER(u16), .offset = offsetof(s16_t, str)}, {s8_const_lit("len"), &type__i64, .offset = offsetof(s16_t, len)}, } }; -global type_t type__s32_t = { type_kind_struct, s8_const_lit("s32_t"), sizeof(s32_t), .count = 2, +gb_read_only type_t type__s32_t = { type_kind_struct, s8_const_lit("s32_t"), sizeof(s32_t), .count = 2, .members = (type_member_t[]){ {s8_const_lit("str"), &POINTER(u32), .offset = offsetof(s32_t, str)}, {s8_const_lit("len"), &type__i64, .offset = offsetof(s32_t, len)}, } }; -global type_t type__ma_arena_t = { type_kind_struct, s8_const_lit("ma_arena_t"), sizeof(ma_arena_t), .count = 6, +gb_read_only type_t type__ma_arena_t = { type_kind_struct, s8_const_lit("ma_arena_t"), sizeof(ma_arena_t), .count = 6, .members = (type_member_t[]){ {s8_const_lit("data"), &POINTER(u8), .offset = offsetof(ma_arena_t, data)}, {s8_const_lit("len"), &type__usize, .offset = offsetof(ma_arena_t, len)}, @@ -120,21 +120,21 @@ global type_t type__ma_arena_t = { type_kind_struct, s8_const_lit("ma_arena_t"), } }; -global type_t type__ma_temp_t = { type_kind_struct, s8_const_lit("ma_temp_t"), sizeof(ma_temp_t), .count = 2, +gb_read_only type_t type__ma_temp_t = { type_kind_struct, s8_const_lit("ma_temp_t"), sizeof(ma_temp_t), .count = 2, .members = (type_member_t[]){ {s8_const_lit("arena"), &POINTER(ma_arena_t), .offset = offsetof(ma_temp_t, arena)}, {s8_const_lit("len"), &type__usize, .offset = offsetof(ma_temp_t, len)}, } }; -global type_t type__v2f32_t = { type_kind_struct, s8_const_lit("v2f32_t"), sizeof(v2f32_t), .count = 2, +gb_read_only type_t type__v2f32_t = { type_kind_struct, s8_const_lit("v2f32_t"), sizeof(v2f32_t), .count = 2, .members = (type_member_t[]){ {s8_const_lit("x"), &type__f32, .offset = offsetof(v2f32_t, x)}, {s8_const_lit("y"), &type__f32, .offset = offsetof(v2f32_t, y)}, } }; -global type_t type__v3f32_t = { type_kind_struct, s8_const_lit("v3f32_t"), sizeof(v3f32_t), .count = 3, +gb_read_only type_t type__v3f32_t = { type_kind_struct, s8_const_lit("v3f32_t"), sizeof(v3f32_t), .count = 3, .members = (type_member_t[]){ {s8_const_lit("x"), &type__f32, .offset = offsetof(v3f32_t, x)}, {s8_const_lit("y"), &type__f32, .offset = offsetof(v3f32_t, y)}, @@ -142,7 +142,7 @@ global type_t type__v3f32_t = { type_kind_struct, s8_const_lit("v3f32_t"), sizeo } }; -global type_t type__v4f32_t = { type_kind_struct, s8_const_lit("v4f32_t"), sizeof(v4f32_t), .count = 4, +gb_read_only type_t type__v4f32_t = { type_kind_struct, s8_const_lit("v4f32_t"), sizeof(v4f32_t), .count = 4, .members = (type_member_t[]){ {s8_const_lit("x"), &type__f32, .offset = offsetof(v4f32_t, x)}, {s8_const_lit("y"), &type__f32, .offset = offsetof(v4f32_t, y)}, @@ -151,7 +151,7 @@ global type_t type__v4f32_t = { type_kind_struct, s8_const_lit("v4f32_t"), sizeo } }; -global type_t type__r3f32_t = { type_kind_struct, s8_const_lit("r3f32_t"), sizeof(r3f32_t), .count = 6, +gb_read_only type_t type__r3f32_t = { type_kind_struct, s8_const_lit("r3f32_t"), sizeof(r3f32_t), .count = 6, .members = (type_member_t[]){ {s8_const_lit("x0"), &type__f32, .offset = offsetof(r3f32_t, x0)}, {s8_const_lit("y0"), &type__f32, .offset = offsetof(r3f32_t, y0)}, @@ -162,28 +162,28 @@ global type_t type__r3f32_t = { type_kind_struct, s8_const_lit("r3f32_t"), sizeo } }; -global type_member_t members__r2f32_t[] = { +gb_read_only type_member_t members__r2f32_t[] = { {s8_const_lit("x0"), &type__f32, .offset = offsetof(r2f32_t, x0)}, {s8_const_lit("y0"), &type__f32, .offset = offsetof(r2f32_t, y0)}, {s8_const_lit("x1"), &type__f32, .offset = offsetof(r2f32_t, x1)}, {s8_const_lit("y1"), &type__f32, .offset = offsetof(r2f32_t, y1)}, }; -global DEFINE_STRUCT(r2f32_t); +gb_read_only DEFINE_STRUCT(r2f32_t); -global type_member_t members__r1f32_t[] = { +gb_read_only type_member_t members__r1f32_t[] = { {s8_const_lit("x0"), &type__f32, .offset = offsetof(r1f32_t, x0)}, {s8_const_lit("x1"), &type__f32, .offset = offsetof(r1f32_t, x1)}, }; -global DEFINE_STRUCT(r1f32_t); +gb_read_only DEFINE_STRUCT(r1f32_t); -global type_t type__v2f64_t = { type_kind_struct, s8_const_lit("v2f64_t"), sizeof(v2f64_t), .count = 2, +gb_read_only type_t type__v2f64_t = { type_kind_struct, s8_const_lit("v2f64_t"), sizeof(v2f64_t), .count = 2, .members = (type_member_t[]){ {s8_const_lit("x"), &type__f64, .offset = offsetof(v2f64_t, x)}, {s8_const_lit("y"), &type__f64, .offset = offsetof(v2f64_t, y)}, } }; -global type_t type__v3f64_t = { type_kind_struct, s8_const_lit("v3f64_t"), sizeof(v3f64_t), .count = 3, +gb_read_only type_t type__v3f64_t = { type_kind_struct, s8_const_lit("v3f64_t"), sizeof(v3f64_t), .count = 3, .members = (type_member_t[]){ {s8_const_lit("x"), &type__f64, .offset = offsetof(v3f64_t, x)}, {s8_const_lit("y"), &type__f64, .offset = offsetof(v3f64_t, y)}, @@ -191,7 +191,7 @@ global type_t type__v3f64_t = { type_kind_struct, s8_const_lit("v3f64_t"), sizeo } }; -global type_t type__v4f64_t = { type_kind_struct, s8_const_lit("v4f64_t"), sizeof(v4f64_t), .count = 4, +gb_read_only type_t type__v4f64_t = { type_kind_struct, s8_const_lit("v4f64_t"), sizeof(v4f64_t), .count = 4, .members = (type_member_t[]){ {s8_const_lit("x"), &type__f64, .offset = offsetof(v4f64_t, x)}, {s8_const_lit("y"), &type__f64, .offset = offsetof(v4f64_t, y)}, @@ -200,7 +200,7 @@ global type_t type__v4f64_t = { type_kind_struct, s8_const_lit("v4f64_t"), sizeo } }; -global type_t type__r3f64_t = { type_kind_struct, s8_const_lit("r3f64_t"), sizeof(r3f64_t), .count = 6, +gb_read_only type_t type__r3f64_t = { type_kind_struct, s8_const_lit("r3f64_t"), sizeof(r3f64_t), .count = 6, .members = (type_member_t[]){ {s8_const_lit("x0"), &type__f64, .offset = offsetof(r3f64_t, x0)}, {s8_const_lit("y0"), &type__f64, .offset = offsetof(r3f64_t, y0)}, @@ -211,28 +211,28 @@ global type_t type__r3f64_t = { type_kind_struct, s8_const_lit("r3f64_t"), sizeo } }; -global type_member_t members__r2f64_t[] = { +gb_read_only type_member_t members__r2f64_t[] = { {s8_const_lit("x0"), &type__f64, .offset = offsetof(r2f64_t, x0)}, {s8_const_lit("y0"), &type__f64, .offset = offsetof(r2f64_t, y0)}, {s8_const_lit("x1"), &type__f64, .offset = offsetof(r2f64_t, x1)}, {s8_const_lit("y1"), &type__f64, .offset = offsetof(r2f64_t, y1)}, }; -global DEFINE_STRUCT(r2f64_t); +gb_read_only DEFINE_STRUCT(r2f64_t); -global type_member_t members__r1f64_t[] = { +gb_read_only type_member_t members__r1f64_t[] = { {s8_const_lit("x0"), &type__f64, .offset = offsetof(r1f64_t, x0)}, {s8_const_lit("x1"), &type__f64, .offset = offsetof(r1f64_t, x1)}, }; -global DEFINE_STRUCT(r1f64_t); +gb_read_only DEFINE_STRUCT(r1f64_t); -global type_t type__v2i32_t = { type_kind_struct, s8_const_lit("v2i32_t"), sizeof(v2i32_t), .count = 2, +gb_read_only type_t type__v2i32_t = { type_kind_struct, s8_const_lit("v2i32_t"), sizeof(v2i32_t), .count = 2, .members = (type_member_t[]){ {s8_const_lit("x"), &type__i32, .offset = offsetof(v2i32_t, x)}, {s8_const_lit("y"), &type__i32, .offset = offsetof(v2i32_t, y)}, } }; -global type_t type__v3i32_t = { type_kind_struct, s8_const_lit("v3i32_t"), sizeof(v3i32_t), .count = 3, +gb_read_only type_t type__v3i32_t = { type_kind_struct, s8_const_lit("v3i32_t"), sizeof(v3i32_t), .count = 3, .members = (type_member_t[]){ {s8_const_lit("x"), &type__i32, .offset = offsetof(v3i32_t, x)}, {s8_const_lit("y"), &type__i32, .offset = offsetof(v3i32_t, y)}, @@ -240,7 +240,7 @@ global type_t type__v3i32_t = { type_kind_struct, s8_const_lit("v3i32_t"), sizeo } }; -global type_t type__v4i32_t = { type_kind_struct, s8_const_lit("v4i32_t"), sizeof(v4i32_t), .count = 4, +gb_read_only type_t type__v4i32_t = { type_kind_struct, s8_const_lit("v4i32_t"), sizeof(v4i32_t), .count = 4, .members = (type_member_t[]){ {s8_const_lit("x"), &type__i32, .offset = offsetof(v4i32_t, x)}, {s8_const_lit("y"), &type__i32, .offset = offsetof(v4i32_t, y)}, @@ -249,7 +249,7 @@ global type_t type__v4i32_t = { type_kind_struct, s8_const_lit("v4i32_t"), sizeo } }; -global type_t type__r3i32_t = { type_kind_struct, s8_const_lit("r3i32_t"), sizeof(r3i32_t), .count = 6, +gb_read_only type_t type__r3i32_t = { type_kind_struct, s8_const_lit("r3i32_t"), sizeof(r3i32_t), .count = 6, .members = (type_member_t[]){ {s8_const_lit("x0"), &type__i32, .offset = offsetof(r3i32_t, x0)}, {s8_const_lit("y0"), &type__i32, .offset = offsetof(r3i32_t, y0)}, @@ -260,29 +260,29 @@ global type_t type__r3i32_t = { type_kind_struct, s8_const_lit("r3i32_t"), sizeo } }; -global type_member_t members__r2i32_t[] = { +gb_read_only type_member_t members__r2i32_t[] = { {s8_const_lit("x0"), &type__i32, .offset = offsetof(r2i32_t, x0)}, {s8_const_lit("y0"), &type__i32, .offset = offsetof(r2i32_t, y0)}, {s8_const_lit("x1"), &type__i32, .offset = offsetof(r2i32_t, x1)}, {s8_const_lit("y1"), &type__i32, .offset = offsetof(r2i32_t, y1)}, }; -global DEFINE_STRUCT(r2i32_t); +gb_read_only DEFINE_STRUCT(r2i32_t); -global type_member_t members__r1i32_t[] = { +gb_read_only type_member_t members__r1i32_t[] = { {s8_const_lit("x0"), &type__i32, .offset = offsetof(r1i32_t, x0)}, {s8_const_lit("x1"), &type__i32, .offset = offsetof(r1i32_t, x1)}, }; -global DEFINE_STRUCT(r1i32_t); +gb_read_only DEFINE_STRUCT(r1i32_t); -global type_t type__v2i64_t = { type_kind_struct, s8_const_lit("v2i64_t"), sizeof(v2i64_t), .count = 2, +gb_read_only type_t type__v2i64_t = { type_kind_struct, s8_const_lit("v2i64_t"), sizeof(v2i64_t), .count = 2, .members = (type_member_t[]){ {s8_const_lit("x"), &type__i64, .offset = offsetof(v2i64_t, x)}, {s8_const_lit("y"), &type__i64, .offset = offsetof(v2i64_t, y)}, } }; -global type_t type__v3i64_t = { type_kind_struct, s8_const_lit("v3i64_t"), sizeof(v3i64_t), .count = 3, +gb_read_only type_t type__v3i64_t = { type_kind_struct, s8_const_lit("v3i64_t"), sizeof(v3i64_t), .count = 3, .members = (type_member_t[]){ {s8_const_lit("x"), &type__i64, .offset = offsetof(v3i64_t, x)}, {s8_const_lit("y"), &type__i64, .offset = offsetof(v3i64_t, y)}, @@ -290,7 +290,7 @@ global type_t type__v3i64_t = { type_kind_struct, s8_const_lit("v3i64_t"), sizeo } }; -global type_t type__v4i64_t = { type_kind_struct, s8_const_lit("v4i64_t"), sizeof(v4i64_t), .count = 4, +gb_read_only type_t type__v4i64_t = { type_kind_struct, s8_const_lit("v4i64_t"), sizeof(v4i64_t), .count = 4, .members = (type_member_t[]){ {s8_const_lit("x"), &type__i64, .offset = offsetof(v4i64_t, x)}, {s8_const_lit("y"), &type__i64, .offset = offsetof(v4i64_t, y)}, @@ -299,7 +299,7 @@ global type_t type__v4i64_t = { type_kind_struct, s8_const_lit("v4i64_t"), sizeo } }; -global type_t type__r3i64_t = { type_kind_struct, s8_const_lit("r3i64_t"), sizeof(r3i64_t), .count = 6, +gb_read_only type_t type__r3i64_t = { type_kind_struct, s8_const_lit("r3i64_t"), sizeof(r3i64_t), .count = 6, .members = (type_member_t[]){ {s8_const_lit("x0"), &type__i64, .offset = offsetof(r3i64_t, x0)}, {s8_const_lit("y0"), &type__i64, .offset = offsetof(r3i64_t, y0)}, @@ -310,35 +310,35 @@ global type_t type__r3i64_t = { type_kind_struct, s8_const_lit("r3i64_t"), sizeo } }; -global type_member_t members__r2i64_t[] = { +gb_read_only type_member_t members__r2i64_t[] = { {s8_const_lit("x0"), &type__i64, .offset = offsetof(r2i64_t, x0)}, {s8_const_lit("y0"), &type__i64, .offset = offsetof(r2i64_t, y0)}, {s8_const_lit("x1"), &type__i64, .offset = offsetof(r2i64_t, x1)}, {s8_const_lit("y1"), &type__i64, .offset = offsetof(r2i64_t, y1)}, }; -global DEFINE_STRUCT(r2i64_t); +gb_read_only DEFINE_STRUCT(r2i64_t); -global type_member_t members__r1i64_t[] = { +gb_read_only type_member_t members__r1i64_t[] = { {s8_const_lit("x0"), &type__i64, .offset = offsetof(r1i64_t, x0)}, {s8_const_lit("x1"), &type__i64, .offset = offsetof(r1i64_t, x1)}, }; -global DEFINE_STRUCT(r1i64_t); +gb_read_only DEFINE_STRUCT(r1i64_t); -global type_member_t members__lex_kind_t[] = { -#define X(KIND, STR, SIMPLE) {.name = s8_const_lit("lex_kind_" #KIND), .value = lex_kind_##KIND}, +gb_read_only type_member_t members__lex_kind_t[] = { +#define X(KIND, STR, SIMPLE) {.name = s8_const_lit("lex_kind_" #KIND), .value = KIND}, LEX_KIND_XLIST #undef X }; DEFINE_ENUM(lex_kind_t); -global type_member_t members__lex_suffix_t[] = { -#define X(KIND) {.name = s8_const_lit("lex_suffix_" #KIND), .value = lex_suffix_##KIND}, +gb_read_only type_member_t members__lex_suffix_t[] = { +#define X(KIND) {.name = s8_const_lit(#KIND), .value = KIND}, LEX_SUFFIX_XLIST #undef X }; DEFINE_ENUM(lex_suffix_t); -global type_member_t members__log_level_t[] = { +gb_read_only type_member_t members__log_level_t[] = { {.name = s8_const_lit("log_level_debug"), .value = log_level_debug}, {.name = s8_const_lit("log_level_info"), .value = log_level_info}, {.name = s8_const_lit("log_level_warning"), .value = log_level_warning}, diff --git a/src/gfx2d/gfx2d.c b/src/gfx2d/gfx2d.c index 9ed711c..9b7c3c4 100644 --- a/src/gfx2d/gfx2d.c +++ b/src/gfx2d/gfx2d.c @@ -5,8 +5,7 @@ fn_wasm_import f64 wasm_measure_text(isize str, i32 len, isize font_str, i32 fo fn_wasm_import f64 wasm_get_font_height(isize font_str, i32 font_len, i32 font_size); fn_wasm_import void wasm_set_clip(f64 x, f64 y, f64 w, f64 h); -global s8_t font_face = s8_const_lit("open_sans_regular"); - +gb_read_only s8_t font_face = s8_const_lit("open_sans_regular"); fn void set_clip(r2f64_t rect) { wasm_set_clip(wasm_dpr * rect.min.x, wasm_dpr * rect.min.y, wasm_dpr * (rect.max.x - rect.min.x), wasm_dpr * (rect.max.y - rect.min.y));