{"id":31688536,"url":"https://github.com/tinybiggames/delphic","last_synced_at":"2025-10-08T10:56:53.095Z","repository":{"id":317520950,"uuid":"1065957433","full_name":"tinyBigGAMES/DelphiC","owner":"tinyBigGAMES","description":"Runtime C compilation for Delphi","archived":false,"fork":false,"pushed_at":"2025-10-01T11:19:52.000Z","size":2031,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-01T13:17:32.046Z","etag":null,"topics":["c-backend","c-runtime","c99","delphi","embedded-c","win64","windows-10","windows-11"],"latest_commit_sha":null,"homepage":"","language":"Pascal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinyBigGAMES.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"tinyBigGAMES","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":null,"thanks_dev":null,"custom":null}},"created_at":"2025-09-28T19:13:34.000Z","updated_at":"2025-10-01T11:19:56.000Z","dependencies_parsed_at":"2025-10-01T13:19:07.577Z","dependency_job_id":"f810fd40-6f19-48d5-a2d3-a26e4e49fff1","html_url":"https://github.com/tinyBigGAMES/DelphiC","commit_stats":null,"previous_names":["tinybiggames/delphic"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/tinyBigGAMES/DelphiC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FDelphiC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FDelphiC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FDelphiC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FDelphiC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinyBigGAMES","download_url":"https://codeload.github.com/tinyBigGAMES/DelphiC/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyBigGAMES%2FDelphiC/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278931652,"owners_count":26070789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-backend","c-runtime","c99","delphi","embedded-c","win64","windows-10","windows-11"],"created_at":"2025-10-08T10:56:43.638Z","updated_at":"2025-10-08T10:56:53.089Z","avatar_url":"https://github.com/tinyBigGAMES.png","language":"Pascal","readme":"![DelphiC](media/delphic.png)\n[![Chat on Discord](https://img.shields.io/discord/754884471324672040?style=for-the-badge)](https://discord.gg/tinyBigGAMES) [![Follow on Bluesky](https://img.shields.io/badge/Bluesky-tinyBigGAMES-blue?style=for-the-badge\u0026logo=bluesky)](https://bsky.app/profile/tinybiggames.com)  \n\n## ⚡ Runtime C compilation for Delphi\n\n**DelphiC** is a comprehensive Delphi wrapper for the Tiny C Compiler (TCC), enabling runtime C code compilation, execution, and bidirectional symbol exchange between Delphi and C code. Compile C code to memory, executables, DLLs, or object files directly from your Delphi applications.\n\n[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](#)\n[![Platform](https://img.shields.io/badge/platform-Win64-lightgrey.svg)](#)\n[![Delphi](https://img.shields.io/badge/Delphi-10.4+-red.svg)](#)\n\n## ✨ Features\n\n- 💾 **In-Memory Compilation** - Compile and execute C code at runtime without temporary files\n- 📦 **Multiple Output Types** - Generate EXE, DLL, OBJ files, or preprocess-only mode\n- 🔄 **Bidirectional Symbols** - Call Delphi functions from C and vice versa\n- 🛡️ **Comprehensive Error Handling** - Structured error capture with filename, line numbers, and severity\n- 🔐 **Workflow Enforcement** - State management prevents API misuse and crashes\n- ⚙️ **Full TCC Options** - Direct access to all TCC compiler flags and settings\n- 🔗 **Multi-Unit Support** - Compile and link multiple C source files and object files\n- 🎯 **Zero Dependencies** - Self-contained with embedded TCC, no external tools required\n\n## 💡 Use Cases\n\n- 🎮 JIT compilation for scripting engines\n- 🔌 Dynamic plugin systems with C-based extensions\n- 🏗️ Runtime code generation for DSLs\n- 📚 Embedding C libraries without separate compilation\n- 🎓 Educational tools demonstrating compilation concepts\n- 🔀 Language transpilers targeting C as intermediate representation\n\n## 📋 Requirements\n\n- **OS**: Windows 64-bit\n- **Delphi**: Tested on 12.3\n- **Target**: x86_64 only\n\n## 📥 Installation\n\n### From Source\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/tinyBigGAMES/DelphiC.git\n```\n\n2. Add the `src` folder to your Delphi library path or project search path\n\n3. Add `DelphiC` to your uses clause:\n```delphi\nuses\n  DelphiC;\n```\n\n## 🚀 Quick Start\n\n### 👋 Hello World - Memory Execution\n\n```delphi\nuses\n  DelphiC;  \n\nprocedure HelloWorld;\ntype\n  THelloFunc = function(): Integer; cdecl;\nvar\n  LCompiler: TDelphiC;\n  LHello: THelloFunc;\nbegin\n  LCompiler := TDelphiC.Create();\n  try\n    // Configure for in-memory execution\n    LCompiler.SetOuput(opMemory);\n    \n    // Compile C code\n    LCompiler.CompileString(\n      '#include \u003cstdio.h\u003e' + #10 +\n      'int hello() {' + #10 +\n      '    printf(\"Hello from C!\\n\");' + #10 +\n      '    return 42;' + #10 +\n      '}'\n    );\n    \n    // Relocate and get function pointer\n    if LCompiler.Relocate() then\n    begin\n      LHello := LCompiler.GetSymbol('hello');\n      if Assigned(LHello) then\n        WriteLn('Result: ', LHello());\n    end;\n  finally\n    LCompiler.Free();\n  end;\nend;\n```\n\n### 🔄 Calling Delphi from C\n\n```delphi\n// Delphi callback function\nfunction DelphiAdd(A, B: Integer): Integer; cdecl;\nbegin\n  Result := A + B;\n  WriteLn('Delphi says: ', A, ' + ', B, ' = ', Result);\nend;\n\nprocedure CallbackExample;\ntype\n  TTestFunc = function(): Integer; cdecl;\nconst\n  CCode = \n    'int delphi_add(int a, int b);' + #10 +\n    'int test() {' + #10 +\n    '    return delphi_add(10, 20);' + #10 +\n    '}';\nvar\n  LCompiler: TDelphiC;\n  LTest: TTestFunc;\nbegin\n  LCompiler := TDelphiC.Create();\n  try\n    LCompiler.SetOuput(opMemory);\n    \n    // Inject Delphi function into C\n    LCompiler.AddSymbol('delphi_add', @DelphiAdd);\n    \n    LCompiler.CompileString(CCode);\n    \n    if LCompiler.Relocate() then\n    begin\n      LTest := LCompiler.GetSymbol('test');\n      if Assigned(LTest) then\n        WriteLn('C called Delphi, result: ', LTest());\n    end;\n  finally\n    LCompiler.Free();\n  end;\nend;\n```\n\n### 🎯 Generating Executables\n\n```delphi\nprocedure CreateExecutable;\nvar\n  LCompiler: TDelphiC;\nbegin\n  LCompiler := TDelphiC.Create();\n  try\n    LCompiler.SetOuput(opEXE);\n    LCompiler.SetSubsystem(ssConsole);\n    \n    LCompiler.CompileString(\n      '#include \u003cstdio.h\u003e' + #10 +\n      'int main() {' + #10 +\n      '    printf(\"Standalone executable!\\n\");' + #10 +\n      '    return 0;' + #10 +\n      '}'\n    );\n    \n    LCompiler.OutputFile('myapp.exe');\n    WriteLn('Created myapp.exe');\n  finally\n    LCompiler.Free();\n  end;\nend;\n```\n\n### 📚 Multi-File Compilation\n\n```delphi\nprocedure MultiFileProject;\nvar\n  LCompiler: TDelphiC;\nbegin\n  LCompiler := TDelphiC.Create();\n  try\n    // Compile unit1 to object file\n    LCompiler.SetOuput(opOBJ);\n    LCompiler.CompileString('int add(int a, int b) { return a + b; }');\n    LCompiler.OutputFile('unit1.o');\n    \n    // Reset and link everything\n    LCompiler.Reset();\n    LCompiler.SetOuput(opEXE);\n    LCompiler.AddFile('unit1.o');  // Link compiled object\n    LCompiler.CompileString('int add(int, int); int main() { return add(2, 3); }');\n    LCompiler.OutputFile('program.exe');\n  finally\n    LCompiler.Free();\n  end;\nend;\n```\n\n## 📖 API Overview\n\n### 🔧 Core Methods\n\n| Method | Description |\n|--------|-------------|\n| `Create()` | Initialize TCC compilation context |\n| `Reset()` | Reset compiler for reuse |\n| `SetOuput(TDCOutput)` | Set output type (Memory/EXE/DLL/OBJ/Preprocess) |\n| `CompileString(code, filename)` | Compile C source from string |\n| `AddFile(filename)` | Add C source, object file, or library |\n| `Relocate()` | Prepare for in-memory execution |\n| `GetSymbol(name)` | Retrieve function/variable pointer |\n| `AddSymbol(name, ptr)` | Inject Delphi symbols into C |\n| `OutputFile(filename)` | Generate output file |\n| `Run(argc, argv)` | Execute compiled program |\n\n### ⚙️ Configuration\n\n| Method | Description |\n|--------|-------------|\n| `SetOption(option)` | Set any TCC command-line option |\n| `SetDebugInfo(enabled)` | Enable debug information (-g) |\n| `DisableWarnings()` | Suppress all warnings (-w) |\n| `SetWarningsAsErrors()` | Treat warnings as errors (-Werror) |\n| `SetSubsystem(TDCSubsystem)` | Set Windows subsystem (Console/GUI) |\n| `DefineSymbol(sym, val)` | Define preprocessor symbol |\n| `AddIncludePath(path)` | Add include directory |\n| `AddLibraryPath(path)` | Add library search path |\n| `AddLibrary(name)` | Link against library |\n\n### 🚨 Error Handling\n\n| Method | Description |\n|--------|-------------|\n| `SetPrintCallback(handler)` | Register error/warning callback |\n| `GetErrors()` | Retrieve structured error list |\n| `ClearErrors()` | Clear accumulated errors |\n\n## 🛠️ Compiler Options\n\nDelphiC supports all TCC Win64 options via `SetOption()`:\n\n**📝 Preprocessor**: `-I`, `-D`, `-U`, `-E`  \n**⚡ Compilation**: `-funsigned-char`, `-fsigned-char`, `-fms-extensions`  \n**⚠️ Warnings**: `-w`, `-Wall`, `-Werror`, `-Wimplicit-function-declaration`  \n**🔗 Linking**: `-L`, `-l`, `-Wl,-subsystem=`, `-Wl,-stack=`  \n**🐛 Debug**: `-g` (bounds checking `-b` not supported on Win64)  \n**🎯 Target**: `-mms-bitfields`, `-mno-sse`\n\nSee full documentation in source code XML comments.\n\n## 🔄 Workflows\n\n### 💾 Memory Output (for JIT/Scripting)\n```\nSetOutput(opMemory) → CompileString → [AddSymbol] → Relocate → GetSymbol\n```\n\n### 📦 File Output (EXE/DLL/OBJ)\n```\nSetOutput(opEXE/DLL/OBJ) → CompileString → [AddSymbol] → OutputFile\n```\n\n### ▶️ Direct Execution\n```\nSetOutput(opEXE) → CompileString → Run(argc, argv)\n```\n\n## 🚨 Error Handling\n\n```delphi\nLCompiler.SetPrintCallback(\n  nil,\n  procedure(const AError: string; const AUserData: Pointer)\n  begin\n    WriteLn('[TCC] ', AError);\n  end\n);\n\nif not LCompiler.CompileString(CCode) then\nbegin\n  var LErrors := LCompiler.GetErrors();\n  for var LError in LErrors do\n    WriteLn(LError.Filename, ':', LError.Line, ': ', LError.Message);\nend;\n```\n\n## 📚 Examples\n\nSee the `examples/` directory for:\n- ✅ Basic compilation and execution\n- 🔄 Callback integration\n- 📦 Multi-unit projects\n- 🚨 Error handling patterns\n- 📖 Dynamic library creation\n\n## ⚠️ Limitations\n\n- 🪟 **Win64 only** - No 32-bit or other platform support\n- 🚫 **No bounds checking** - The `-b` flag causes crashes on Win64\n- 🔧 **No optimization flags** - TCC ignores `-O` options (single-pass compiler)\n- 📜 **C99 standard** - Some C11/C23 features may not be supported\n- 🚷 **No C++** - Pure C compilation only\n\n## 🏗️ Architecture\n\nDelphiC uses a state machine to enforce correct TCC API usage:\n\n```\n🆕 New → ⚙️ Configured → ✅ Compiled → 🚀 Relocated/Finalized\n```\n\nInvalid state transitions return `False` and prevent crashes from TCC API misuse.\n\n## 🔨 Building from Source\n\n1. Open `DelphiC - Runtime C compilation for Delphi.groupproj` in `src` folder\n2. in `UTestbed.pas`, set `LNum` to test number to run\n3. Build an run\n\nNo external dependencies required - TCC is embedded as a compiled object.\n\n## 🤝 Contributing\n\nContributions are welcome! Please:\n\n1. 🍴 Fork the repository\n2. 🌿 Create a feature branch\n3. 📝 Follow existing code style\n4. ✅ Add tests for new features\n5. 💾 Commit changes\n6. 📤 Push to branch\n7. 🔀 Open a Pull Request\n\n## 📄 License\n\nDelphiC is released under the **BSD 3-Clause License**.\n\nCopyright © 2025-present tinyBigGAMES™ LLC. All Rights Reserved.\n\nSee [LICENSE](https://github.com/tinyBigGAMES/DelphiC#BSD-3-Clause-1-ov-file) for full license text.\n\n### 📦 Third-Party Components\n\nThis library uses:\n- **TCC (Tiny C Compiler)** - https://github.com/TinyCC/tinycc\n\n## 💬 Support\n\n- 🐛 **Issues**: [GitHub Issues](https://github.com/tinyBigGAMES/DelphiC/issues)\n- 💭 **Discussions**: [GitHub Discussions](https://github.com/tinyBigGAMES/DelphiC/discussions)\n\n\n## 🙏 Acknowledgments\n\n- **Fabrice Bellard** - Original TCC author\n- **TCC Contributors** - Ongoing TCC development\n- **Delphi Community** - Testing and feedback\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\n**Made with ❤️ by tinyBigGAMES™**\n\n*\"Bridging Delphi and C at runtime\"*\n\n\u003c/div\u003e","funding_links":["https://github.com/sponsors/tinyBigGAMES"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinybiggames%2Fdelphic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinybiggames%2Fdelphic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinybiggames%2Fdelphic/lists"}