hachem.wtf
aboutsummaryrefslogtreecommitdiff

hdass

hachem's dumb assembly super-set, pronounced "hd ass", or "headass" depending on your mood.

the entire point of this project is to provide a middle ground between c and assembly because if we think about why we still write assembly today, it's usually because we need direct control over what the cpu is doing. we want control over the exact instructions being executed, the memory, the stack and everything else that higher level programming languages like c normally abstract away. the thing is, not every program written in assembly actually needs allat. sometimes you want to write something close to the machine without having to manuall deal with every tiny detail yourself. this is where this piece of shit comes in.

it's not quite high level enough to be a c like language, but it's also not low level enough to be as annoying to write as raw assembly. the goal is to sit somewhere in between, keeping the parts of assembly that make it useful while making the parts that don't need to be painful less of unlubricated dildo levels of pain. hdass transpiles into multiple flavours of assembly, currently nasm and fasm (masm is planned unfortunately), rather than directly producing machine code. the idea is to provide a single language for writing low level programs while allowing the backend to translate code into the assembler syntax you want to target, totally not because i didn't want to make an assembler manually. you're still ultimately producing assembly, and you're never particularly far away from the code that gets assembled.

examples

here's a simple "hello, world!" world program written using hdass' syntax:

[entry: main]

const SYS_WRITE = 1
const SYS_EXIT = 60

const STDOUT = 1

data message = "type shi\n"

proc main
{
    rax = SYS_WRITE
    rdi = STDOUT
    rsi = message
    rdx = message.len
    syscall

    rax = SYS_EXIT
    rdi = 0
    syscall
}

more shit can be found in examples/.

docs

some day lmao

building

the build is with by meson:

meson setup build
meson compile -C build

this produces the hdass binary at build/hdass. the default build turns on the address and undefined-behaviour sanitizers, for an optimised build without them, configure a separate directory:

meson setup build-release --buildtype=release -Db_sanitize=none
meson compile -C build-release

hdass emits x86-64 assembly, so to actually assemble and run its output you need an x86-64 linux toolchain. since it's a pain in the ass to actually use, i bundled a docker environment.

start the container (this builds the image the first time):

docker compose up -d --build

open a shell inside it. the repository is bind-mounted at /hdass, so edits on the host are visible immediately:

docker compose exec hdass bash

from inside the container you can build the compiler and take a program all the way to a running executable:

meson setup build-linux && meson compile -C build-linux
./build-linux/hdass examples/hello_world.hdass -o hello.asm
nasm -f elf64 hello.asm -o hello.o
ld -e main hello.o -o hello
./hello

to build, assemble, link and run a single program in the container:

./scripts/run.sh examples/circle.hdass

when you're finished, stop and remove the container:

docker compose down

disclaimer

hdass is extremely experimental. the language, syntax and semantics are still being figured out, so things will probably change, sometimes because there is a better way to do something and sometimes because i decided the old syntax looked stupid.

license

this project is licensed under the mit license. see license for more information.