hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 1f7d16140e6d89ad7bd7aac1cdf0f12ce103697b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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:
```hdass
[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/](examples/).

## docs
> some day lmao

## building
the build is with by meson:
```bash
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:
```bash
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):
```bash
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:
```bash
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:
```bash
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:
```bash
./scripts/run.sh examples/circle.hdass
```

when you're finished, stop and remove the container:
```bash
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](LICENSE) for more information.