Skip to content

ShoryaRawal/emberc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

emberc

emberc is a tiny C-to-WebAssembly (WAT) compiler written in Rust.

Supported Subset

  • Types: int, unsigned int
  • Variables: block-scoped local declarations with optional initialization
  • Expressions:
    • arithmetic: + - * / %
    • bitwise: & | ^ ~
    • logical: && || !
    • comparisons: < <= > >= == !=
    • assignment: =
  • Statements:
    • blocks
    • expression statements
    • if / else
    • while
    • for
    • break
    • continue
    • return
  • Functions:
    • function definitions and calls
    • integer return types
    • main entry required

Builtin Runtime Functions

  • printf(int) is available as a builtin import.
  • Current implementation is intentionally minimal: it prints one integer per call.
  • Full libc printf formatting is not implemented in this tiny subset.

Out of Scope

  • pointers
  • arrays
  • structs
  • floating-point types
  • preprocessor/macros
  • full libc integration

Build

cargo build

Build WebAssembly For Browser Use

wasm-pack build --target web --out-dir web-next/public/wasm --out-name emberc_wasm

This exports a browser-loadable module with compileToWat.

Run

cargo run -- examples/add.c -o examples/add.wat

If -o is omitted, emberc writes output next to input with a .wat extension.

Test

cargo test

Next.js Demo

A small editor + compile UI is provided in web-next/README.md.

Quick start:

wasm-pack build --target web --out-dir web-next/public/wasm --out-name emberc_wasm
cd web-next
npm install
npm run dev

About

emberc is a tiny C-to-WebAssembly (WAT) compiler written in Rust.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors