-
Notifications
You must be signed in to change notification settings - Fork 0
📥 A FORTH compiler to x86 assembly
License
lowczarc/back
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
Repository files navigation
=============================================================================== BACK - A Forth compiler =============================================================================== ------------------------------------------------------------------------------- I don't know why but I'm writing a Forth compiler now. It's not efficient, the created assembly code is very bad and un-optimized, I'm directly returning x86 assembly instead of LLVM IR (bc I'm too lazy to learn) but I'm having fun ok ? Of course, don't use it in production (or anywhere really). ------------------------------------------------------------------------------- What is forth ? ------------------------------------------------------------------------------- Forth is a stack-based language from the 1970s where everything is written in reverse-polish notation. For example, if you want to print the sum of 39 and 3 you would write 39 3 + . (The dot is the word for printing the top of the stack) It's a very simple language to parse and compile. In theory you don't need an AST since every word can be directly translated to assembly (check the commit 655bd4b for an example). I want to try making some optimizations so I've made an AST anyway. But even with its simplicity the language is still very powerful and allows to abstract and is way easier to write than assembly. ABI Definition ------------------------------------------------------------------------------- | rax | working register | | rbx | working register | | rcx | Unused for now | | rdx | working register | | rsi | Unused for now | | rdi | Unused for now | | rbp | call stack | | rsp | call stack | | r8 | working stack top | | r9 | do loop i | | r10 | do loop max | | r11 | Unused for now | | r12 | heap top | | r13 | Unused for now | | r14 | Unused for now | | r15 | Unused for now |
About
📥 A FORTH compiler to x86 assembly