Skip to content

Purely functional language for JVM platform with compiler written in Scala

License

Notifications You must be signed in to change notification settings

JacekDuszenko/singularity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

singularity

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.

Dependencies

scala 2.13 java 11 sbt

How to run

  1. Inside singularity directory run sbt assembly. Fat jar will be built in target directory.
  2. To compile the code, run scala FAT_JAR FILE_WITH_CODE where FILE_WITH_CODE contains valid code written in the language.
  3. After executing the previous step directory named WYNIK_KOMPILACJI will be created. The directory name can be changed by altering the configuration parameters.
  4. cd into newly created directory and issue java Main command to run the program.

Development plan

  1. Lexer & parser
  • Basic data types (int, str, float, char, bool)
  • read and write instructions
  • function invokation syntax
  • if else then
  • let exprs
  • pattern matching
  1. ast traversal & bytecode gen
  • main class with main method
  • read and write bytecode gen
  • function invokation
  • if else then
  1. optimization & utility
  • import native java classes
  • recursion tco

About

Purely functional language for JVM platform with compiler written in Scala

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages