From d2cad703b1732650fb39a8f26ba0e221152cfd34 Mon Sep 17 00:00:00 2001 From: Andreew Gregory Date: Thu, 16 Oct 2025 04:01:32 +0300 Subject: [PATCH] Whoopsie, found segfault --- .gitignore | 3 ++- Makefile | 2 +- src/l1/sobiralka.py | 22 ++++++++++++---------- src/l2/marie/graphics_geom.h | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index fa9c71a..912e641 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ vgcore.* *_TEMPLATE.png /out GRAPH*.gv -GRAPH*.png \ No newline at end of file +GRAPH*.png +SICK_JOKE* diff --git a/Makefile b/Makefile index 1e52fb4..c47440f 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ HEADERS_src_l2 := $(HEADERS_gen_l1_5) $(call find_headers,l2) HEADERS_gen_l2 := $(HEADERS_src_l2) gen/l2/dorothy.txt cflags := -Wall -Wextra -Werror=implicit-function-declaration -Werror=return-type -Wno-unused-parameter \ - --std=c99 -g -ggdb -O0 \ + --std=c99 -g -ggdb -O3 \ -fno-trapping-math -D_POSIX_C_SOURCE=200112L -D_GNU_SOURCE cc := gcc diff --git a/src/l1/sobiralka.py b/src/l1/sobiralka.py index 5feecae..98b928d 100644 --- a/src/l1/sobiralka.py +++ b/src/l1/sobiralka.py @@ -108,7 +108,7 @@ def parse_second_quoted_path(s): return s[start:p.index] -def analyze_file(lines_dirty) -> List[LineToken]: +def analyze_file(lines_dirty, alien_headers: Set[str]) -> List[LineToken]: lines = list(map(lambda x: x.rstrip(), lines_dirty)) i = 0 tokens = [] @@ -130,7 +130,7 @@ def analyze_file(lines_dirty) -> List[LineToken]: if directive == 'include': local_file = parse_second_quoted_path(line) - if local_file is not None: + if (local_file is not None) and (local_file not in alien_headers): tokens.append(LineToken(type = token_type_include_local, filepath=local_file, original=original_lines)) else: @@ -165,7 +165,7 @@ def analyze_file(lines_dirty) -> List[LineToken]: # Returns new_i, block (text + new_symbol_set) def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[str], i: int, input_dir, - take_seriously: bool) -> Tuple[int, IfDirBlock]: + take_seriously: bool, alien_headers: Set[str]) -> Tuple[int, IfDirBlock]: output = "" symbols_here = defined_symbols_outside.copy() @@ -212,7 +212,8 @@ def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[s token_type_elif, token_type_elifdef, token_type_elifndef, token_type_else]: i, block_in_front = process_part_of_file(tokens, symbols_here, i, input_dir, (saw_match == len(in_if) or (t in [token_type_if, token_type_elif]) or - (t == token_type_else and saw_unevaluatable_condition)) and take_seriously) + (t == token_type_else and saw_unevaluatable_condition)) and take_seriously, + alien_headers) in_if.append(IfDirCondAndBlock(cond=token, inside=block_in_front)) if t == token_type_endif: @@ -239,7 +240,7 @@ def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[s include_path = os.path.join(input_dir, token.filepath) if not os.path.isfile(include_path): raise ValueError(f"No such file {include_path}") - included_output = process_file(include_path, symbols_here) + included_output = process_file(include_path, symbols_here, alien_headers) output += included_output.text symbols_here = included_output.new_symbol_set else: @@ -252,12 +253,12 @@ def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[s return i, IfDirBlock(text=output, new_symbol_set=symbols_here) # Returns block (text + new_symbols) -def process_file(file_path, symbols_here) -> IfDirBlock: +def process_file(file_path, symbols_here: Set[str], alien_headers: Set[str]) -> IfDirBlock: input_dir = os.path.dirname(os.path.abspath(file_path)) with open(file_path, 'r') as f: lines = f.readlines() - tokens = analyze_file(lines) - end_i, block = process_part_of_file(tokens, symbols_here, 0, input_dir, True) + tokens = analyze_file(lines, alien_headers) + end_i, block = process_part_of_file(tokens, symbols_here, 0, input_dir, True, alien_headers) assert end_i == len(tokens) return block @@ -267,14 +268,15 @@ def main(): parser.add_argument('input_file', type=str, help="Input C file path") parser.add_argument('output_file', type=str, help="Output C file path") parser.add_argument('-D', action='append', default=[], help="Define symbols") + parser.add_argument('-I', action='append', default=[], help="Imaginary headers from the other side") args = parser.parse_args() defined_symbols = set(args.D) + alien_headers = set(args.I) - entire_program = process_file(args.input_file, defined_symbols) + entire_program = process_file(args.input_file, defined_symbols, alien_headers) with open(args.output_file, 'w') as f: f.write(entire_program.text) if __name__ == "__main__": main() - diff --git a/src/l2/marie/graphics_geom.h b/src/l2/marie/graphics_geom.h index 97cbcbe..4bad928 100644 --- a/src/l2/marie/graphics_geom.h +++ b/src/l2/marie/graphics_geom.h @@ -2,7 +2,7 @@ #define PROTOTYPE1_SRC_L2_MARIE_GRAPHICS_GEOM_H #include "../../../gen/l1/geom.h" -#include "math.h" +#include mat4 marie_translation_mat4(vec3 vec) { return mat4_new(