forked from ellisk42/ec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logoPrimitives.py
46 lines (39 loc) · 2.11 KB
/
logoPrimitives.py
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
from program import Primitive, Program
from listPrimitives import _map, _unfold, _range, _index, _fold, _if, _addition, _subtraction, _cons, _car, _cdr, _isEmpty, bootstrapTarget
from arithmeticPrimitives import addition
from type import arrow, baseType, t0, t1, tint, tlist, tbool
turtle = baseType("turtle")
tstate = baseType("tstate")
tangle = baseType("tangle")
tlength = baseType("tlength")
primitives = [
Primitive("logo_UA", tangle, ""),
Primitive("logo_UL", tlength, ""),
Primitive("logo_ZA", tangle, ""),
Primitive("logo_ZL", tlength, ""),
Primitive("logo_DIVA", arrow(tangle,tint,tangle), ""),
Primitive("logo_MULA", arrow(tangle,tint,tangle), ""),
Primitive("logo_DIVL", arrow(tlength,tint,tlength), ""),
Primitive("logo_MULL", arrow(tlength,tint,tlength), ""),
Primitive("logo_ADDA", arrow(tangle,tangle,tangle), ""),
Primitive("logo_SUBA", arrow(tangle,tangle,tangle), ""),
Primitive("logo_ADDL", arrow(tlength,tlength,tlength), ""),
Primitive("logo_SUBL", arrow(tlength,tlength,tlength), ""),
Primitive("logo_PU", arrow(turtle,turtle), ""),
Primitive("logo_PD", arrow(turtle,turtle), ""),
Primitive("logo_FWRT", arrow(tlength,tangle,turtle,turtle), ""),
# Primitive("logo_SET", arrow(tstate,turtle,turtle), ""),
# Primitive("logo_GET", arrow(arrow(tstate,turtle),turtle), "")
Primitive("logo_GETSET", arrow(turtle,turtle,turtle), "")
] + [
addition,
Primitive("logo_IFTY", tint, ""),
Primitive("logo_epsA", tangle, ""),
Primitive("logo_epsL", tlength, ""),
Primitive("logo_forLoopM", arrow(tint, arrow(tint, turtle), turtle, turtle), "ERROR: python has no way of expressing this hence you shouldn't eval on this"),
Primitive("+", arrow(tint, tint, tint), _addition)
] + [Primitive(str(j), tint, j) for j in range(7)]
if __name__ == "__main__":
expr_s = "(lambda (logo_forLoop 3 (lambda (lambda (logo_GET (lambda (logo_FWRT (logo_S2L (logo_I2S 1)) (logo_S2A (logo_I2S 0)) (logo_SET $0 (logo_FWRT (logo_S2L eps) (logo_DIVA (logo_S2A (logo_I2S 2)) (logo_I2S 3)) ($1)))))))) ($0)))"
x = Program.parse(expr_s)
print(x)