Skip to content

A minimal ML, type-inferred, compiled, and/or interpreted in less than 750 lines

Notifications You must be signed in to change notification settings

hellerve/microml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

microml

A compiler from a simple ML-like language to C, and also a tree-walking interpreter. This was made as an illustration of how to turn the code from Eli Bendersky’s blog post on type inference into a simple compiler, with less than a few hundred lines added.

Usage

You can open a REPL by typing python main.py at the top of this repository, or execute a file by writing python main.py <myfile>.

The language looks roughly like this:

x y z = if y < z then y + z else y / z

(* we need a main function; no global expressions :( *)
main = lambda -> print(x(1,2))

And it will compile to C. It’s super small and minimal, but it shows you how to turn the typed AST into C, and how to write an object-oriented tree-walking interpreter.

If you’re in the REPL and want to find out what your current program would evaluate to, type :i—for interpretation—or :e—for proper, compiled execution.


Have fun!

About

A minimal ML, type-inferred, compiled, and/or interpreted in less than 750 lines

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages