punch

module
v0.0.0-...-cad9b24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2024 License: MIT

README ΒΆ

PUNCH πŸ₯Š

punch is a hobby programming language. At the moment, punch targets wasm.

I'm mainly working on this as a learning experience.

Build

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

Functions
// 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")
}
Conditions
if a && b {
    println("abc")
}
Assignment
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"
Structs
struct message {
    i8  sender
    i8 	recipient
    str body
}
message msg = {
    sender: 5,
    recipient: 10,
    body: "hello"
}

println(msg.sender, msg.recipient, msg.body)
Loops
// traditional for loop
for i := 0; i < 10 ; i = i + 1 {

}

// loop while true
for true {

}

// loop forever
for {

}
Simple Program
pkg main

import (
    "fmt"
)

main() {
    fmt.Println("hello, world!")
}
Status

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 ❌ ❌

Reference

Directories ΒΆ

Path Synopsis
cmd
internal
ast

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL