punch

module
v0.0.0-...-4f2805b Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: MIT

README ΒΆ

PUNCH πŸ₯Š

punch is a hobby programming language.

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

demo playground

I have some aspirations of working on a backend for this. To work out some issues with the AST, I added a js code generation step (to easily produce runnable code). I'm not sure if i'll fully commit to that.

Build

To build you will need golang installed.

To run code locally, you will need node or bun installed in your PATH.

go build ./cmd/punch/

./punch ./examples/simple.pun # output: Hello, World!
Functions
// function declaration
bool is_best(i32 a, i32 b)

// simple function
i8 add(i32 a, i32 b) {
    return a + b
}

// exported function
pub i32 add_two(i32 a, i32 b) {
    return a + b
}

// multiple return types
(i32, bool) add_eq(i32 a, i32 b) {
    return a + b, a == b
}

// no return
fn main() {
    println("hello world")
}
Conditions
if a && b {
    println("abc")
}
Assignment
i32 c    = 42
i64 d    = 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"
)

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

work in progress

Feature ast wasm js
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
punch command
repl command
emitters
js
wat
tools
ast_explorer command
punchgen command

Jump to

Keyboard shortcuts

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