⚠️ VIBE CODED This entire project — compiler, VM, library API, game demo, docs — was generated through an AI-assisted vibe coding session. No careful design documents, no formal spec, no test-driven development. Just vibes, iteration, and a lot of "do that". Expect rough edges. Treat it as a working prototype and proof of concept, not production-grade software.
A high-performance, embeddable JIT compiler for a subset of the HolyC programming language, designed for seamless integration into Odin-based game projects.
OdinC is a statically-typed compiler/interpreter hybrid that:
- Compiles HolyC source code to bytecode
- Executes via a lightweight VM with JIT capability
- Provides a stable Odin library API for embedding
- Supports real-time scripting in game engines
# Check syntax
odin check OdinC.odin -file
# Run tests
./run_tests.sh
# Build to bytecode
odin run OdinC.odin -file -- build demo/src/main.hc -o demo/build/main.ocbc
# Run bytecode
odin run OdinC.odin -file -- run demo/build/main.ocbcpackage main
import "core:fmt"
import "odinc:odinc"
main :: proc() {
// Compile HolyC source
pkg, ok := odinc.Compile("scripts/game_logic.hc")
if !ok do return
// Create and run VM
vm := odinc.New_VM(&pkg)
result, ok_run := odinc.Run_VM(&vm)
if !ok_run do return
// Extract result
if exit_code, ok_int := odinc.To_I64(result); ok_int {
fmt.printf("Script exit code: %d\n", exit_code)
}
}OdinC implements a subset of HolyC with:
i64- 64-bit signed integer (default numeric type)i32,u64,u32,f64,bool- recognized but mostly treated as i64- Pointers:
i64*, arrays:i64[10] - String literals (read-only)
if/else- standard conditionalfor- C-style loops:for (init; cond; post)while- standard while loopsswitch/case/default- with fallthrough supportbreak/continue- loop controlreturn- function returns with optional value
- User-defined and built-in (
printf) - Recursion supported
- Local variables with type declarations
- Arithmetic:
+,-,*,/, unary- - Comparison:
==,!=,<,<=,>,>= - Logical:
&&,||,! - Pointers:
&(address),*(dereference) - Arrays:
[](indexing) - Assignment:
=
- Stack-allocated locals and arrays
- Pointer arithmetic with bounds checking
- Type-safe pointer operations (compile-time checked)
OdinC/
├── OdinC.odin # CLI compiler/VM (main entry point)
├── odinc/
│ ├── odinc.odin # Implementation (package odinc)
│ └── odinc_lib.odin # Stable facade for embedders
├── demo/
│ ├── src/ # Example HolyC programs
│ ├── tests/ # Regression tests
│ ├── build_demo.sh # Build and run demo
│ └── README.md # Demo guide
├── library_demo/
│ ├── main.odin # Example of library usage
│ └── run_library_demo.sh # Run library demo
├── tests/
│ ├── *.hc # Test programs
│ └── manifest.txt # Test manifest
└── run_tests.sh # Test runner
The odinc:odinc package exposes a stable API:
// Type aliases
Package :: BC_Package
Virtual_Machine :: VM
Runtime_Value :: Value
// Compilation
Compile(path: string) -> (Package, bool)
Save(path: string, pkg: Package) -> bool
Load(path: string) -> (Package, bool)
// VM execution
New_VM(pkg: ^Package) -> Virtual_Machine
Run_VM(vm: ^Virtual_Machine) -> (Runtime_Value, bool)
Run_File(path: string) -> (Runtime_Value, bool)
Run_Bytecode(path: string) -> (Runtime_Value, bool)
// Result inspection
To_I64(v: Runtime_Value) -> (i64, bool)
Kind_Name(v: Runtime_Value) -> string
// CLI
CLI() # Entry point for command-line interfaceSee GAME_INTEGRATION.md for detailed patterns and examples on using OdinC in game projects.
Real-time scripting: Load and execute HolyC scripts without game restart Configuration: Define game logic in HolyC instead of C/C++ Modding: Let players write mods in HolyC Prototyping: Rapidly test gameplay mechanics
# Run source code directly
odin run OdinC.odin -file -- run script.hc
# Compile to bytecode package
odin run OdinC.odin -file -- build script.hc -o output.ocbc
# Run bytecode package
odin run OdinC.odin -file -- run output.ocbc
# Run test manifest
odin run OdinC.odin -file -- test tests/manifest.txtManifest files (manifest.txt) specify tests as:
# path|expected_outcome
tests/demo.hc|39
tests/error.hc|ERR
tests/compile_fail.hc|COMPILE_ERR
|0..255- Expected exit code|ERR- Expect runtime error|COMPILE_ERR- Expect compile error
- Bytecode-based execution is inherently slower than native code
- No optimization passes yet (planned for future versions)
- Memory bounds are checked at runtime
- Suitable for non-performance-critical game code (UI, logic, AI)
- Object-oriented features (structs, methods)
- More built-in functions (math, strings, etc.)
- Optimization passes
- Debugger support
- Module system / imports
- Async/coroutine support
- FFI for calling Odin code from HolyC
See repository LICENSE file.
This is an educational/research project. Contributions, bug reports, and discussion welcome.