From 122f3dba245519b3cd9c85db7965e2a6c3b76944 Mon Sep 17 00:00:00 2001 From: Andreew Gregory Date: Wed, 8 Oct 2025 16:42:10 +0300 Subject: [PATCH] int_ptimitives template instantiation and vec,cvec templ instantiation split into many separarate files --- src/l1/anne/pixel_masses.h | 5 +- src/l1/anne/util_temp_geom.h | 27 ++------- src/l1/anne/util_temp_very_base.h | 84 +++++++++++++--------------- src/l1/codegen/util_template_inst.h | 1 - src/l1/core/VecU8_as_str.h | 2 +- src/l1_4/tests/t0.c | 3 +- src/l1_4/tests/t1.c | 4 +- src/l1_5/anne/l1_5_templ_very_base.h | 10 ++-- src/l1_5/anne/marie/clipping.h | 2 +- src/l1_5/core/stringop.h | 6 +- src/l2/margaret/vulkan_utils.h | 4 +- src/l2/tests/data_structures/t0.c | 2 +- src/l2/tests/r0/r0_assets.h | 4 +- src/l3/fun_machine/fun_machine.h | 3 +- 14 files changed, 66 insertions(+), 91 deletions(-) diff --git a/src/l1/anne/pixel_masses.h b/src/l1/anne/pixel_masses.h index a40ef32..fb5d453 100644 --- a/src/l1/anne/pixel_masses.h +++ b/src/l1/anne/pixel_masses.h @@ -133,9 +133,10 @@ NODISCARD VecU8 generate_texture_data_struct_and_necc_methods(SpanU8 tex, SpanU8 void generate_pixel_masses_header() { GeneratedHeader res = begin_header(cstr("l1/pixel_masses.h")); - VecU8_append_span(&res.result, cstr("#include \"VecAndSpan_int_primitives.h\"\n")); + VecU8_append_span(&res.result, cstr("#include \"VecAndSpan_U8.h\"\n")); VecU8_append_span(&res.result, cstr("#include \"../../src/l1/system/fileio.h\"\n")); - VecU8_append_span(&res.result, cstr("#include \"VecAndSpan_cvec.h\"\n\n")); + VecU8_append_span(&res.result, cstr("#include \"VecAndSpan_cvec3.h\"\n")); + VecU8_append_span(&res.result, cstr("#include \"VecAndSpan_cvec4.h\"\n\n")); VecU8_append_vec(&res.result, generate_texture_data_struct_and_necc_methods(cstr("TextureDataR8"), cstr("U8"))); VecU8_append_vec(&res.result, generate_texture_data_struct_and_necc_methods(cstr("TextureDataR8G8B8"), cstr("cvec3"))); VecU8_append_vec(&res.result, generate_texture_data_struct_and_necc_methods(cstr("TextureDataR8G8B8A8"), cstr("cvec4"))); diff --git a/src/l1/anne/util_temp_geom.h b/src/l1/anne/util_temp_geom.h index 6b24d2d..d443f99 100644 --- a/src/l1/anne/util_temp_geom.h +++ b/src/l1/anne/util_temp_geom.h @@ -4,29 +4,10 @@ #include "../codegen/util_template_inst.h" void generate_util_temp_geom_headers() { - { - GeneratedHeader head = begin_header(cstr("l1/VecAndSpan_cvec.h")); - VecU8_append_span(&head.result, cstr("#include \"geom.h\"\n")); - VecU8_append_span(&head.result, cstr("#include \"../../src/l1/core/util.h\"\n\n")); - SpanU8 T[] = {cstr("cvec3"), cstr("cvec4")}; - for (size_t i = 0; i < ARRAY_SIZE(T); i++) { - VecU8_append_vec(&head.result, generate_util_templates_instantiation((util_templates_instantiation_options){ - .T = T[i], .t_primitive = true, .vec = true, .span = true, .collab_vec_span = true, - })); - } - finish_header(head); - } - { - GeneratedHeader head = begin_header(cstr("l1/VecAndSpan_vec.h")); - VecU8_append_span(&head.result, cstr("#include \"geom.h\"\n")); - VecU8_append_span(&head.result, cstr("#include \"../../src/l1/core/util.h\"\n\n")); - SpanU8 T[] = {cstr("vec2"), cstr("vec3"), cstr("vec4")}; - for (size_t i = 0; i < ARRAY_SIZE(T); i++) { - VecU8_append_vec(&head.result, generate_util_templates_instantiation((util_templates_instantiation_options){ - .T = T[i], .t_primitive = true, .vec = true, .span = true, .collab_vec_span = true, - })); - } - finish_header(head); + SpanU8 T[] = {cstr("cvec3"), cstr("cvec4"), cstr("vec2"), cstr("vec3"), cstr("vec4")}; + for (size_t i = 0; i < ARRAY_SIZE(T); i++) { + generate_guarded_span_company_for_primitive(cstr("l1"), cstr(""), T[i], + cstr("#include \"geom.h\"\n"), true, true); } } diff --git a/src/l1/anne/util_temp_very_base.h b/src/l1/anne/util_temp_very_base.h index 095ddb2..177fd31 100644 --- a/src/l1/anne/util_temp_very_base.h +++ b/src/l1/anne/util_temp_very_base.h @@ -7,54 +7,48 @@ /* These headers are guarded */ void generate_util_temp_very_base_headers() { - { - GeneratedHeader head = begin_header(cstr("l1/VecAndSpan_int_primitives.h")); - VecU8_append_span(&head.result, cstr("#include \"../../src/l1/core/util.h\"\n\n")); - SpanU8 T[] = {cstr("U8"), cstr("U16"), cstr("U32"), cstr("U64"), cstr("S64")}; - for (size_t i = 0; i < ARRAY_SIZE(T); i++) { - VecU8_append_vec(&head.result, generate_util_templates_instantiation((util_templates_instantiation_options){ - .T = T[i], - .t_integer = true, .t_primitive = true, .vec = true, .vec_extended = true, - .vec_equal = true, .span = true, .span_extended = true, .mut_span = true, - .collab_vec_span = true, .collab_vec_span_extended = true, - })); - } - finish_header(head); + SpanU8 l = cstr("l1"), ns = cstr(""); + SpanU8 T_codegen_VecAndSpan[] = {cstr("U8"), cstr("U16"), cstr("U32"), cstr("U64"), cstr("S64")}; + SpanU8 T_codegen_Option[] = {cstr("U8"), cstr("U16"), cstr("U32"), cstr("U64"), cstr("S64")}; + SpanU8 T_codegen_VecAndSpan_of_Vec[] = {cstr("U8"), cstr("U16"), cstr("U32"), cstr("U64")}; + SpanU8 T_codegen_VecAndSpan_of_Span[] = {cstr("U8"), cstr("U16"), cstr("U32"), cstr("U64")}; + for (size_t i = 0; i < ARRAY_SIZE(T_codegen_VecAndSpan); i++) { + generate_util_templ_inst_guarded_header(l, ns, + cstr(""), + (util_templates_instantiation_options){ + .T = T_codegen_VecAndSpan[i], + .t_integer = true, .t_primitive = true, .vec = true, .vec_extended = true, + .vec_equal = true, .span = true, .span_extended = true, .mut_span = true, + .collab_vec_span = true, .collab_vec_span_extended = true, + }); } - { - GeneratedHeader head = begin_header(cstr("l1/Option_int_primitives.h")); - VecU8_append_span(&head.result, cstr("#include \"../../src/l1/core/util.h\"\n\n")); - SpanU8 T[] = {cstr("U8"), cstr("U16"), cstr("U32"), cstr("U64"), cstr("S64")}; - for (size_t i = 0; i < ARRAY_SIZE(T); i++) { - VecU8_append_vec(&head.result, generate_OptionT_struct_and_methods((option_template_instantiation_op){ - .T = T[i], .t_integer = true, .t_primitive = true - })); - } - finish_header(head); + for (size_t i = 0; i < ARRAY_SIZE(T_codegen_Option); i++) { + generate_Option_templ_inst_guarded_header(l, ns, + cstr(""), + (option_template_instantiation_op){.T = T_codegen_Option[i], .t_integer = true}); } - { - GeneratedHeader head = begin_header(cstr("l1/VecAndSpan_Vec_int_primitives.h")); - VecU8_append_span(&head.result, cstr("#include \"VecAndSpan_int_primitives.h\"\n\n")); - SpanU8 T[] = {cstr("VecU8"), cstr("VecU16"), cstr("VecU32"), cstr("VecU64")}; - for (size_t i = 0; i < ARRAY_SIZE(T); i++) { - VecU8_append_vec(&head.result, generate_util_templates_instantiation((util_templates_instantiation_options){ - .T = T[i], .t_clonable = true, .vec = true, .vec_extended = true, - .span = true, .collab_vec_span = true, .vec_equal = true, - })); - } - VecU8_append_vec(&head.result, generate_VecT_new_of_size_method(cstr("VecU8"))); - finish_header(head); + for (size_t i = 0; i < ARRAY_SIZE(T_codegen_VecAndSpan_of_Vec); i++) { + VecU8 VecT = VecU8_fmt("Vec%s", T_codegen_VecAndSpan_of_Vec[i]); + VecU8 dependency = VecU8_fmt("#include \"VecAndSpan_%s.h\"", T_codegen_VecAndSpan_of_Vec[i]); + generate_util_templ_inst_guarded_header(l, ns, + VecU8_to_span(&dependency), + (util_templates_instantiation_options){ + .T = VecU8_to_span(&VecT), .t_clonable = true, .vec = true, .vec_extended = true, + .span = true, .collab_vec_span = true, .vec_equal = true, .vec_new_of_size = true + }); + VecU8_drop(VecT); + VecU8_drop(dependency); } - { - GeneratedHeader head = begin_header(cstr("l1/VecAndSpan_Span_int_primitives.h")); - VecU8_append_span(&head.result, cstr("#include \"VecAndSpan_int_primitives.h\"\n\n")); - SpanU8 T[1] = {cstr("SpanU8")}; - for (size_t i = 0; i < ARRAY_SIZE(T); i++) { - VecU8_append_vec(&head.result, generate_util_templates_instantiation((util_templates_instantiation_options){ - .T = T[i], .t_primitive = true, .vec = true, .span = true, .mut_span = true, .collab_vec_span = true, - })); - } - finish_header(head); + for (size_t i = 0; i < ARRAY_SIZE(T_codegen_VecAndSpan_of_Span); i++) { + VecU8 SpanT = VecU8_fmt("Span%s", T_codegen_VecAndSpan_of_Span[i]); + VecU8 dependency = VecU8_fmt("#include \"VecAndSpan_%s.h\"", T_codegen_VecAndSpan_of_Span[i]); + generate_util_templ_inst_guarded_header(l, ns, + VecU8_to_span(&dependency), + (util_templates_instantiation_options){ + .T = VecU8_to_span(&SpanT), .t_primitive = true, .vec = true, .span = true, .mut_span = true, .collab_vec_span = true, + }); + VecU8_drop(SpanT); + VecU8_drop(dependency); } generate_guarded_span_company_for_primitive(cstr("l1"), cstr(""), cstr("CSTR"), cstr(""), true, false); diff --git a/src/l1/codegen/util_template_inst.h b/src/l1/codegen/util_template_inst.h index 9fc775d..4f7c837 100644 --- a/src/l1/codegen/util_template_inst.h +++ b/src/l1/codegen/util_template_inst.h @@ -476,7 +476,6 @@ void generate_util_templ_inst_eve_header(SpanU8 layer, SpanU8 bonus_ns, util_tem " * Do not include it in more than one place */\n\n"); VecU8_append_vec(&text, generate_util_templates_instantiation(op)); VecU8 filename = util_templates_instantiation_get_appropriate_filename(op); - // todo: add %v that takes a vector VecU8 nt_path = VecU8_fmt("%s/eve/%s/%v%c", layer, bonus_ns, filename, 0); write_whole_file_or_abort((const char*)nt_path.buf, VecU8_to_span(&text)); VecU8_drop(nt_path); diff --git a/src/l1/core/VecU8_as_str.h b/src/l1/core/VecU8_as_str.h index d80ec43..b4be777 100644 --- a/src/l1/core/VecU8_as_str.h +++ b/src/l1/core/VecU8_as_str.h @@ -6,7 +6,7 @@ #ifdef PROTOTYPE1_L1_CODEGEN_BOOTSTRAP_USE_CHICKEN_VECU8 #include "chicken_VecU8.h" #else -#include "../../../gen/l1/VecAndSpan_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_U8.h" #endif VecU8 VecU8_from_cstr(const char* dc) { diff --git a/src/l1_4/tests/t0.c b/src/l1_4/tests/t0.c index ceddf96..7236e9f 100644 --- a/src/l1_4/tests/t0.c +++ b/src/l1_4/tests/t0.c @@ -1,4 +1,5 @@ -#include "../../../gen/l1/VecAndSpan_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_U8.h" +#include "../../../gen/l1/VecAndSpan_U32.h" int main() { VecU8 a = VecU8_new(); diff --git a/src/l1_4/tests/t1.c b/src/l1_4/tests/t1.c index 8583a87..6976db4 100644 --- a/src/l1_4/tests/t1.c +++ b/src/l1_4/tests/t1.c @@ -1,5 +1,5 @@ -#include "../../../gen/l1/VecAndSpan_int_primitives.h" -#include "../../../gen/l1/VecAndSpan_Vec_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_U64.h" +#include "../../../gen/l1/VecAndSpan_VecU64.h" int main() { VecU64 v = VecU64_new(); diff --git a/src/l1_5/anne/l1_5_templ_very_base.h b/src/l1_5/anne/l1_5_templ_very_base.h index 479b283..9b12e22 100644 --- a/src/l1_5/anne/l1_5_templ_very_base.h +++ b/src/l1_5/anne/l1_5_templ_very_base.h @@ -6,12 +6,10 @@ void generate_l1_5_template_instantiation_for_base_types(){ SpanU8 l = cstr("l1_5"); SpanU8 ns = cstr(""); - SpanU8 dep = cstr( - "#include \"../l1/VecAndSpan_int_primitives.h\"" - ); - // todo: split VecAndSpan_int_primitives into multiple files (one file per integer type) - generate_rb_tree_Set_templ_inst_guarded_header(l, ns, dep, (set_instantiation_op){.T = cstr("U64"), .t_integer = true}); - generate_rb_tree_Set_templ_inst_guarded_header(l, ns, dep, (set_instantiation_op){.T = cstr("S64"), .t_integer = true}); + generate_rb_tree_Set_templ_inst_guarded_header(l, ns, cstr("#include \"../l1/VecAndSpan_U64.h\""), + (set_instantiation_op){.T = cstr("U64"), .t_integer = true}); + generate_rb_tree_Set_templ_inst_guarded_header(l, ns, cstr("#include \"../l1/VecAndSpan_S64.h\""), + (set_instantiation_op){.T = cstr("S64"), .t_integer = true}); } #endif diff --git a/src/l1_5/anne/marie/clipping.h b/src/l1_5/anne/marie/clipping.h index 1101660..33d8492 100644 --- a/src/l1_5/anne/marie/clipping.h +++ b/src/l1_5/anne/marie/clipping.h @@ -2,7 +2,7 @@ #define PROTOTYPE1_SRC_L1_CODEGEN_CLIPPING_H #include "../../../l1/codegen/codegen.h" -#include "../../../../gen/l1/VecAndSpan_Span_int_primitives.h" +#include "../../../../gen/l1/VecAndSpan_SpanU8.h" // todo: move all of this to marie namespace // todo: instead of returning triangles, return points of convex polygon diff --git a/src/l1_5/core/stringop.h b/src/l1_5/core/stringop.h index b4719b9..616fee3 100644 --- a/src/l1_5/core/stringop.h +++ b/src/l1_5/core/stringop.h @@ -1,9 +1,9 @@ #ifndef PROTOTYPE1_SRC_L1_5_CORE_STRINGOP_H #define PROTOTYPE1_SRC_L1_5_CORE_STRINGOP_H -#include "../../../gen/l1/VecAndSpan_int_primitives.h" -#include "../../../gen/l1/VecAndSpan_Vec_int_primitives.h" -#include "../../../gen/l1/VecAndSpan_Span_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_U8.h" +#include "../../../gen/l1/VecAndSpan_VecU8.h" +#include "../../../gen/l1/VecAndSpan_SpanU8.h" #include "../../l1/core/VecU8_as_str.h" U8 U8_to_lowercase(U8 ch) { diff --git a/src/l2/margaret/vulkan_utils.h b/src/l2/margaret/vulkan_utils.h index 8afcf30..277b7e2 100644 --- a/src/l2/margaret/vulkan_utils.h +++ b/src/l2/margaret/vulkan_utils.h @@ -1,8 +1,8 @@ #ifndef PROTOTYPE1_SRC_L2_MARGARET_MARGARET_H #define PROTOTYPE1_SRC_L2_MARGARET_MARGARET_H -#include "../../../gen/l1/Option_int_primitives.h" -#include "../../../gen/l1/VecAndSpan_Vec_int_primitives.h" +#include "../../../gen/l1/OptionU32.h" +#include "../../../gen/l1/VecAndSpan_VecU8.h" #include "../../l1_5/core/stringop.h" #include "../../l1/system/fileio.h" #include "time_utils.h" diff --git a/src/l2/tests/data_structures/t0.c b/src/l2/tests/data_structures/t0.c index 1d2d1aa..072afa8 100644 --- a/src/l2/tests/data_structures/t0.c +++ b/src/l2/tests/data_structures/t0.c @@ -1,5 +1,5 @@ #include "../../../../gen/l1_5/BuffRBTree_SetS64.h" -#include "../../../../gen/l1/VecAndSpan_int_primitives.h" +#include "../../../../gen/l1/VecAndSpan_S64.h" #include "../../../l1/core/VecU8_as_str.h" #include "../../../l1/system/fileio.h" #include "../../../l1/system/fsmanip.h" diff --git a/src/l2/tests/r0/r0_assets.h b/src/l2/tests/r0/r0_assets.h index 1460d7a..bdd9b21 100644 --- a/src/l2/tests/r0/r0_assets.h +++ b/src/l2/tests/r0/r0_assets.h @@ -2,10 +2,10 @@ #define SPLITTER_DRAFT_SRC_L2_TESTS_R0_ASSETS_H #include "../../marie/graphics_geom.h" -#include "../../../../gen/l1/VecAndSpan_int_primitives.h" +#include "../../../../gen/l1/VecAndSpan_U32.h" #include "../../../l1/system/fileio.h" #include -#include "../../../../gen/l1/VecAndSpan_vec.h" +#include "../../../../gen/l1/VecAndSpan_vec2.h" #include "../../../../gen/l1/pixel_masses.h" #include "../../marie/rasterization.h" diff --git a/src/l3/fun_machine/fun_machine.h b/src/l3/fun_machine/fun_machine.h index bcbd77f..34964c5 100644 --- a/src/l3/fun_machine/fun_machine.h +++ b/src/l3/fun_machine/fun_machine.h @@ -1,7 +1,8 @@ #ifndef PROTOTYPE1_SRC_L3_FUN_MACHINE_STATE_H #define PROTOTYPE1_SRC_L3_FUN_MACHINE_STATE_H -#include "../../../gen/l1/VecAndSpan_int_primitives.h" +#include "../../../gen/l1/VecAndSpan_U8.h" +#include "../../../gen/l1/VecAndSpan_U16.h" // todo: recheck this structure const U8 FunMachine_LRU_states[24][4] ={