punch
is a hobby programming language. At the moment, punch
targets wasm.
I'm mainly working on this as a learning experience.
Compile a punch program to wasm:
# build the wasm file
punch -o ./examples/adder/adder ./examples/adder/adder.p
# execute the wasm file
cd ./examples/adder
node adder.js
a
.wat
file and.ast
file will also be output for debug purposes
// function declaration
bool is_best(i8 a, i8 b)
// simple function
i8 add(i8 a, i8 b) {
return a + b
}
// exported function
pub i8 add_two(i8 a, i8 b) {
return a + b
}
// multiple return types
(i8, bool) add_eq(i8 a, i8 b) {
return a + b, a == b
}
// no return
main() {
println("hello world")
}
if a && b {
println("abc")
}
i8 a = 42
i16 b = 42
i32 c = 42
i64 d = 42
u8 e = 42
u16 f = 42
u32 g = 42
u64 h = 42
f32 k = 42.0
f64 l = 42.0
bool m = true
str n = "hello"
struct message {
i8 sender
i8 recipient
str body
}
message msg = {
sender: 5,
recipient: 10,
body: "hello"
}
println(msg.sender, msg.recipient, msg.body)
// traditional for loop
for i := 0; i < 10 ; i = i + 1 {
}
// loop while true
for true {
}
// loop forever
for {
}
pkg main
import (
"fmt"
)
main() {
fmt.Println("hello, world!")
}
work in progress
Feature | ast | wasm |
---|---|---|
function declaration | ✅ | ✅ |
function calls | ✅ | ✅ |
function multiple returns | ✅ | ❌ |
if/else | ✅ | ✅ |
strings | ✅ | ✅ |
integers | ✅ | ✅ |
floats | ✅ | ✅ |
structs | ✅ | ✅ |
struct access | ❌ | ❌ |
loops | ❌ | ❌ |
lists | ❌ | ❌ |
maps | ❌ | ❌ |
pointers | ❌ | ❌ |
enums | ❌ | ❌ |
modules | ❌ | ❌ |
type inference | ✅ | ✅ |
interfaces | ❌ | ❌ |