A very simple purely functional language for the JVM platform with the compiler written in Scala. This project was part of my bachelor's degree final thesis and even the written thesis itself can be found in this repo (it is in Polish though and of no great value anyways).
The language is a subset of Scheme enriched with a JVM directive which implements Java interoperability - user can use functions from Java standard library. There are plenty of syntactic constructs that are handled only partially, but, e.g. following programs compile correctly:
(define fib (lambda (n) (if (<= n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))))
(write (fib 6))
(write (JVM.String.length "Answer to the Ultimate Question of Life, the Universe, and Everything"))
(define nwd (lambda (a b) (if (= b 0) a (nwd b (% a b) ) ) ))
(write (nwd 133 32))
(write (nwd 42 56))
(write (nwd 100 100))
You can find more examples in the examples directory.
scala 2.13
java 11
sbt
- Inside
singularitydirectory runsbt assembly. Fat jar will be built intargetdirectory. - To compile the code, run
scala FAT_JAR FILE_WITH_CODEwhereFILE_WITH_CODEcontains valid code written in the language. - After executing the previous step directory named
WYNIK_KOMPILACJIwill be created. The directory name can be changed by altering the configuration parameters. cdinto newly created directory and issuejava Maincommand to run the program.
- Lexer & parser
- Basic data types (int, str, float, char, bool)
- read and write instructions
- function invokation syntax
- if else then
- let exprs
- pattern matching
- ast traversal & bytecode gen
- main class with main method
- read and write bytecode gen
- function invokation
- if else then
- optimization & utility
- import native java classes
- recursion tco