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

标签:#delphi

找到 3 篇相关文章

AI 资讯

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

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

2026-06-04 原文 →
AI 资讯

Building REST APIs in Pascal with Horse | APIs REST em Pascal com Horse

Bilingual post · Post bilíngue Jump to: English · Português English {#english} Building REST APIs in Pascal with Horse Pascal is not stuck in desktop forms. With Horse — a lightweight HTTP framework popular in the Delphi ecosystem — CrabPascal v2.22.0 runs real REST servers from .dpr files. No IIS, no Apache: just crab-pascal run and curl. Why Horse in CrabPascal? Horse provides routing, JSON bodies, and middleware-style handlers. CrabPascal ships RTL shims and a runtime HTTP stack so examples work out of the box: Example Port Endpoints examples/crud/ 9000 Full product CRUD examples/time-server/ 9001 Time/date ping examples/agenda/ 9000 Contact registry All runnable with the internal runtime — no gcc required. Minimal API program SimpleAPI ; uses Horse , System . JSON ; begin THorse . Get ( '/ping' , procedure ( Req : THorseRequest ; Res : THorseResponse ; Next : TNextProc ) var J : TJSONObject ; begin J := TJSONObject . Create ; J . AddPair ( 'message' , 'pong' ); Res . Send ( J . ToJSON ); end ); THorse . Listen ( 9000 ); end . Run and test: crab-pascal run SimpleAPI.dpr curl http://localhost:9000/ping Expected response: {"message":"pong"} . CRUD example from the repo The examples/crud/crud.dpr project demonstrates production-style routes: THorse . Get ( '/produtos' , procedure ( Req , Res , Next ) begin Res . Send < TJSONObject >( TProdutoService . ListarProdutos ); end ); THorse . Post ( '/produtos' , procedure ( Req , Res , Next ) var json : TJSONObject ; begin json := Req . Body < TJSONObject >; Res . Send ( TProdutoService . CriarProduto ( json . GetValue ( 'nome' ). Value , json . GetValue ( 'categoria' ). Value , StrToFloatDef ( json . GetValue ( 'preco' ). Value , 0 ), StrToIntDef ( json . GetValue ( 'estoque' ). Value , 0 ) )); end ); Start the server: cd examples/crud crab-pascal run crud.dpr Testing with curl List products: curl http://localhost:9000/produtos Create a product: curl -X POST http://localhost:9000/produtos \ -H "Content-Type: application/j

2026-06-04 原文 →
开源项目

Configuring CrabPascal with crabpascal.toml | Configurando com crabpascal.toml

Bilingual post · Post bilíngue Jump to: English · Português English {#english} Configuring CrabPascal with crabpascal.toml Every serious compiler needs project-level configuration. CrabPascal v2.22.0 reads crabpascal.toml from your project root — search paths, preprocessor symbols, Delphi vs FPC mode, output format, and runtime defaults. Where the file lives The compiler searches in order: crabpascal.toml (project root) .crabpascal.toml (hidden) config/crabpascal.toml If none exist, sensible defaults apply. Add the file when your project grows beyond a single .dpr . Starter configuration [compiler] version = "2.22.0" search_paths = [ "rtl/" , "lib/" , "examples/" ] defines = [ "CRABPASCAL" , "RELEASE" , "MSWINDOWS" ] mode = "DELPHI" # or "OBJFPC" strict = false warnings = true [preprocessor] enabled = true process_includes = true symbols = [] [output] error_format = "vscode" # or "gcc", "delphi" colors = true [runtime] default_http_port = 9000 [paths] rtl_path = "rtl/" output_path = "output/" Place this beside your .dpr file. All CLI commands ( check , run , build-exe ) pick it up automatically. Common use cases Delphi vs Free Pascal mode [compiler] mode = "DELPHI" defines = [ "CRABPASCAL" , "MSWINDOWS" ] Switch to FPC compatibility: [compiler] mode = "OBJFPC" defines = [ "FPC" , "UNIX" ] Mode affects parsing rules and RTL resolution under rtl/ . Custom unit search paths Large projects split units across folders: [compiler] search_paths = [ "rtl/" , "src/units/" , "src/services/" , "third_party/" ] This replaces hardcoded -U flags in scripts. Preprocessor symbols Match Delphi conditional compilation: [preprocessor] enabled = true symbols = [ "DEBUG" , "TESTING" ] Your Pascal code can use: {$IFDEF DEBUG} WriteLn ( 'Debug build' ); {$ENDIF} Run crab-pascal preproc MyApp.dpr to inspect expanded source. CI-friendly error output [output] error_format = "gcc" colors = false show_stacktrace = false GitHub Actions parsers often prefer gcc-style lines. Local development can

2026-06-04 原文 →