First, ensure you have ocaml
, opam
, and ocamlbuild
installed.
Then:
cd {project_dir}
make
Run:
./main.native {file_name}
Run unit tests:
make test
Run example tests:
make ex
Basicslet-in
expressions- Int operators:
+
,-
,*
,/
,%
- Reads numbers from stdin:
read
- Prints values of any type:
print
- Prints programs' result to stdout
- Generates x86 and compiles with
GCC
Register Allocation- Uncovers live variables
- Builds an interference graph
- Allocates registers
- Move Biasing
Control Flow- Boolean support:
#t
and#f
- Relational operators:
eq?
,<
,<=
,>
,>=
,pos?
,zero?
, andneg?
- Logical operators:
and
,or
, andnot
if-else
,when
,unless
, andbegin
expressionswhile
loops
- Boolean support:
Tuples & Garbage Collection- Vectors (tuples):
vector
- Vector operations:
vector-set!
,vector-ref
,vector-length
- Stop and Copy garbage collection
- Vectors (tuples):
Functions- First class :
(vector foo #t)
- Mutually recursive
- Typed:
(define (add1 [x : Int]) : Int ...)
- First class :
Closures- Typed:
(let ([y 4]) (lambda ([z : Int]) : Int (+ y z)))
- Typed:
Arrays(array 1 2 3)
(array-set! {array} {index} {exp})
- Runtime bound checking
CharsPolymorphism- Type lambdas:
(Lambda A M)
- Type lambdas:
Type Constructors- User defined sum types
- Polymorphic
(define-type List A [Nil] [Cons (Vector A List)])
- Case expressions
Macros- Hygienic macros by example
let-syntax, define-syntax, syntax-case
Other features I have implemented, but are not in this compiler:
TODO:
- Unit Testing Macros
- Exceptions
- LLVM
- Hashtable
- ...