-
Notifications
You must be signed in to change notification settings - Fork 2
/
PushTest.tz
executable file
·87 lines (63 loc) · 2.33 KB
/
PushTest.tz
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
#
# PushTest.tz 9/24/2004
# jon klein <jk@spiderland.org>
#
# This simulation is a basic test of breve's built-in Push language
# capabilities. See the PushRegression.tz demo for a more practical
# demonstration of Push as a genetic programming language.
#
@path "classes"
@path "lib/classes"
@use Push.
@use Control.
Controller myController.
Control : myController {
+ to init:
new PushTest go.
}
Object : PushTest {
+ variables:
code, code2, interpreter (object).
+ to init:
interpreter = new PushInterpreter.
interpreter clear-stacks.
interpreter read-config from-file "PushTest.config".
interpreter add-instruction for-instance self for-method "callback2" named "CALLBACK-TEST2".
interpreter add-instruction for-instance self for-method "callback" named "CALLBACK-TEST".
+ to test-set-from-list:
code = ( new PushProgram parse program "( ( INTEGER./ 1 1 1 1 1 1 1 1) )" ).
code2 copy-from program code.
# code2 set-from code-list { "X", code, "Y", code, "Z", code }.
code2 mutate with-interpreter interpreter.
code2 mutate with-interpreter interpreter.
code2 mutate with-interpreter interpreter.
code2 mutate with-interpreter interpreter.
print "c2: ", (code2 get-string).
print "c1: ", (code get-string).
+ to go:
interpreter push-integer value 100.
interpreter clear-stacks.
# code = (new PushProgram parse program "( 0 0 INTEGER./ 3.5 3.6 3.7 10.1 POINT.SETZ FLOAT.FROMPOINTZ)").
code = (new PushProgram parse program "( 0 0 INTEGER./ )" ).
code2 = (new PushProgram parse program "( 1 ( 3 ) ( 4 5 6 ) 8 4 CALLBACK-TEST CALLBACK2-TEST ( 1 ) ( INTEGER.* ) )").
self test-set-from-list.
print "Discrepancy", (code get-discrepancy from code2).
print "Top level diff", (code get-top-level-difference from code2).
print (code2 get-string).
interpreter run program code2.
print "Effort = ", (interpreter get-effort).
interpreter print-stacks.
interpreter print-config.
interpreter clear-stacks.
print (interpreter get-integer-stack-top).
free interpreter.
controller end-simulation.
+ to callback:
print "$self is calling the breve callback function, pushing 7, ".
interpreter push-integer value 7.
interpreter print-stacks.
+ to callback2:
print "$self is calling the breve callback2 function, pushing 8, ".
interpreter push-integer value 8.
interpreter print-stacks.
}