Ocar is a low-level Assembly transpiler (not a compiler!). With its C-inspired syntax, it aims to provide a more visually appealing way of writing raw assembly.
A previous commit added a VSCode syntax highlighter. To use, run:
code --install-extension ocarlang-0.0.4.vsixThen press Ctrl+Shift+P and type Developer: Reload Window and press enter. Then, after creating a .ocar file, you should be able to see it syntax highlighted!
Technically, it is indeed a compiler. However, because it doesn't provide many features compilers are known to provide (mainly register allocation and recursive expressions), I choose to call it a transpiler because the information for every instruction is pretty much self-contained.
#stdlib entry
#stdlib exit
rtn _start() noret {
rbx myVar1 = 3;
rcx myVar2 = 5;
myVar1 += myVar2;
@push rax
@pop rax
delete myVar1;
delete myVar2;
exit();
}
#stdlib entryincludesentry.ocarfrom the standard library, which defines_start()as the entry point.#stdlib exitincludesexit.ocarfrom the standard library, which allowsexit()to exit the program with exit code 0.rtnmeans routine. It is the language's version of a function.rtn _start()defines a routine called_start().noretmakes it that the transpiler doesn't add aretat the end of the function, which is not needed for the entry point.rbx myVar1 = 3;andrcx myVar2 = 5;define two variables that take up the registersrbxandrcxrespectively. Note that the user manually declares which registers they should take. If any other variable tries to claim those registers without the registers being freed first, the compiler will throw.@push raxand@pop raxare prefixed with@to signal direct assembly conversion; everything after@is emitted to assembly directly without any checks.delete myVar1;anddelete myVar2;end the lifetime ofmyVar1andmyVar2, freeing the registersrbxandrcxfor possible future use.exit()cals the standard function imported earlier to exit the program.
- Add register freeing (e.g.
free rax,free rdi) - Add multiline comments
- Add
syscalloperation - Raw register access (e.g.
raw rax = 5) - Variable support for assignment (allow
rax a = b;) - Four operations
- Implemented three operations; addition, subtraction, and multiplication. Division requires hardcoded registers which doesn't currently work.
- If statements
- Comparisons
- Else statements
- Goto and labels
- While loops
- For loops
- Add linking. Probably C-style, because it's easier.
- Make a standard library
-
#noheaderoption that removes the autogeneration header - Stack memory acces (e.g.
stk[bytecount] varname = 0;,stk[8] myint = 17;) - Function parameters/arguments
- Maybe give an optional
autopushkeyword that finds free spots in the stack and pushes the registers used by parameters into them, then loads them on exit, so users don't have to worry about register data disappearing.
- Maybe give an optional
-
autokeyword to automatically choose an unused register
Ocar's name is a recursive acronym stnding for OCAR Can't Allocate Registers.