Skip to content

iwao0/ilang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

238 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ ilang

English | ๆ—ฅๆœฌ่ชž

๐Ÿฆ€ ARC memory safety ยท โšก Cranelift JIT ยท ๐Ÿ”— C FFI ยท ๐ŸŽฎ ships with an SDL2 game demo

A compiler/runtime for ilang, a young programming language under active design. Tree-walking interpreter for fast feedback, Cranelift JIT for performance, and a Rust-flavoured surface syntax that talks to C libraries when you need to.

fn fib(n: i64): i64 {
    if n < 2 { n } else { fib(n - 1) + fib(n - 2) }
}
console.log(fib(20))    // โ†’ 6765

โœจ Vision

  • ๐Ÿ›ก๏ธ Capability-based security โ€” libraries and classes carry permissions like net, file; the host grants them at use sites to reduce supply-chain blast radius. (annotations parse today; enforcement is the next big milestone)
  • ๐Ÿฆ€ ARC for memory safety โ€” no ownership / mut / borrow checker.
  • ๐Ÿฆ€ Rust-flavoured declarations and type names.
  • ๐ŸŒ C / JavaScript arithmetic semantics (operator precedence, integer-promotion behaviour).

๐Ÿ“š Syntax cheatsheet

The implemented syntax / types / built-ins are catalogued in docs/syntax.md.

โœ… Status

Category Status
Numeric types (i8โ€“i64 / u8โ€“u64 / f32 / f64) + as casts โœ…
bool / comparison / short-circuit logic โœ…
let / assignment / compound assignment (+= and friends) โœ…
Control flow (if / else / while / loop / break / continue / early return) โœ…
Strings / arrays (dynamic & fixed-length) โœ…
class / new / init / this / deinit (JS-style) โœ…
Inheritance (extends / super) + virtual dispatch โœ…
console.log โœ…
Optional (T? / some / none / if let) โœ…
Weak references (T.weak / .get()) โœ…
enum + match (with built-in Result<T, E>) โœ…
Map<K, V> / Tuple โœ…
Closures (with capture) โœ…
Generics (functions / classes / enums) โœ…
Function overloading โœ…
ARC-based memory management โœ…
Type checking โœ…
Cranelift JIT (ilang run --jit) โœ…
FFI (@extern(C) {} blocks calling C libraries) โœ…
Capability annotations ๐Ÿšง parse-only

No ownership / mut / borrow checker โ€” every variable is reassignable. Errors are emitted in the uniform filename [row:col]: message format.

๐Ÿ”ง Setup

ilang is implemented in Rust, so you'll need a Rust toolchain (rustup / cargo). If it isn't installed, grab it from https://rustup.rs:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Clone the repo:

git clone https://github.com/iwao0/ilang
cd ilang
cargo build           # first run resolves deps + compiles (~1 minute)

๐Ÿš€ Usage

# ๐Ÿ’ฌ REPL โ€” let / fn persist across lines, interpreter mode
cargo run -p ilang-cli

# ๐Ÿ“„ Run a file (`;` is optional, newlines act as statement separators
#    JS-ASI style)
cargo run -p ilang-cli -- run path/to/script.il

# โšก Run via the JIT (Cranelift native code โ€” tens to hundreds of times
#    faster than the interpreter)
cargo run -p ilang-cli -- run --jit path/to/script.il

Code that calls into a C library through @extern(C) {} (the SDL2 sample below, for example) is JIT-only. Symbols are resolved through dlsym at JIT-build time, so the interpreter has no path to those functions.

๐Ÿงฎ Sample: count multiples of 3 or 5 from 1 to 100

cat > sample.il <<'EOF'
fn count_div(n: i64): i64 {
    let i = 1
    let count = 0
    while i <= n {
        if i % 3 == 0 || i % 5 == 0 {
            count = count + 1
        }
        i = i + 1
    }
    count
}
count_div(100)
EOF
cargo run -p ilang-cli -- run sample.il   # => 47

๐Ÿงฑ Classes

JS-flavoured objects with class / new / init (constructor) / this. Inside method bodies you can omit this. for fields and methods (a local or parameter of the same name still wins).

cat > counter.il <<'EOF'
class Counter {
    count: i64
    init(start: i64) { this.count = start }
    bump(): i64 {
        count += 1     // same as `this.count += 1`
        count
    }
}

let c = new Counter(10)
let i = 0
loop {
    if i >= 5 { break }
    c.bump()
    i += 1
}
c.bump()
EOF
cargo run -p ilang-cli -- run counter.il   # => 16

๐ŸŽฎ Sample: an SDL2 game window

examples/sdl_breakout/ contains an SDL2 demo: a neon-style breakout game with paddle, bricks, particles, and gamepad support. Arrow keys / A D (or D-pad / left stick) move the paddle, Space launches the ball, F toggles fullscreen, R restarts after game over, ESC quits.

Install SDL2 first:

# ๐ŸŽ macOS (Homebrew)
brew install sdl2

# ๐Ÿง Debian/Ubuntu
sudo apt install libsdl2-dev libsdl2-2.0-0

Run:

cargo run -p ilang-cli -- run --jit examples/sdl_breakout/main.il

The sample pulls in the SDL2 bindings under bindings/sdl2/ via a plain use sdl. The mechanism (an ilang.toml with a [deps] table) is documented in bindings/sdl2/README.md.

To use the SDL2 bindings from your own project, drop an ilang.toml next to (or above) your entry file:

[package]
name = "my_game"

[deps]
sdl2 = "/path/to/ilang/bindings/sdl2"

The CLI walks upward from the entry file looking for ilang.toml at startup; each [deps] value becomes an additional search directory for use module resolution.

๐Ÿงฉ VSCode

vscode-extension/ ships syntax highlighting plus a language server (ilang-lsp) for diagnostics, hover, and go-to-definition. Local install:

# 1. Build the language server
cargo build -p ilang-lsp

# 2. Build the extension client
cd vscode-extension
npm install
npm run compile

# 3. Symlink into VSCode's extensions directory
ln -s "$(pwd)" ~/.vscode/extensions/ilang

Restart VSCode. See vscode-extension/README.md for configuration (ilang.serverPath) and current limitations.

๐Ÿ› ๏ธ Development

Run the whole test suite โ€” Rust unit tests across every crate plus the language-level fixtures under crates/ilang-cli/tests/programs/ (each .il fixture is executed in both the interpreter and the JIT, with expect: / expect-error: magic comments asserting the outcome):

cargo test --workspace

๐Ÿ“„ License

MIT OR Apache-2.0

About

๐Ÿšง Work-in-progress ๐Ÿš€ A new programming language ๐Ÿฆ€ ARC (no ownership/mut) โšก Cranelift JIT ๐Ÿ”— C FFI ๐ŸŽฎ ships with an SDL2 game demo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors