文件
PazeE-Language/test_comprehensive.pe
JGZ_YES 7b0a4c535b feat(los4): add pure C compiler targeting Los4 ELF
Add src/PazeE.los4/ — a pure C implementation of the PazeE compiler
that generates static Los4 ELF executables (x86-64, int 0x80 syscalls).

Core components:
- Lexer, preprocessor, recursive-descent parser, AST
- Tree-walking interpreter (paze run) with breakpoints
- x86-64 code generator (SysV AMD64 ABI)
- Los4 ELF writer (4 PH layout matching doomlauncher.elf, base 0x400000)
- Runtime library as raw machine code: printf, sprintf, puts, malloc,
  memcpy, memset, strcmp, strlen, exit, etc.

Key fixes:
- Fix use-after-free: AST paze_str_t slices point into source buffer,
  so free(src) is deferred until after interpreter/codegen completes
- printf/sprintf support %d/%i/%u/%x/%c/%s/%% with rel32 jumps
- External function calls resolved via runtime offset lookup

All 14 test cases pass for both paze run and paze build.

Also includes DebuggerVM.cs and Program.cs updates for the C# compiler.
2026-08-10 21:32:39 +08:00

63 行
1.3 KiB
Plaintext

#include <paze.h>
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
int fibonacci(int n) {
if (n <= 1) return n;
int a = 0, b = 1;
for (int i = 2; i <= n; i++) {
int temp = a + b;
a = b;
b = temp;
}
return b;
}
int main(void) {
printf("=== PazeE Comprehensive Test ===\n");
// Test typedef
paze_uint64_t big_num = 123456789ULL;
printf("big_num = %llu\n", big_num);
// Test arithmetic
int x = 10, y = 3;
printf("x + y = %d\n", x + y);
printf("x - y = %d\n", x - y);
printf("x * y = %d\n", x * y);
printf("x / y = %d\n", x / y);
printf("x %% y = %d\n", x % y);
// Test loops
printf("Counting: ");
for (int i = 0; i < 5; i++) {
printf("%d ", i);
}
printf("\n");
// Test while loop
printf("While: ");
int i = 0;
while (i < 3) {
printf("%d ", i);
i++;
}
printf("\n");
// Test functions
printf("factorial(5) = %d\n", factorial(5));
printf("fibonacci(10) = %d\n", fibonacci(10));
// Test do-while
int n = 0;
do {
printf("do-while: %d\n", n);
n++;
} while (n < 2);
printf("=== All tests passed! ===\n");
return 0;
}