The following is a compiler which translates a subset of the Plait language into OCaml.
Plait is a statically typed language that syntatically resembles Racket, but has a type system similar to ML. For this reason, I decided to implement a compiler which translates between the two languages languages. I mostly just included features of the Plait language that I use. Other features could definitely be added in the future.
The following features of Plait were not included for simplicity reasons, but I hope to include them in the future:
- some definition and lambda forms with explicit type declarations
- Example 1: (define x : Number 10)
- Example 2: (lambda (x) : Number (+ x 10))
- (cond ...), (begin ...), (set! ...), and (try ...)
- (values ...) form
- macros
- modules
- trace function
- ... placeholder, for ex: (if #f ... 'ok)
- vector and box
- quasiquote and unquote
- (#%app ...)
- (case ...), since type-case is much more prevalent in Plait
- (when ...) and (unless ...)
- (local ...)
- (shared ...)
- (parameterize ...)
- (time ...)
- (let/cc ...) and (call/cc ...)
- Many primops are not supported yet, but can be easily implemented.
- tuple arguments (however, curried arguments and function arguments are supported)
- untyped, lazy, and fuel modes
Limits of the nanopass parser resulted in the following forms not being included. I haven't looked into a solution for this yet, but it would be nice to allow for the else keyword in a type-case and conditional branch.
- else case of a type-case
- else case of a cond
- main.rkt
- Entry point to the compiler. Takes in a plait file and compiles it into ML.
- plait.rkt
- Nanopass language definition for Plait.
- simplify.rkt
- Conversion passes that run before codegen. Includes the following:
- Let to λ conversion
- Unroll let* and letrec
- Remove type declarations
- Obey OCaml capitalization and naming conventions
- Compile away plait accessor/predicate functions into ML match expressions.
- Conversion passes that run before codegen. Includes the following:
- codegen.rkt
- Compiles the Plait IR into an ML code string.