Saving unfinished work: another refactoring of l1 codegen. Yet another...
This commit is contained in:
parent
83bef6da7e
commit
b0cd4a92cd
@ -27,29 +27,30 @@ add_compile_definitions(_POSIX_C_SOURCE=200112L)
|
||||
add_compile_definitions(_GNU_SOURCE)
|
||||
add_compile_options(-fno-trapping-math)
|
||||
|
||||
#add_executable(codegen_l1 src/l1/anne/codegen.c)
|
||||
#target_compile_definitions(codegen_l1
|
||||
# PRIVATE PROTOTYPE1_L1_CODEGEN_BOOTSTRAP_USE_CHICKEN_VECU8)
|
||||
add_executable(codegen_l1 src/l1/anne/codegen.c)
|
||||
target_compile_definitions(codegen_l1
|
||||
PRIVATE PROTOTYPE1_L1_CODEGEN_BOOTSTRAP_USE_CHICKEN_VECU8)
|
||||
|
||||
add_executable(0_test src/l1_4/tests/t0.c)
|
||||
add_executable(1_test src/l1_4/tests/t1.c)
|
||||
|
||||
add_executable(codegen_l1_5 src/l1_5/anne/codegen.c)
|
||||
|
||||
add_executable(0_render_test src/l2/tests/r0/r0.c gen/l_wl_protocols/xdg-shell-private.c)
|
||||
target_link_libraries(0_render_test -lvulkan -lwayland-client -lm -lxkbcommon -lpng)
|
||||
|
||||
add_executable(0r_tex_init_prep src/l2/tests/r0/r0_tex_init_prep.c)
|
||||
target_link_libraries(0r_tex_init_prep -lm -lpng)
|
||||
|
||||
add_executable(1_render_test src/l2/tests/r1/r1.c gen/l_wl_protocols/xdg-shell-private.c)
|
||||
target_link_libraries(1_render_test -lwayland-client -lrt -lm -lxkbcommon)
|
||||
|
||||
add_executable(2a_render_test src/l2/tests/r2/r2a.c gen/l_wl_protocols/xdg-shell-private.c)
|
||||
target_link_libraries(2a_render_test ${LIBPIPEWIRE_LIBS} -lwayland-client -lrt -lm -lxkbcommon)
|
||||
|
||||
add_executable(3_render_test src/l2/tests/r3/r3.c gen/l_wl_protocols/xdg-shell-private.c)
|
||||
target_link_libraries(3_render_test -lwayland-client -lm -lvulkan -lxkbcommon)
|
||||
#add_executable(0_test src/l1_4/tests/t0.c)
|
||||
#add_executable(1_test src/l1_4/tests/t1.c)
|
||||
#
|
||||
#add_executable(codegen_l1_5 src/l1_5/anne/codegen.c)
|
||||
#
|
||||
#add_executable(0_render_test src/l2/tests/r0/r0.c gen/l_wl_protocols/xdg-shell-private.c
|
||||
# src/l1/core/rb_tree_node.h)
|
||||
#target_link_libraries(0_render_test -lvulkan -lwayland-client -lm -lxkbcommon -lpng)
|
||||
#
|
||||
#add_executable(0r_tex_init_prep src/l2/tests/r0/r0_tex_init_prep.c)
|
||||
#target_link_libraries(0r_tex_init_prep -lm -lpng)
|
||||
#
|
||||
#add_executable(1_render_test src/l2/tests/r1/r1.c gen/l_wl_protocols/xdg-shell-private.c)
|
||||
#target_link_libraries(1_render_test -lwayland-client -lrt -lm -lxkbcommon)
|
||||
#
|
||||
#add_executable(2a_render_test src/l2/tests/r2/r2a.c gen/l_wl_protocols/xdg-shell-private.c)
|
||||
#target_link_libraries(2a_render_test ${LIBPIPEWIRE_LIBS} -lwayland-client -lrt -lm -lxkbcommon)
|
||||
#
|
||||
#add_executable(3_render_test src/l2/tests/r3/r3.c gen/l_wl_protocols/xdg-shell-private.c)
|
||||
#target_link_libraries(3_render_test -lwayland-client -lm -lvulkan -lxkbcommon)
|
||||
|
||||
#add_executable(0_play_test src/l3/tests/p0.c)
|
||||
#target_link_libraries(0_play_test -lncurses)
|
||||
|
||||
31
Makefile
31
Makefile
@ -53,22 +53,51 @@ gen/l_wl_protocols/xdg-shell-private.c: $(wl_protocols)/stable/xdg-shell/xdg-she
|
||||
xdg_shell_private := gen/l_wl_protocols/xdg-shell-private.c
|
||||
l_wl_protocols := gen/l_wl_protocols/xdg-shell-client.h $(xdg_shell_private)
|
||||
|
||||
|
||||
out/l2/r0: src/l2/tests/r0/r0.c $(HEADERS_src_l2) $(l_wl_protocols)
|
||||
mkdir -p out/l2
|
||||
$(cc) $(cflags) -o $@ $< $(xdg_shell_private) -lvulkan -lm -lxkbcommon -lwayland-client -lpng
|
||||
|
||||
out/l2/r0_tex_init_prep: src/l2/tests/r0/r0_tex_init_prep.c $(HEADERS_src_l2)
|
||||
mkdir -p out/l2
|
||||
$(cc) $(cflags) -o $@ $< -lm -lpng
|
||||
|
||||
.PHONY: run_r0
|
||||
run_r0: out/l2/r0
|
||||
cd src/l2/tests/r0 && ../../../../out/l2/r0
|
||||
|
||||
.PHONY: run_r0_tex_init_prep
|
||||
run_r0_tex_init_prep: out/l2/r0_tex_init_prep
|
||||
cd src/l2/tests/r0 && ../../../../out/l2/r0_tex_init_prep
|
||||
|
||||
|
||||
out/l2/r1: src/l2/tests/r1/r1.c $(HEADERS_src_l2) $(l_wl_protocols)
|
||||
mkdir -p out/l2
|
||||
$(cc) $(cflags) -o $@ $< $(xdg_shell_private) -lwayland-client -lrt -lxkbcommon -lm
|
||||
|
||||
out/l2/r2a: src/l2/tests/r2/r2a.c $(HEADERS_src_l2) $(l_wl_protocols)
|
||||
.PHONY: run_r1
|
||||
run_r1: out/l2/r1
|
||||
./out/l2/r1
|
||||
|
||||
|
||||
out/l2/r2: src/l2/tests/r2/r2a.c $(HEADERS_src_l2) $(l_wl_protocols)
|
||||
mkdir -p out/l2
|
||||
$(cc) $(cflags) -o $@ $< $(xdg_shell_private) -lwayland-client -lrt -lxkbcommon -lm $(libpipewire_flags)
|
||||
|
||||
.PHONY: run_r2
|
||||
run_r2: out/l2/r2
|
||||
./out/l2/r2
|
||||
|
||||
|
||||
out/l2/r3: src/l2/tests/r3/r3.c $(HEADERS_src_l2) $(l_wl_protocols)
|
||||
mkdir -p out/l2
|
||||
$(cc) $(cflags) -o $@ $< $(xdg_shell_private) -lwayland-client -lrt -lxkbcommon -lm -lvulkan
|
||||
|
||||
.PHONY: run_r3
|
||||
run_r3: out/l2/r3
|
||||
./out/l2/r3
|
||||
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf gen out
|
||||
|
||||
@ -10,6 +10,7 @@ void generate_l1_headers_for_l1_5() {
|
||||
SpanU8 ns = cstr("embassy_l1_5");
|
||||
generate_eve_span_company_for_primitive(l, ns, cstr("NamedVariableRecordRef"), false, true);
|
||||
generate_eve_span_company_for_primitive(l, ns, cstr("NamedMethodSignatureRecordRef"), false, true);
|
||||
generate_eve_span_company_for_primitive(l, ns, cstr("RBTreeNode"), true, false);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -7,8 +7,9 @@ void generate_liza_l1_headers() {
|
||||
SpanU8 l = cstr("l1");
|
||||
SpanU8 ns = cstr("liza");
|
||||
mkdir_nofail("l1/eve/liza");
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("BoxLizaSound"),
|
||||
(util_templates_instantiation_options){ .vec = true});
|
||||
// todo: continue OptionT + util_templates_instantiation_options refactoring from here
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("BoxLizaSound"), .vec = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("PlayingSound"),
|
||||
(util_templates_instantiation_options){.vec_extended = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("BoxLizaInstrument"),
|
||||
|
||||
@ -25,9 +25,9 @@ void generate_headers_for_r0_r1_r2_r3() {
|
||||
mkdir_nofail("l1/eve/r2");
|
||||
{ /* r2 */
|
||||
SpanU8 ns = cstr("r2");
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("PlayingSound"), (util_templates_instantiation_options){
|
||||
.vec_extended = true});
|
||||
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("PlayingSound"), .vec_extended = true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,10 +10,9 @@ void generate_util_temp_geom_headers() {
|
||||
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(T[i],
|
||||
(util_templates_instantiation_options){
|
||||
.t_primitive = true, .vec = true, .span = true, .collab_vec_span = true,
|
||||
}));
|
||||
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);
|
||||
}
|
||||
@ -23,10 +22,9 @@ void generate_util_temp_geom_headers() {
|
||||
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(T[i],
|
||||
(util_templates_instantiation_options){
|
||||
.t_primitive = true, .vec = true, .span = true, .collab_vec_span = true,
|
||||
}));
|
||||
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);
|
||||
}
|
||||
|
||||
@ -10,7 +10,8 @@ void generate_util_temp_very_base_headers() {
|
||||
VecU8_append_span(&head.result, cstr("#include \"../../src/l1/core/util.h\"\n\n"));
|
||||
SpanU8 T[4] = {cstr("U8"), cstr("U16"), cstr("U32"), cstr("U64")};
|
||||
for (size_t i = 0; i < ARRAY_SIZE(T); i++) {
|
||||
VecU8_append_vec(&head.result, generate_util_templates_instantiation(T[i], (util_templates_instantiation_options){
|
||||
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,
|
||||
@ -23,8 +24,8 @@ void generate_util_temp_very_base_headers() {
|
||||
VecU8_append_span(&head.result, cstr("#include \"../../src/l1/core/util.h\"\n\n"));
|
||||
SpanU8 T[4] = {cstr("U8"), cstr("U16"), cstr("U32"), cstr("U64")};
|
||||
for (size_t i = 0; i < ARRAY_SIZE(T); i++) {
|
||||
VecU8_append_vec(&head.result, generate_util_templates_instantiation(T[i], (util_templates_instantiation_options){
|
||||
.t_integer = true, .t_primitive = true, .option = true
|
||||
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);
|
||||
@ -34,8 +35,9 @@ void generate_util_temp_very_base_headers() {
|
||||
VecU8_append_span(&head.result, cstr("#include \"VecAndSpan_int_primitives.h\"\n\n"));
|
||||
SpanU8 T[4] = {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(T[i], (util_templates_instantiation_options){
|
||||
.t_clonable = true, .vec = true, .vec_extended = true, .span = true, .collab_vec_span = true, .vec_equal = true,
|
||||
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")));
|
||||
@ -46,9 +48,8 @@ void generate_util_temp_very_base_headers() {
|
||||
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(T[i], (util_templates_instantiation_options){
|
||||
.t_primitive = true, .vec = true, .span = true, .mut_span = true,
|
||||
.collab_vec_span = true,
|
||||
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);
|
||||
|
||||
@ -11,16 +11,29 @@ void generate_util_templ_inst_for_vulkan_headers() {
|
||||
mkdir_nofail("l1/vulkan");
|
||||
generate_guarded_span_company_for_primitive(l, ns, cstr("VkQueueFamilyProperties"), vulkan_dep, true, false);
|
||||
generate_guarded_span_company_for_primitive(l, ns, cstr("VkExtensionProperties"), vulkan_dep, true, false);
|
||||
generate_util_templ_inst_guarded_header(l, ns, cstr("VkSurfaceFormatKHR"), vulkan_dep,
|
||||
(util_templates_instantiation_options){ .t_primitive = true, .vec = true, .option = true });
|
||||
generate_util_templ_inst_guarded_header(l, ns, cstr("VkPresentModeKHR"), vulkan_dep,
|
||||
(util_templates_instantiation_options){ .t_primitive = true, .vec = true, .option = true });
|
||||
generate_util_templ_inst_guarded_header(l, ns, cstr("VkCompositeAlphaFlagBitsKHR"), vulkan_dep,
|
||||
(util_templates_instantiation_options){ .t_primitive = true, .option = true });
|
||||
generate_util_templ_inst_guarded_header(l, ns, cstr("VkExtent2D"), vulkan_dep,
|
||||
(util_templates_instantiation_options){ .t_primitive = true, .option = true });
|
||||
generate_util_templ_inst_guarded_header(l, ns, cstr("VkFormat"), vulkan_dep,
|
||||
(util_templates_instantiation_options){ .t_primitive = true, .span = true, .option = true });
|
||||
|
||||
generate_guarded_span_company_for_primitive(l, ns, cstr("VkSurfaceFormatKHR"), vulkan_dep, true, false);
|
||||
generate_guarded_span_company_for_primitive(l, ns, cstr("VkPresentModeKHR"), vulkan_dep, true, false);
|
||||
generate_guarded_span_company_for_primitive(l, ns, cstr("VkFormat"), vulkan_dep, false, true);
|
||||
|
||||
generate_Option_templ_inst_guarded_header(l, ns, vulkan_dep, (option_template_instantiation_op){
|
||||
.T = cstr("VkPresentModeKHR"), .t_integer = true
|
||||
});
|
||||
generate_Option_templ_inst_guarded_header(l, ns, vulkan_dep, (option_template_instantiation_op){
|
||||
.T = cstr("VkFormat"), .t_integer = true
|
||||
});
|
||||
generate_Option_templ_inst_guarded_header(l, ns, vulkan_dep, (option_template_instantiation_op){
|
||||
.T = cstr("VkSurfaceFormatKHR"), .t_primitive = true
|
||||
});
|
||||
generate_Option_templ_inst_guarded_header(l, ns, vulkan_dep, (option_template_instantiation_op){
|
||||
.T = cstr("VkCompositeAlphaFlagBitsKHR"), .t_integer = true
|
||||
});
|
||||
generate_Option_templ_inst_guarded_header(l, ns, vulkan_dep, (option_template_instantiation_op){
|
||||
.T = cstr("VkExtent2D"), .t_primitive = true
|
||||
});
|
||||
// for these
|
||||
|
||||
|
||||
generate_guarded_span_company_for_primitive(l, ns, cstr("VkPhysicalDevice"), vulkan_dep, true, false);
|
||||
generate_guarded_span_company_for_primitive(l, ns, cstr("VkImage"), vulkan_dep, true, false);
|
||||
generate_guarded_span_company_for_primitive(l, ns, cstr("VkImageView"), vulkan_dep, true, false);
|
||||
|
||||
@ -48,4 +48,27 @@ void finish_layer(SpanU8 layer_name) {
|
||||
VecU8_drop(nt_name);
|
||||
}
|
||||
|
||||
int get_number_of_parts_in_header_namespace(SpanU8 ns) {
|
||||
int a = 0;
|
||||
for (size_t i = 0; i < ns.len; i++) {
|
||||
if (*SpanU8_at(ns, i) != '/' && (i == 0 || *SpanU8_at(ns, i - 1) == '/'))
|
||||
a++;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
/* takes ownership of strings a, b */
|
||||
NODISCARD VecU8 codegen_T_ref_equal_T_ref(SpanU8 T, bool t_integer, VecU8 a, VecU8 b){
|
||||
if (t_integer)
|
||||
return VecU8_fmt("(%s == %s)", VecU8_to_span(&a), VecU8_to_span(&b));
|
||||
return VecU8_fmt("%s_equal_%s(%v, %v)", T, T, a, b);
|
||||
}
|
||||
|
||||
/* takes ownership of strings a, b */
|
||||
NODISCARD VecU8 codegen_T_ref_less_T_ref(SpanU8 T, bool t_integer, VecU8 a, VecU8 b){
|
||||
if (t_integer)
|
||||
return VecU8_fmt("(%s < %s)", VecU8_to_span(&a), VecU8_to_span(&b));
|
||||
return VecU8_fmt("%s_equal_%s(%v, %v)", T, T, a, b);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -387,65 +387,13 @@ NODISCARD VecU8 generate_SpanT_VecT_trivmove_collab(SpanU8 T, bool primitive, bo
|
||||
return res;
|
||||
}
|
||||
|
||||
NODISCARD VecU8 generate_OptionT_struct_and_methods(SpanU8 T, bool primitive, bool clonable) {
|
||||
VecU8 g_OptionT = VecU8_fmt("Option%s", T);
|
||||
SpanU8 OptionT = VecU8_to_span(&g_OptionT);
|
||||
|
||||
VecU8 res = VecU8_fmt(
|
||||
"typedef struct {\n"
|
||||
SPACE4 "Option_variant variant;\n"
|
||||
SPACE4 "%s some;\n"
|
||||
"} %s;\n\n", T, OptionT);
|
||||
|
||||
VecU8_append_vec(&res, VecU8_fmt("#define None_%s() (%s){ .variant = Option_None }\n\n", T, OptionT));
|
||||
VecU8_append_vec(&res, VecU8_fmt("%s Some_%s(%s obj) {\n"
|
||||
SPACE4 "return (%s){ .variant = Option_Some, .some = obj };\n"
|
||||
"}\n\n", OptionT, T, T, OptionT));
|
||||
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"const %s* %s_expect_ref(const %s* self){\n"
|
||||
SPACE4 "if (self->variant == Option_None)\n"
|
||||
SPACE4 SPACE4 "abortf(\"Expected something in const %s* got None\\n\");\n"
|
||||
SPACE4 "return &self->some;\n"
|
||||
"}\n\n", T, OptionT, OptionT, OptionT));
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"%s* %s_expect_mut_ref(%s* self){\n"
|
||||
SPACE4 "if (self->variant == Option_None)\n"
|
||||
SPACE4 SPACE4 "abortf(\"Expected something in %s* got None\\n\");\n"
|
||||
SPACE4 "return &self->some;\n"
|
||||
"}\n\n", T, OptionT, OptionT, OptionT));
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"%s %s_expect(%s self){\n"
|
||||
SPACE4 "if (self.variant == Option_None)\n"
|
||||
SPACE4 SPACE4 "abortf(\"Expected something in %s got None\\n\");\n"
|
||||
SPACE4 "return self.some;\n"
|
||||
"}\n\n", T, OptionT, OptionT, OptionT));
|
||||
if (!primitive) {
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"void %s_drop(%s self) {\n"
|
||||
SPACE4 "if (self.variant == Option_None)\n"
|
||||
SPACE4 SPACE4 "%s_drop(self.some);\n"
|
||||
"}\n\n", OptionT, OptionT, T));
|
||||
if (clonable) {
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"NODISCARD %s %s_clone(const %s* self) {\n"
|
||||
SPACE4 "if (self->variant == Option_None)\n"
|
||||
SPACE4 SPACE4 "return (%s) { .variant = Option_None };\n"
|
||||
SPACE4 "return (%s){ .variant = Option_Some, .some = %s_clone(&self->some) };\n"
|
||||
"}\n\n", OptionT, OptionT, OptionT, OptionT, OptionT, T));
|
||||
}
|
||||
}
|
||||
|
||||
VecU8_drop(g_OptionT);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* The only reason this function exists is because in C it is easier to supply a lot of brace list arguments,
|
||||
* than function arguments. This struct is an argument for generate_util_templates_instantiation
|
||||
* It is assumed that all necessary properties of T have been met, including cases where
|
||||
* T needs to be sized (everywhere) and trivially movable (for VecT)
|
||||
*/
|
||||
typedef struct {
|
||||
SpanU8 T;
|
||||
bool t_integer;
|
||||
bool t_primitive;
|
||||
bool t_clonable;
|
||||
@ -459,10 +407,10 @@ typedef struct {
|
||||
bool span_sort;
|
||||
bool collab_vec_span;
|
||||
bool collab_vec_span_extended;
|
||||
bool option;
|
||||
} util_templates_instantiation_options;
|
||||
|
||||
void util_templates_instantiation_options_fix(util_templates_instantiation_options* op) {
|
||||
assert(op->T.len > 0);
|
||||
if (op->t_integer)
|
||||
op->t_primitive = true;
|
||||
if (op->t_primitive)
|
||||
@ -483,98 +431,84 @@ void util_templates_instantiation_options_fix(util_templates_instantiation_optio
|
||||
op->span = true;
|
||||
op->vec = true;
|
||||
}
|
||||
assert(op->vec || op->span || op->option);
|
||||
assert(op->vec || op->span);
|
||||
assert(op->t_primitive || !op->t_integer);
|
||||
assert(!op->t_primitive || op->t_clonable);
|
||||
}
|
||||
|
||||
NODISCARD VecU8 generate_util_templates_instantiation(SpanU8 T, util_templates_instantiation_options op) {
|
||||
NODISCARD VecU8 generate_util_templates_instantiation(util_templates_instantiation_options op) {
|
||||
VecU8 res = VecU8_new();
|
||||
util_templates_instantiation_options_fix(&op);
|
||||
if (op.vec) {
|
||||
VecU8_append_vec(&res, generate_VecT_struct_and_base_methods(T, op.t_primitive, op.t_clonable));
|
||||
VecU8_append_vec(&res, generate_VecT_struct_and_base_methods(op.T, op.t_primitive, op.t_clonable));
|
||||
}
|
||||
if (op.vec_extended) {
|
||||
assert(op.vec);
|
||||
VecU8_append_vec(&res, generate_VecT_trivmove_extended_methods(T, op.t_primitive, op.t_clonable));
|
||||
VecU8_append_vec(&res, generate_VecT_trivmove_extended_methods(op.T, op.t_primitive, op.t_clonable));
|
||||
}
|
||||
if (op.vec_equal) {
|
||||
assert(op.vec);
|
||||
VecU8_append_vec(&res, generate_VecT_equal_method(T, op.t_integer));
|
||||
VecU8_append_vec(&res, generate_VecT_equal_method(op.T, op.t_integer));
|
||||
}
|
||||
if (op.vec_new_of_size) {
|
||||
assert(op.vec);
|
||||
VecU8_append_vec(&res, generate_VecT_new_of_size_method(T));
|
||||
VecU8_append_vec(&res, generate_VecT_new_of_size_method(op.T));
|
||||
}
|
||||
if (op.span) {
|
||||
VecU8_append_vec(&res, generate_SpanT_struct_and_methods(T, op.t_integer, op.mut_span, false, op.span_extended, op.span_sort));
|
||||
VecU8_append_vec(&res, generate_SpanT_struct_and_methods(op.T, op.t_integer, op.mut_span, false, op.span_extended, op.span_sort));
|
||||
}
|
||||
if (op.collab_vec_span) {
|
||||
assert(op.vec && op.span);
|
||||
VecU8_append_vec(&res, generate_SpanT_VecT_trivmove_collab(T, op.t_primitive, op.t_clonable, op.mut_span, op.collab_vec_span_extended));
|
||||
}
|
||||
if (op.option) {
|
||||
VecU8_append_vec(&res, generate_OptionT_struct_and_methods(T, op.t_primitive, op.t_clonable));
|
||||
VecU8_append_vec(&res, generate_SpanT_VecT_trivmove_collab(op.T, op.t_primitive, op.t_clonable, op.mut_span, op.collab_vec_span_extended));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
NODISCARD VecU8 util_templates_instantiation_get_appropriate_filename(
|
||||
SpanU8 T, util_templates_instantiation_options op
|
||||
) {
|
||||
NODISCARD VecU8 util_templates_instantiation_get_appropriate_filename(util_templates_instantiation_options op) {
|
||||
util_templates_instantiation_options_fix(&op);
|
||||
return VecU8_fmt("%s%s%s%s%s""%s%s.h",
|
||||
return VecU8_fmt("%s%s%s""%s%s.h",
|
||||
op.vec ? cstr("Vec") : cstr(""), op.vec && op.span ? cstr("And") : cstr(""), op.span ? cstr("Span") : cstr(""),
|
||||
(op.span || op.vec) && op.option ? cstr("And") : cstr(""), op.option ? cstr("Option") : cstr(""),
|
||||
(int)op.vec + (int)op.span + (int)op.option > 1 ? cstr("_") : cstr(""), T);
|
||||
(int)op.vec + (int)op.span > 1 ? cstr("_") : cstr(""), op.T);
|
||||
}
|
||||
|
||||
void generate_util_templ_inst_eve_header(SpanU8 layer, SpanU8 bonus_ns, SpanU8 T, util_templates_instantiation_options op) {
|
||||
void generate_util_templ_inst_eve_header(SpanU8 layer, SpanU8 bonus_ns, util_templates_instantiation_options op) {
|
||||
VecU8 text = VecU8_from_cstr("/* Automatically generated file. Do not edit it.\n"
|
||||
" * Do not include it in more than one place */\n\n");
|
||||
VecU8_append_vec(&text, generate_util_templates_instantiation(T, op));
|
||||
VecU8 filename = util_templates_instantiation_get_appropriate_filename(T, op);
|
||||
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/%s%c", layer, bonus_ns, VecU8_to_span(&filename), 0);
|
||||
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);
|
||||
VecU8_drop(filename);
|
||||
VecU8_drop(text);
|
||||
}
|
||||
|
||||
void generate_eve_span_company_for_primitive(SpanU8 layer, SpanU8 ns, SpanU8 T, bool with_vector, bool with_span) {
|
||||
generate_util_templ_inst_eve_header(layer, ns, T, (util_templates_instantiation_options){
|
||||
generate_util_templ_inst_eve_header(layer, ns, (util_templates_instantiation_options){
|
||||
.T = T,
|
||||
.t_primitive = true, .vec = with_vector, .span = with_span, .collab_vec_span = with_vector && with_span
|
||||
});
|
||||
}
|
||||
|
||||
void generate_eve_span_company_for_non_primitive_clonable(SpanU8 layer, SpanU8 ns, SpanU8 T, bool with_vector, bool with_span) {
|
||||
generate_util_templ_inst_eve_header(layer, ns, T, (util_templates_instantiation_options){
|
||||
generate_util_templ_inst_eve_header(layer, ns, (util_templates_instantiation_options){
|
||||
.T = T,
|
||||
.t_clonable = true, .vec = with_vector, .span = with_span, .collab_vec_span = with_vector && with_span
|
||||
});
|
||||
}
|
||||
|
||||
void generate_eve_span_company_for_non_primitive_non_clonable(SpanU8 layer, SpanU8 ns, SpanU8 T, bool with_vector, bool with_span) {
|
||||
generate_util_templ_inst_eve_header(layer, ns, T, (util_templates_instantiation_options){
|
||||
generate_util_templ_inst_eve_header(layer, ns, (util_templates_instantiation_options){
|
||||
.T = T,
|
||||
.vec = with_vector, .span = with_span, .collab_vec_span = with_vector && with_span
|
||||
});
|
||||
}
|
||||
|
||||
int get_number_of_parts_in_header_namespace(SpanU8 ns) {
|
||||
int a = 0;
|
||||
for (size_t i = 0; i < ns.len; i++) {
|
||||
if (*SpanU8_at(ns, i) != '/' && (i == 0 || *SpanU8_at(ns, i - 1) == '/'))
|
||||
a++;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
void generate_util_templ_inst_guarded_header(
|
||||
SpanU8 layer, SpanU8 bonus_ns, SpanU8 T, SpanU8 dependencies,
|
||||
util_templates_instantiation_options op
|
||||
SpanU8 layer, SpanU8 bonus_ns, SpanU8 dependencies, util_templates_instantiation_options op
|
||||
) {
|
||||
assert(layer.len > 1);
|
||||
VecU8 filename = util_templates_instantiation_get_appropriate_filename(T, op);
|
||||
VecU8 filename = util_templates_instantiation_get_appropriate_filename(op);
|
||||
VecU8 path = VecU8_fmt("%s/%s%s%s", layer, bonus_ns, bonus_ns.len ? cstr("/") : cstr(""), VecU8_to_span(&filename));
|
||||
GeneratedHeader head = begin_header(VecU8_to_span(&path));
|
||||
VecU8_drop(path);
|
||||
@ -586,14 +520,15 @@ void generate_util_templ_inst_guarded_header(
|
||||
VecU8_append_span(&head.result, cstr("src/l1/core/util.h\"\n"));
|
||||
VecU8_append_span(&head.result, dependencies);
|
||||
VecU8_append_span(&head.result, cstr("\n\n"));
|
||||
VecU8_append_vec(&head.result, generate_util_templates_instantiation(T, op));
|
||||
VecU8_append_vec(&head.result, generate_util_templates_instantiation(op));
|
||||
finish_header(head);
|
||||
}
|
||||
|
||||
void generate_guarded_span_company_for_primitive(
|
||||
SpanU8 layer, SpanU8 ns, SpanU8 T, SpanU8 dependencies, bool with_vector, bool with_span
|
||||
) {
|
||||
generate_util_templ_inst_guarded_header(layer, ns, T, dependencies, (util_templates_instantiation_options){
|
||||
generate_util_templ_inst_guarded_header(layer, ns, dependencies, (util_templates_instantiation_options){
|
||||
.T = T,
|
||||
.t_primitive = true, .vec = with_vector, .span = with_span, .collab_vec_span = with_vector && with_span
|
||||
});
|
||||
}
|
||||
@ -601,7 +536,8 @@ void generate_guarded_span_company_for_primitive(
|
||||
void generate_guarded_span_company_for_non_primitive_clonable(
|
||||
SpanU8 layer, SpanU8 ns, SpanU8 T, SpanU8 dependencies, bool with_vector, bool with_span
|
||||
) {
|
||||
generate_util_templ_inst_guarded_header(layer, ns, T, dependencies, (util_templates_instantiation_options){
|
||||
generate_util_templ_inst_guarded_header(layer, ns, dependencies, (util_templates_instantiation_options){
|
||||
.T = T,
|
||||
.t_clonable = true, .vec = with_vector, .span = with_span, .collab_vec_span = with_vector && with_span
|
||||
});
|
||||
}
|
||||
@ -609,9 +545,106 @@ void generate_guarded_span_company_for_non_primitive_clonable(
|
||||
void generate_guarded_span_company_for_non_primitive_non_clonable(
|
||||
SpanU8 layer, SpanU8 ns, SpanU8 T, SpanU8 dependencies, bool with_vector, bool with_span
|
||||
) {
|
||||
generate_util_templ_inst_guarded_header(layer, ns, T, dependencies, (util_templates_instantiation_options){
|
||||
generate_util_templ_inst_guarded_header(layer, ns, dependencies, (util_templates_instantiation_options){
|
||||
.T = T,
|
||||
.vec = with_vector, .span = with_span, .collab_vec_span = with_vector && with_span
|
||||
});
|
||||
}
|
||||
|
||||
typedef struct{
|
||||
SpanU8 T;
|
||||
bool t_ptr;
|
||||
bool t_integer;
|
||||
bool t_primitive;
|
||||
bool t_clonable;
|
||||
} option_template_instantiation_op;
|
||||
|
||||
void option_template_instantiation_op_fix(option_template_instantiation_op* self){
|
||||
assert(self->T.len > 0);
|
||||
if (self->t_ptr)
|
||||
self->t_integer = true;
|
||||
if (self->t_integer)
|
||||
self->t_primitive = true;
|
||||
if (self->t_primitive)
|
||||
self->t_clonable = true;
|
||||
}
|
||||
|
||||
NODISCARD VecU8 generate_OptionT_struct_and_methods(option_template_instantiation_op op) {
|
||||
VecU8 g_OptionT = VecU8_fmt("Option%s", op.T);
|
||||
SpanU8 OptionT = VecU8_to_span(&g_OptionT);
|
||||
|
||||
VecU8 res = VecU8_new();
|
||||
if (op.t_ptr) {
|
||||
VecU8_append_vec(&res, VecU8_fmt("typedef %s %s;\n", op.T, OptionT));
|
||||
VecU8_append_vec(&res, VecU8_fmt("#define None_%s() NULL\n", op.T));
|
||||
VecU8_append_vec(&res, VecU8_fmt("%s Some_%s(%s ref) {\n" SPACE4 "return ref;\n}\n\n", OptionT, op.T, op.T));
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"%s %s_expect(%s self) {\n"
|
||||
SPACE4 "return self;\n"
|
||||
"}\n\n", op.T, OptionT, OptionT));
|
||||
} else {
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"typedef struct {\n"
|
||||
SPACE4 "Option_variant variant;\n"
|
||||
SPACE4 "%s some;\n"
|
||||
"} %s;\n\n", op.T, OptionT));
|
||||
VecU8_append_vec(&res, VecU8_fmt("#define None_%s() (%s){ .variant = Option_None }\n\n", op.T, OptionT));
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"NODISCARD %s Some_%s(%s obj) {\n"
|
||||
SPACE4 "return (%s){ .variant = Option_Some, .some = obj };\n"
|
||||
"}\n\n", OptionT, op.T, op.T, OptionT));
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"NODISCARD %s %s_expect(%s self){\n"
|
||||
SPACE4 "if (self.variant == Option_None)\n"
|
||||
SPACE4 SPACE4 "abortf(\"Expected something in %s got None\\n\");\n"
|
||||
SPACE4 "return self.some;\n"
|
||||
"}\n\n", op.T, OptionT, OptionT, OptionT));
|
||||
if (!op.t_primitive) {
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"void %s_drop(%s self) {\n"
|
||||
SPACE4 "if (self.variant == Option_None)\n"
|
||||
SPACE4 SPACE4 "%s_drop(self.some);\n"
|
||||
"}\n\n", OptionT, OptionT, op.T));
|
||||
if (op.t_clonable) {
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"NODISCARD %s %s_clone(const %s* self) {\n"
|
||||
SPACE4 "if (self->variant == Option_None)\n"
|
||||
SPACE4 SPACE4 "return (%s) { .variant = Option_None };\n"
|
||||
SPACE4 "return (%s){ .variant = Option_Some, .some = %s_clone(&self->some) };\n"
|
||||
"}\n\n", OptionT, OptionT, OptionT, OptionT, OptionT, op.T));
|
||||
}
|
||||
}
|
||||
}
|
||||
VecU8_drop(g_OptionT);
|
||||
return res;
|
||||
}
|
||||
|
||||
void generate_Option_templ_inst_eve_header(SpanU8 layer, SpanU8 bonus_ns, option_template_instantiation_op op) {
|
||||
VecU8 text = VecU8_from_cstr("/* Automatically generated file. Do not edit it.\n"
|
||||
" * Do not include it in more than one place */\n\n");
|
||||
VecU8_append_vec(&text, generate_OptionT_struct_and_methods(op));
|
||||
VecU8 nt_path = VecU8_fmt("%s/eve/%s/Option%s%c", layer, bonus_ns, op.T, 0);
|
||||
write_whole_file_or_abort((const char*)nt_path.buf, VecU8_to_span(&text));
|
||||
VecU8_drop(nt_path);
|
||||
VecU8_drop(text);
|
||||
}
|
||||
|
||||
void generate_Option_templ_inst_guarded_header(
|
||||
SpanU8 layer, SpanU8 bonus_ns, SpanU8 dependencies, option_template_instantiation_op op
|
||||
) {
|
||||
assert(layer.len > 1);
|
||||
VecU8 path = VecU8_fmt("%s/%s%sOption%s.h", layer, bonus_ns, bonus_ns.len ? cstr("/") : cstr(""), op.T);
|
||||
GeneratedHeader head = begin_header(VecU8_to_span(&path));
|
||||
VecU8_drop(path);
|
||||
VecU8_append_span(&head.result, cstr("#include \"../../"));
|
||||
int to_my_layer = get_number_of_parts_in_header_namespace(bonus_ns);
|
||||
for (int i = 0; i < to_my_layer; i++)
|
||||
VecU8_append_span(&head.result, cstr("../"));
|
||||
VecU8_append_span(&head.result, cstr("src/l1/core/util.h\"\n"));
|
||||
VecU8_append_span(&head.result, dependencies);
|
||||
VecU8_append_span(&head.result, cstr("\n\n"));
|
||||
VecU8_append_vec(&head.result, generate_OptionT_struct_and_methods(op));
|
||||
finish_header(head);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -19,6 +19,8 @@ VecU8 VecU8_from_cstr(const char* dc) {
|
||||
SpanU8 SpanU8_from_cstr(const char* dc) {
|
||||
return (SpanU8){.data = (const U8*)dc, .len = strlen(dc)};
|
||||
}
|
||||
|
||||
#define vcstr(dc) (VecU8_from_cstr(dc))
|
||||
#define cstr(dc) ((SpanU8){(const U8*)dc, sizeof(dc) - 1})
|
||||
|
||||
/* Not thread safe (for stdout) !*/
|
||||
@ -57,6 +59,82 @@ NODISCARD VecU8 VecU8_format(const char *fmt, ...) {
|
||||
return (VecU8){ .buf = buf, .len = len, .capacity = len + 1 };
|
||||
}
|
||||
|
||||
size_t S64_stringification_get_length(S64 x){
|
||||
if (x == -9223372036854775807L-1)
|
||||
return 20;
|
||||
int i = 0;
|
||||
if (x <= 0) {
|
||||
x = -x;
|
||||
i++;
|
||||
}
|
||||
while (x > 0) {
|
||||
i++;
|
||||
x /= 10;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void S64_stringification_into_buf(S64 x, VecU8* targ){
|
||||
if (x == 0) {
|
||||
VecU8_append(targ, '0');
|
||||
} else if (x == -9223372036854775807L-1) {
|
||||
VecU8_append_span(targ, cstr("-9223372036854775807"));
|
||||
} else {
|
||||
if (x < 0) {
|
||||
VecU8_append(targ, '-');
|
||||
x = -x;
|
||||
}
|
||||
int digits = 0;
|
||||
while (x > 0) {
|
||||
VecU8_append(targ, '0' + (x % 10));
|
||||
x /= 10;
|
||||
digits++;
|
||||
}
|
||||
U8* left = targ->buf + targ->len - digits;
|
||||
U8* right = targ->buf + targ->len - 1;
|
||||
while (left < right) {
|
||||
U8 t = *right;
|
||||
*right = *left;
|
||||
*left = t;
|
||||
left++;
|
||||
right++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t U64_stringification_get_length(U64 x){
|
||||
if (x == 0)
|
||||
return 1;
|
||||
int i = 0;
|
||||
while (x > 0) {
|
||||
i++;
|
||||
x /= 10;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void U64_stringification_into_buf(U64 x, VecU8* targ){
|
||||
if (x == 0) {
|
||||
VecU8_append(targ, '0');
|
||||
} else {
|
||||
int digits = 0;
|
||||
while (x > 0) {
|
||||
VecU8_append(targ, '0' + (x % 10));
|
||||
x /= 10;
|
||||
digits++;
|
||||
}
|
||||
U8* left = targ->buf + targ->len - digits;
|
||||
U8* right = targ->buf + targ->len - 1;
|
||||
while (left < right) {
|
||||
U8 t = *right;
|
||||
*right = *left;
|
||||
*left = t;
|
||||
left++;
|
||||
right++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// todo: add %d (when I figure out how to do it)
|
||||
NODISCARD VecU8 VecU8_fmt(const char* fmt, ...) {
|
||||
assert(fmt);
|
||||
@ -73,7 +151,17 @@ NODISCARD VecU8 VecU8_fmt(const char* fmt, ...) {
|
||||
k += s.len;
|
||||
} else if (*ch == 'c') {
|
||||
va_arg(args, int);
|
||||
k ++;
|
||||
k++;
|
||||
} else if (*ch == 'v') {
|
||||
/* We had not taken ownership of YET (will take it the next iteration) */
|
||||
VecU8 vs = va_arg(args, VecU8);
|
||||
k += vs.len;
|
||||
} else if (*ch == 's') {
|
||||
S64 x = va_arg(args, S64);
|
||||
k += S64_stringification_get_length(x);
|
||||
} else if (*ch == 'u') {
|
||||
U64 x = va_arg(args, U64);
|
||||
k += U64_stringification_get_length(x);
|
||||
} else
|
||||
abortf("Format syntax error at pos %lu! Watch out, be careful", (size_t)(ch - fmt));
|
||||
} else {
|
||||
@ -95,6 +183,15 @@ NODISCARD VecU8 VecU8_fmt(const char* fmt, ...) {
|
||||
} else if (*ch == 'c') {
|
||||
int byte = va_arg(args, int);
|
||||
VecU8_append(&res, (U8)byte);
|
||||
} else if (*ch == 'v') {
|
||||
VecU8 vs = va_arg(args, VecU8);
|
||||
VecU8_append_vec(&res, vs); /* Moved ownership of vs argument */
|
||||
} else if (*ch == 's') {
|
||||
S64 x = va_arg(args, S64);
|
||||
S64_stringification_into_buf(x, &res);
|
||||
} else if (*ch == 'u') {
|
||||
U64 x = va_arg(args, U64);
|
||||
U64_stringification_into_buf(x, &res);
|
||||
} else
|
||||
assert(false);
|
||||
} else {
|
||||
|
||||
135
src/l1_5/codegen/all_set_map_templ_util_inst.h
Normal file
135
src/l1_5/codegen/all_set_map_templ_util_inst.h
Normal file
@ -0,0 +1,135 @@
|
||||
#ifndef PROTOTYPE1_SRC_L1_5_CODEGEN_ALL_SET_MAP_TEMPL_UTIL_INST_H
|
||||
#define PROTOTYPE1_SRC_L1_5_CODEGEN_ALL_SET_MAP_TEMPL_UTIL_INST_H
|
||||
|
||||
#include "../../l1/codegen/util_template_inst.h"
|
||||
|
||||
// todo: continue from here
|
||||
|
||||
/* We assume that T is trivially movable */
|
||||
typedef struct {
|
||||
SpanU8 T;
|
||||
bool t_ptr;
|
||||
bool t_integer;
|
||||
bool t_primitive;
|
||||
bool t_clonable;
|
||||
} set_instantiation_op;
|
||||
|
||||
void set_instantiation_op_fix(set_instantiation_op* self){
|
||||
assert(self->T.len > 0);
|
||||
if (self->t_ptr)
|
||||
self->t_integer = true;
|
||||
if (self->t_integer)
|
||||
self->t_primitive = true;
|
||||
if (self->t_primitive)
|
||||
self->t_clonable = true;
|
||||
}
|
||||
|
||||
// /* K and V still must be sized and trivially movable */
|
||||
// typedef struct {
|
||||
// SpanU8 K;
|
||||
// bool k_integer;
|
||||
// bool k_primitive;
|
||||
// bool k_clonable;
|
||||
// SpanU8 V;
|
||||
// bool v_primitive;
|
||||
// bool v_clonable;
|
||||
// } map_instantiation_options;
|
||||
//
|
||||
// void map_instantiation_options_fix(map_instantiation_options* self){
|
||||
// if (self->K.len == 0)
|
||||
// abortf("Key cannot be void");
|
||||
// if (self->k_integer)
|
||||
// self->k_primitive = true;
|
||||
// if (self->k_primitive)
|
||||
// self->k_clonable = true;
|
||||
//
|
||||
// if (self->V.len == 0)
|
||||
// self->v_primitive = true;
|
||||
// if (self->v_primitive)
|
||||
// self->v_clonable = true;
|
||||
// }
|
||||
|
||||
|
||||
// NODISCARD VecU8 codegen_expr_MapKToV_option_ref_mut_pair_type(map_instantiation_options op){
|
||||
// if (op.V.len)
|
||||
// return VecU8_fmt("OptionRefMutPairMap%sTo%s", op.K, op.V);
|
||||
// return VecU8_fmt("OptionRefMut%s", op.K);
|
||||
// }
|
||||
//
|
||||
// /* Generates PairMapKToV structure + [drop] + [clone] methods
|
||||
// * Instantiates Option<PairMapKToV> and Vec<PairMapKToV>
|
||||
// * Generates alias RefPairMapKToV = const PairMapKToV*
|
||||
// * Instantiates Option<RefPairMapKToV> template
|
||||
// * Generates RefMutMapKToV structure (const ptr to key with mutable ptr to value)
|
||||
// * Instantiates Option<RefMutPairMapKToV> template
|
||||
// * If `vec_vec_pair_needed` option is set, Vec<Vec<PairMapKToV>> template will be instantiated
|
||||
// * Vec<Vec<PairMapKToV>> is needed in Hash_Map implementation
|
||||
// */
|
||||
// NODISCARD VecU8 generate_MapKToV_pair_type(map_instantiation_options op, bool vec_vec_pair_needed){
|
||||
// map_instantiation_options_fix(&op);
|
||||
// if (op.V.len == 0)
|
||||
// abortf("No need to generate structure for Key Value pair when Value is void\n");
|
||||
// VecU8 g_pair = codegen_expr_MapKToV_pair_type(op);
|
||||
// SpanU8 pair = VecU8_to_span(&g_pair);
|
||||
// VecU8 result = VecU8_fmt(
|
||||
// "typedef struct {\n"
|
||||
// SPACE4 "%s key;\n"
|
||||
// SPACE4 "%s value;\n"
|
||||
// "} %s;\n\n", op.K, op.V, pair);
|
||||
//
|
||||
// if (!op.k_primitive || !op.v_primitive) {
|
||||
// VecU8_append_vec(&result, VecU8_fmt("void %s_drop(%s self) {\n", pair, pair));
|
||||
// if (!op.k_primitive)
|
||||
// VecU8_append_vec(&result, VecU8_fmt("%s_drop();\n", op.K));
|
||||
// if (!op.v_primitive)
|
||||
// VecU8_append_vec(&result, VecU8_fmt("%s_drop();\n", op.V));
|
||||
// VecU8_append_span(&result, cstr("}\n\n"));
|
||||
// }
|
||||
//
|
||||
// if (op.k_clonable && op.v_clonable && !(op.k_primitive && op.v_primitive)) {
|
||||
// VecU8_append_vec(&result, VecU8_fmt("%s%s %s_clone(const %s* self) {\n",
|
||||
// (op.k_primitive && op.v_primitive) ? cstr("") : cstr("NODISCARD"), pair, pair, pair));
|
||||
// VecU8_append_vec(&result, VecU8_fmt(
|
||||
// SPACE4 "return (%s) {.key = %v, .value = %v};\n"
|
||||
// "}\n\n",
|
||||
// op.k_primitive ? vcstr("self->key") : VecU8_fmt("%s_clone(&self->key)"),
|
||||
// op.v_primitive ? vcstr("self->value") : VecU8_fmt("%s_clone(&self->value)")));
|
||||
// }
|
||||
//
|
||||
// VecU8_append_vec(&result, generate_util_templates_instantiation(pair, (util_templates_instantiation_options){
|
||||
// .t_integer = op.k_integer, .t_primitive = op.k_primitive, .t_clonable = op.k_clonable,
|
||||
// .vec = true, .vec_extended = true, .option = true}));
|
||||
//
|
||||
// VecU8 g_vec_pair = codegen_expr_MapKToV_vec_pair_type(op);
|
||||
// SpanU8 vec_pair = VecU8_to_span(&g_vec_pair);
|
||||
// VecU8 g_ref_pair = codegen_expr_MapKToV_ref_pair_type(op);
|
||||
// SpanU8 ref_pair = VecU8_to_span(&g_ref_pair);
|
||||
//
|
||||
// VecU8_append_vec(&result, VecU8_fmt("typedef const %s* %s;\n\n", pair, ref_pair));
|
||||
// VecU8_append_vec(&result, generate_util_templates_instantiation(ref_pair,
|
||||
// (util_templates_instantiation_options){.t_integer = true, .option = true}));
|
||||
//
|
||||
// VecU8 g_ref_mut_pair = codegen_expr_MapKToV_ref_mut_pair_type(op);
|
||||
// SpanU8 ref_mut_pair = VecU8_to_span(&g_ref_pair);
|
||||
//
|
||||
// VecU8_append_vec(&result, VecU8_fmt(
|
||||
// "typedef struct {\n"
|
||||
// SPACE4 "const %s* key;\n"
|
||||
// SPACE4 "%s* value;\n"
|
||||
// "} %s\n\n", op.K, op.V, ref_mut_pair));
|
||||
// VecU8_append_vec(&result, generate_util_templates_instantiation(ref_mut_pair,
|
||||
// (util_templates_instantiation_options){.t_integer = true, .option = true}));
|
||||
//
|
||||
// if (vec_vec_pair_needed) {
|
||||
// VecU8_append_vec(&result, generate_util_templates_instantiation(vec_pair,
|
||||
// (util_templates_instantiation_options){.vec = true}));
|
||||
// }
|
||||
//
|
||||
// VecU8_drop(g_ref_mut_pair);
|
||||
// VecU8_drop(g_ref_pair);
|
||||
// VecU8_drop(g_vec_pair);
|
||||
// VecU8_drop(g_pair);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
#endif
|
||||
102
src/l1_5/codegen/rb_tree_set_map_template_inst.h
Normal file
102
src/l1_5/codegen/rb_tree_set_map_template_inst.h
Normal file
@ -0,0 +1,102 @@
|
||||
#ifndef PROTOTYPE1_SRC_L1_5_CODEGEN_RB_TREE_SET_MAP_TEMPLATE_INST_H
|
||||
#define PROTOTYPE1_SRC_L1_5_CODEGEN_RB_TREE_SET_MAP_TEMPLATE_INST_H
|
||||
|
||||
#include "all_set_map_templ_util_inst.h"
|
||||
|
||||
NODISCARD VecU8 generate_rb_tree_set_template_instantiation(set_instantiation_op op){
|
||||
VecU8 res = VecU8_new();
|
||||
VecU8 set = VecU8_fmt("BuffRBTree_Set%s", op.T);
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"typedef struct {\n"
|
||||
SPACE4 ""
|
||||
"}\n\n"
|
||||
));
|
||||
// todo: continue from here after I finish the dumb option shit
|
||||
VecU8_drop(set);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* This type will require not only the definition of T=MapPair<K, V>, but also Vec<T>, Option<>, Option<&mut T> and Option<&T>
|
||||
* Also it requires l1_5/core/rb_tree_node.h to be included by that point */
|
||||
// NODISCARD VecU8 generate_rb_tree_set_template_instantiation(map_instantiation_options op, bool
|
||||
// bool implementation_mark){
|
||||
// VecU8 g_map = get_rb_tree_MapKToV_name(op, implementation_mark);
|
||||
// SpanU8 map = VecU8_to_span(&g_map);
|
||||
// VecU8 g_pair = get_MapKToV_pair_name(op);
|
||||
// SpanU8 pair = VecU8_to_span(&g_pair);
|
||||
// VecU8 g_vec_pair = VecU8_fmt("Vec%s", pair);
|
||||
// SpanU8 vec_pair = VecU8_to_span(&g_vec_pair);
|
||||
// VecU8 g_option_pair = VecU8_fmt("Option%s", pair);
|
||||
// SpanU8 option_pair = VecU8_to_span(&g_option_pair);
|
||||
// VecU8 g_option_ref_pair = VecU8_fmt("OptionRef%s", pair);
|
||||
// SpanU8 option_ref_pair = VecU8_to_span(&g_option_ref_pair);
|
||||
// VecU8 g_option_ref_mut_pair = VecU8_fmt("OptionRefMut%s", pair);
|
||||
// SpanU8 option_ref_mut_pair = VecU8_to_span(&g_option_ref_mut_pair);
|
||||
//
|
||||
// VecU8 res = VecU8_new();
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "typedef struct {\n"
|
||||
// SPACE4 "VecRBTreeNode tree;\n"
|
||||
// SPACE4 "size_t root;\n"
|
||||
// SPACE4 "%s el;\n"
|
||||
// "} %s;\n\n", vec_pair, map));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "NODISCARD %s %s_new() {\n"
|
||||
// SPACE4 "return (%s){.tree = VecRBTreeNode_new_zeroinit(1), .root = 0, .el = %s_new()};\n"
|
||||
// "}\n\n", map, map, map, vec_pair));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "NODISCARD %s %s_new_reserved(size_t n) {\n"
|
||||
// SPACE4 "return (%s){.tree = VecRBTreeNode_new_reserved(1 + n), .root = 0, .el = %s_new_reserved(n)};\n"
|
||||
// "}\n\n", map, map, map, vec_pair));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "void %s_drop(%s self) {\n"
|
||||
// SPACE4 "VecRBTreeNode_drop(self.tree);\n"
|
||||
// SPACE4 "%s_drop(self.el);\n"
|
||||
// "}\n\n", vec_pair));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "bool %s_contains(const %s* self, const %s* key){\n"
|
||||
// SPACE4 "size_t cur = self->root;\n"
|
||||
// SPACE4 "while (cur > 0) {\n"
|
||||
// SPACE4 SPACE4 "const RBTreeNode* node = VecRBTreeNode_at(&self->tree, cur);\n"
|
||||
// SPACE4 SPACE4 "if %v\n"
|
||||
// SPACE4 SPACE4 SPACE4 "return true;\n"
|
||||
// SPACE4 SPACE4 "cur = %v ? node->left : node -> right;\n"
|
||||
// SPACE4 "}\n"
|
||||
// SPACE4 "return false\n"
|
||||
// "}\n\n", map, map, op.K,
|
||||
// codegen_T_ref_equal_T_ref(op.K, op.k_integer, vcstr("key"), codegen_rb_tree_el_keyptr(op, cstr("cur"))),
|
||||
// codegen_T_ref_less_T_ref(op.K, op.k_integer, vcstr("key"), codegen_rb_tree_el_keyptr(op, cstr("cur")))));
|
||||
//
|
||||
// /* Map may want to get mutable reference to Value of minimal pair
|
||||
// * Btw, UB happens when you call this function on an empty map
|
||||
// */
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "const %s* %s_min_unsafe(const %s* self) {\n"
|
||||
// SPACE4 "size_t cur = self->root;\n"
|
||||
// SPACE4 "while (self->tree[cur]->left) {\n"
|
||||
// SPACE4 SPACE4 "cur = self->tree[cur]->left;\n"
|
||||
// SPACE4"}\n"
|
||||
// SPACE4 "return &self->el[cur - 1]\n"
|
||||
// "\n\n", pair, ));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "const %s* %s_max_unsafe(const %s* self) {\n"
|
||||
// SPACE4 "size_t cur = self->root;\n"
|
||||
// SPACE4 "while (self->tree[cur]->left) {\n"
|
||||
// SPACE4 SPACE4 "cur = self->tree[cur]->left;\n"
|
||||
// SPACE4"}\n"
|
||||
// SPACE4 "return &self->el[cur - 1]\n"
|
||||
// "\n\n", T, set));
|
||||
//
|
||||
// VecU8_drop(g_option);
|
||||
// VecU8_drop(g_vec);
|
||||
// VecU8_drop(g_set);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
#endif
|
||||
19
src/l1_5/core/rb_tree_node.h
Normal file
19
src/l1_5/core/rb_tree_node.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef PROTOTYPE1_SRC_L1_5_CORE_RB_TREE_NODE_H
|
||||
#define PROTOTYPE1_SRC_L1_5_CORE_RB_TREE_NODE_H
|
||||
|
||||
#include "../../l1/core/util.h"
|
||||
|
||||
|
||||
#define RBTree_black 0
|
||||
#define RBTree_red 1
|
||||
|
||||
typedef struct {
|
||||
size_t left;
|
||||
size_t right;
|
||||
size_t parent;
|
||||
bool color;
|
||||
} RBTreeNode;
|
||||
|
||||
#include "../../../gen/l1/eve/embassy_l1_5/VecRBTreeNode.h"
|
||||
|
||||
#endif
|
||||
@ -22,7 +22,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
void* r;
|
||||
const LizaSound_Table* t;
|
||||
} MutRefLizaSound;
|
||||
} RefMutLizaSound;
|
||||
|
||||
/* Existence of Box<Trait> type implies that _drop method is virtual according to this trait */
|
||||
typedef struct {
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "../../../gen/l1/vulkan/VecAndOption_VkPresentModeKHR.h"
|
||||
#include "../../../gen/l1/vulkan/VecAndOption_VkSurfaceFormatKHR.h"
|
||||
#include <vulkan/vulkan_wayland.h>
|
||||
// #include <vulkan/vulkan.h>
|
||||
|
||||
|
||||
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
#include "../../../l1/system/pthread.h"
|
||||
#include "../../margaret/time_utils.h"
|
||||
|
||||
// todo: delete this file
|
||||
|
||||
#define DEFAULT_RATE 44100
|
||||
#define DEFAULT_CHANNELS 2
|
||||
#define DEFAULT_VOLUME 0.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user