-
Notifications
You must be signed in to change notification settings - Fork 0
/
kompiler-sig.sml
77 lines (59 loc) · 2.39 KB
/
kompiler-sig.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
signature KOMPILER =
sig
exception Kompiler of string
datatype src =
Var of string
| Lambda of string * src
| Apply of src * src
| Card of Card.card
| Int of int
val src2str : src -> string
(*
Copy these into your file for shorter syntax, e.g.
\x.f (\y. x x y)
val w = \"x" ` $"f" -- (\"y" ` $"x" -- $"x" -- $"y")
infix 9 --
val op -- = Apply
val $ = Var
fun \ x exp = Lambda (x, exp)
infixr 1 `
fun a ` b = a b
*)
(* Helpful operators *)
(* A fixed point combinator, e.g.
compile (fix (Lambda ("self", Lambda ("x", ...)))) slot *)
val fix : src -> src
(* Takes an expression of type unit. Wraps in a function that ignores its
single argument, evaluates the expression, and then returns itself. *)
val run_and_return_self : src -> src
(* Version of run_and_return_self that uses an explicit get, on the named slot, instead of
the fixed point combinator. Must be installed in slot s (the second arg). *)
val rrs_ref : src -> int -> src
(* Take a function that represents the body of a loop, and return a function
that, when called, executes one iteration of the loop. The argument passed
the first time is used as the counter for the first iteration; after that
the counter is incremented by one. *)
val for : src -> src
(* Version of for that uses an explicit get, on the named slot, instead of
the fixed point combinator. Must be installed in slot s (the second arg). *)
val for_ref : src -> int -> src
(* Compiles a source expression into a turn-list that will create
that expression in the given slot. *)
val compile : src -> int -> LTG.turn list
(* You may get worse answers, but avoids rare exponential blowup. *)
val compile_never_exponential : src -> int -> LTG.turn list
(* As above, but doesn't clear the content of the slot first. If the given
turns are played, src will be left-applied to the current content of the
slot. *)
val compile_no_clear : src -> int -> LTG.turn list
(* Internal utilities *)
(* Kombinator internal language *)
datatype kil = KApply of kil * kil
| KCard of Card.card
| KVar of string
(* First translate from lambda calculus to Kombinators. *)
val src2kil : src -> kil
(* Run the tests and print results *)
val test : unit -> unit
val tomtest : unit -> unit
end