o

OdinC

v44dfef4library

Vibe coded port of holy c to odin

0 stars0 forksUnknownupdated 5 hours ago
Open repo

OdinC - HolyC JIT Compiler for Game Integration

⚠️ 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.

Overview

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

Quick Start

Building

# 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.ocbc

Using OdinC in Your Odin Game Project

package 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)
	}
}

Language Features

OdinC implements a subset of HolyC with:

Types

  • 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)

Control Flow

  • if/else - standard conditional
  • for - C-style loops: for (init; cond; post)
  • while - standard while loops
  • switch/case/default - with fallthrough support
  • break/continue - loop control
  • return - function returns with optional value

Functions

  • User-defined and built-in (printf)
  • Recursion supported
  • Local variables with type declarations

Operators

  • Arithmetic: +, -, *, /, unary -
  • Comparison: ==, !=, <, <=, >, >=
  • Logical: &&, ||, !
  • Pointers: & (address), * (dereference)
  • Arrays: [] (indexing)
  • Assignment: =

Memory

  • Stack-allocated locals and arrays
  • Pointer arithmetic with bounds checking
  • Type-safe pointer operations (compile-time checked)

Project Structure

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

Library API (Facade)

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 interface

Game Integration Guide

See GAME_INTEGRATION.md for detailed patterns and examples on using OdinC in game projects.

Common Use Cases

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

Command-Line Interface

# 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.txt

Test Format

Manifest 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

Performance Notes

  • 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)

Future Enhancements

  • 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

License

See repository LICENSE file.

Contributing

This is an educational/research project. Contributions, bug reports, and discussion welcome.

Package Info
Version
v44dfef4
License
Unknown
Author
@MyStupidVibeCodingProjects
Type
library
Forks
0
Created
5 hours ago
Updated
5 hours ago
Health
maintained
has releases
has readme
has license
Activity
last 56 weeks