Skip to content

A a small ML-like language interpreted or compiled to x86-64 assembly with a custom runtime

Notifications You must be signed in to change notification settings

rootmos/silly-ml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

07ef507 · Oct 26, 2024
Oct 26, 2024
Jul 23, 2017
Jul 23, 2017
Jul 23, 2017
Jul 19, 2017
Oct 26, 2024
Oct 26, 2024
Oct 26, 2024
Jul 21, 2017
Jun 29, 2017
Jul 22, 2017
Jul 21, 2017

Repository files navigation

silly-ml

Build, test and push image

silly-ml (aka vacation-ml) is a:

  • small ML-like, type-checked language,
  • interpreted in a REPL or compiled to x86-64 assembly (with garbage getting both marked and sweeped),
  • created because it's weekend and because I haven't written one before,
  • coded in OCaml and inspired by OCaml.

Disclaimer: the silly prefix indicates that this is a hobby project with no other purpose than to learn and explore and it should definently be interpreted as an homage to its big brothers.

Usage

Simplest way to try it out is by using Docker:

docker run -it rootmos/silly-ml

and maybe use rlwrap to get a proper REPL feeling with line editing, history etc.

Examples

Here's an example session from the REPL:

> 7;;
7: int
> type foo = A | B of int;;
> A;;
A: foo
> B 7;;
B 7: foo
> let f x = match x with A -> 0 | B i -> i;;
> f;;
<fun>: foo -> int
> f A;;
0: int
> f (B 3);;
3: int
> type bar = C of foo;;
> C A;;
C A: bar
> f (C A);;
typed error: unification failed
> ((), 7);;
((), 7): (unit, int)
> 3 * (7 - (1 + 2));;
12: int
> let x = 7;;
> print_int x;; print_newline ();;
7
(): unit
> let f x y = x + y;;
> f;;
<fun>: int -> int -> int
> let g = f 1;;
> g;;
<fun>: int -> int
> let h = f 2;;
> h;;
<fun>: int -> int
> g 2;;
3: int
> h 2;;
4: int
> let sum n = let rec go acc i = match i with 0 -> acc | _ -> go (acc + i) (i - 1) in go 0 n;;
> sum;;
<fun>: int -> int
> sum 6;;
21: int
> let rec fib n = match n with 0 -> 0 | 1 -> 1 | n -> (fib (n - 1)) + (fib (n - 2));;
> fib 5;;
5: int
> fib 6;;
8: int
>

About

A a small ML-like language interpreted or compiled to x86-64 assembly with a custom runtime

Topics

Resources

Stars

Watchers

Forks