Sign inSign up

rootmos/silly-ml

By rootmos

•Updated almost 2 years ago

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

Image
Languages & frameworks
0

9.5K

rootmos/silly-ml repository overview

⁠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
>

Tag summary

Content type

Image

Digest

sha256:7f886a139…

Size

19.5 MB

Last updated

almost 2 years ago

docker pull rootmos/silly-ml