ternlang-codegen 0.3.2

C transpiler backend for the Ternlang compiler — emits C source from the Ternlang AST for native cross-compilation targets.
Documentation
  • Coverage
  • 50%
    2 out of 4 items documented1 out of 4 items with examples
  • Size
  • Source code size: 26.27 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.65 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 14s Average build duration of successful builds.
  • all releases: 1m 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • eriirfos-eng/ternary-intelligence-stack
    4 2 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • eriirfos-eng

ternlang-codegen — AST → C transpiler backend.

Converts a ternlang Program (produced by ternlang-core::Parser) into a valid, self-contained C source file that can be compiled with any C11 compiler.

Ternary representation

Trits are represented as int8_t with values -1, 0, +1. The generated file includes a small header of inline trit primitives so it has no external dependencies beyond <stdint.h> and <stdio.h>.

Usage

use ternlang_codegen::CTranspiler;
use ternlang_core::{Parser, StdlibLoader};

let src = r#"fn main() -> trit { return consensus(1, -1); }"#;
let mut parser = ternlang_core::Parser::new(src);
let mut prog = parser.parse_program().unwrap();
StdlibLoader::resolve(&mut prog);

let c_src = CTranspiler::new().emit(&prog);
println!("{c_src}");