今日已更新 80 条资讯 | 累计 20052 条内容
关于我们

Codegen to C: Native Binaries from Pascal (v2.18.0) | Codegen para C: binários nativos a partir de Pascal (v2.18.0)

CrabPascal 2026年06月04日 15:00 4 次阅读 来源:Dev.to

Bilingual post · Post bilíngue Jump to: English · Português English {#english} Codegen to C: Native Binaries from Pascal (v2.18.0) Sprint 10 ( v2.18.0 ) closes the loop on CrabPascal's most ambitious feature: turning Pascal source into real native executables via C codegen — with string builtins that actually match the interpreter. The pipeline Pascal (.dpr/.pas) → AST → C source + stubs.c → gcc/clang → native binary run skips the last steps and executes in Rust. build-exe is for when you want an .exe or ELF on disk without carrying the CrabPascal runtime as a dependency. End-to-end example program NativeHello ; uses System . SysUtils ; begin WriteLn ( Trim ( ' Hello, native world! ' )); end . crab-pascal build-exe NativeHello.dpr ./NativeHello # or NativeHello.exe on Windows Expected output: Hello, native world! — no leading or trailing spaces. What Sprint 10 fixed Parser: Trim , Copy , Length , and friends are recognized as SysUtils builtins , not mistaken for type names starting with T . A denylist prevents hard-casts that produced invalid C. Codegen: Forward declarations for pascal_* helpers in generated C. WriteLn emits correct %s formats for string expressions. main returns 0 like a well-behaved C program. Tests: build_string_conformance_stdout_matches_run_when_toolchain_present runs only when gcc/clang is available — skipping cleanly in CI sandboxes without a compiler, failing loudly when a compiler is present but output diverges. cargo test --test run_build_parity stubs.c: shared runtime surface String functions implemented once in Rust for run mirror into stubs.c for native builds: // conceptual — see repo for full signatures int pascal_Length ( const char * s ); char * pascal_Trim ( const char * s ); Generated Pascal calls route through these instead of ad-hoc inline logic, keeping Sprint 5–8 string semantics intact in binaries. When build-exe is not enough yet Sprint 10 explicitly did not ship full OO, exception, or generics codegen parity — those appear

本文内容来源于互联网,版权归原作者所有
查看原文