make./cmp file.cmp # compiles to ./a
./cmp file.cmp -o out # compiles to ./out
./cmp file.cmp -v # verbose, shows what's going on
./cmp file.cmp --debug # keeps the .asm and .o files around
./aprint("Hello, world!\n")
print(x)
int x = 10
int y = x + 5
int z = x - 3
int w = x * 2
int d = x / 2
| Type | Size | What it is |
|---|---|---|
int |
32-bit | your everyday integer |
long |
64-bit | big number, won't overflow fast |
bool |
8-bit | 0 or 1, that's it |
char |
— | string variable |
int x = 10
long big = 1000000
bool flag = 1
char msg = "hello\n"
print(msg)
Works with ==, !=, <, >. That's all you get for now.
if x == 10 {
print("yep\n")
} else {
print("nope\n")
}
int i = 0
while i < 10 {
print(i)
i = i + 1
}
Pretty much C-style. Step is + or - only.
for (i = 0; i < 10; i = i + 1) {
print("hey\n")
}
Heads up - declare i as int before the loop if you need it outside.
Up to 6 args. Don't try recursion, it'll blow up (because all var are global).
fn add(a, b) {
int result = a + b
print(result)
}
fn main() {
add(10, 20)
}
Simple return. Just:
fn add(a, b) {
int result = a + b
return result
}
fn main() {
int x = add(3, 4)
print(x)
}
int x = 42
ptr* p = &x
print(x) // 42
*p = 99
print(x) // 99
Call C func from libc
extern malloc
extern free
fn main() {
ptr* p = malloc(64)
free(p)
}
To compile with another library, pass -l while compilling
./cmp file.cmp -l m
./cmp file.cmp -l pthread
// PANTERA DOMINATION
| Flag | What it does |
|---|---|
-o <file> |
name the output binary (default: a) |
-v |
print each step as it happens |
--debug |
don't clean up .asm and .o |
-l <lib> |
link an external library (e.g. -l m for libm) |