Custom language compiler to X86_64 nasm assembly, written in Scala
Table of Contents
A testing ground for my knowledge of unix, make, scala, compilers and assembly. I called it Po# cause my friend suggested something like P#, but that is already a language, so i chose Po# as it reminds me of potatoes :). I will also base the language on C# in some ways.
I did a compiler course in university, but we actually wrote a interpreter there. The language was quite functional and of limited syntax. I tried to extend it to a different syntax and add more useful syntactic sugar (it didn't even have loops). However, it was hard to work with at the end. Therefore, I decided to make a new base, this time also making a compiler.
The intention is to make this language a combination of features i really like from many languages, like scala, java, c# and python. The main focus currently will be c++ like, as i find that easiest to translate to assembly.
- Ubuntu 18.04 and/or WSL
- JDK 13+
- Scala 2.13
- SBT 1.6.1
- NASM
- GCC
Currently, I run the scala compiler through IntelliJ. The conversion from assembly to binary is handled by a makefile, that i run in WSL with ubuntu 18;
There is also an option to compile with a single command using sbt. Just run make full
in the main directory
For now the code that is interpreted can be typed in the Main object. The assembly file
will be generated in compiled/hello.asm
(do not ask why I named it that).
With IntelliJ
- Run
Main.scala
- In root directory call
make
With sbt
- In root directory call
make full
//recursive fibonacci implementation
def main(): int {
val a = 9;
print(fib(a));
return 0;
}
def fib(n: int): int {
if(n <= 1) {return n;};
return (fib((n-1)) + fib((n-2)));
}
- Integer arithmetic (with forced parenthesis for subexpressions)
- variable definition and assignment
- print function
- if/else (&&, ||, ==, >, <, !, !=, >=, <=), forced parenthesis
- While, for loops
- Arrays(default values, size access)
- Types
- Functions
- Float support
- Strings
- Enums
- Objects
- Generics
- runtime exceptions
- Object inheritance
- lambda functions
- library functions
- typeof
- Garbage collector
- multiple files
- packages
- File i/o
- Optimisation
- Structs
- ref/out
- Type alias
- Interface union
- String manipulation
- user input
- online demo for posharp
- Input filename (perhaps make compiled version for release)