blob: ced0b92d74346134469abc359b1edd71496c6b71 (
plain) (
blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
(load "mu.arc")
(clear)
(add-fns '((test1
(1 <- loadi 1)
(2 <- loadi 3)
(3 <- add 1 2))))
(run function*!test1)
(if (~iso memory* (obj 1 1 2 3 3 4))
(prn "F - load and add instructions work"))
(clear)
(add-fns
'((add-fn
(3 <- add 1 2))
(main
(1 <- loadi 1)
(2 <- loadi 3)
(add-fn))))
(run function*!main)
;? (prn memory*)
(if (~iso memory* (obj 1 1 2 3 3 4))
(prn "F - compound functions work"))
(clear)
(add-fns
'((add-fn
(3 <- add 1 2)
(reply)
(4 <- loadi 34))
(main
(1 <- loadi 1)
(2 <- loadi 3)
(add-fn))))
(run function*!main)
;? (prn memory*)
(if (~iso memory* (obj 1 1 2 3 3 4))
(prn "F - early return works"))
;? (quit)
(clear)
(add-fns
'((add-fn
(4 <- read)
(5 <- read)
(3 <- add 4 5)
(reply)
(4 <- loadi 34))
(main
(1 <- loadi 1)
(2 <- loadi 3)
(add-fn 1 2)
)))
(run function*!main)
;? (prn memory*)
(if (~iso memory* (obj 1 1 2 3 3 4
; add-fn's temporaries
4 1 5 3))
(prn "F - parameterized compound fn"))
(clear)
(add-fns
'((add-fn
(4 <- read)
(5 <- read)
(6 <- add 4 5)
(reply 6)
(4 <- loadi 34))
(main
(1 <- loadi 1)
(2 <- loadi 3)
(3 <- add-fn 1 2))))
(run function*!main)
;? (prn memory*)
(if (~iso memory* (obj 1 1 2 3 3 4
; add-fn's temporaries
4 1 5 3 6 4))
(prn "F - parameterized compound fn with return value"))
(clear)
(add-fns
'((add-fn
(4 <- read)
(5 <- read)
(6 <- add 4 5)
(reply 6 5)
(4 <- loadi 34))
(main
(1 <- loadi 1)
(2 <- loadi 3)
(3 7 <- add-fn 1 2))))
(run function*!main)
;? (prn memory*)
(if (~iso memory* (obj 1 1 2 3 3 4 7 3
; add-fn's temporaries
4 1 5 3 6 4))
(prn "F - parameterized compound fn with multiple return values"))
|