annotate src/sim.tp @ 12:6ef6dc8ab95e

Get simulator compiling
author William Morgan <bill@mrgn.org>
date Sat, 14 Jul 2012 03:07:02 -0700
parents f28e465e9ee6
children c92633098f1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
1 {
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
2 true <- #{
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
3 if:else <- :self trueblock :elseblock {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
4 trueblock:
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
5 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
6 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
7
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
8 false <- #{
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
9 if:else <- :self trueblock :elseblock {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
10 elseblock:
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
11 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
12 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
13
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
14 eachbyte <- :string action {
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
15 strLen <- string byte_length:
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
16 index <- 0
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
17 while: {index < strLen} do: {
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
18 element <- (string byte: index)
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
19 action: index element
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
20 index <- index + 1
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
21 }
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
22 }
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
23
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
24 makeCellTypes <- {
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
25 allstr <- #[]
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
26 allobj <- #[]
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
27 new <- :idstr {
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
28 ret <- #{
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
29 id <- (idstr byte: 0)
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
30 isrobot <- { false }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
31 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
32 allobj append: ret
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
33 allstr append: idstr
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
34 ret
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
35 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
36 #{
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
37 find <- :idstr {
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
38 if: idstr = "R" { robot: } else: {
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
39 index <- 0
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
40 while: {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
41 if: index < (allstr length) {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
42 (allstr get: index) != idstr
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
43 } else: {false}
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
44 } do: {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
45 index <- index + 1
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
46 }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
47 if: index < (allstr length) {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
48 allobj get: index
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
49 } else: {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
50 empty
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
51 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
52 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
53 }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
54 wall <- new: "#"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
55 empty <- new: " "
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
56 earth <- new: "."
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
57 rock <- new: "*"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
58 lambda <- new: "\\"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
59 closedlift <- new: "L"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
60 openlift <- new: "O"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
61 newline <- new: "\n"
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
62 robot <- {
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
63 #{
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
64 id <- ("R" byte: 0)
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
65 isrobot <- { true }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
66 heldBreath <- 0
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
67 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
68 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
69 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
70 }
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
71 ttrue <- true
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
72 tfalse <- false
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
73 #{
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
74
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
75 // utilities
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
76 true <- ttrue
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
77
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
78 false <- tfalse
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
79
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
80 // end utilities
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
81
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
82
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
83 cellTypes <- makeCellTypes:
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
84
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
85 state <- #{
6
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
86 new <- :in_grid in_width in_height {
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
87 nextGrid <- #[]
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
88 robot <- false
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
89 foreach: in_grid :index el{
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
90 nextGrid append: el
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
91 if: (el isrobot) { robot <- el } else: { true }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
92 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
93 #{
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
94 grid <- in_grid
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
95 width <- in_width
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
96 height <- in_height
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
97 address <- :x y { x + y * width }
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
98 setCell <- :x y val {
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
99 grid set: (address: x y) val
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
100 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
101 getCell <- :x y {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
102 grid get: (address: x y)
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
103 }
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
104 water <- 0
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
105 flooding <- 0
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
106 waterproof <- 10
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
107 collected <- 0
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
108 moves <- 0
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
109 ended <- false
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
110 doUpdate <- {
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
111 true
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
112 }
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
113 advance <- :roboCmd {
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
114 ended <- roboCmd = "A"
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
115 robot move: roboCmd
6
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
116 moves <- moves + 1
7
1bd46f854dbb progress on sim, celltypes as objects
William Morgan <bill@mrgn.org>
parents: 6
diff changeset
117 doUpdate:
6
86cdb799f950 unbarfed some things
William Morgan <bill@mrgn.org>
parents: 5
diff changeset
118 self
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
119 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
120
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
121 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
122 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
123 fromStr <- :str {
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
124
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
125 strLen <- str byte_length:
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
126 maxRow <- 0
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
127 curRow <- 0
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
128 eachbyte: str :index element {
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
129 if: element = ((cellTypes newline) id) {
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
130 maxRow <- if: curRow > maxRow {curRow} else: {maxRow}
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
131 curRow <- 0
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
132 } else: {
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
133 curRow <- curRow + 1
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
134 }
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
135 }
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
136
12
6ef6dc8ab95e Get simulator compiling
William Morgan <bill@mrgn.org>
parents: 11
diff changeset
137 eachbyte: str :index element {
10
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
138 if: element = ((cellTypes newline) id) {
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
139 // add spaces
370a1eeb8812 merge and stuff
William Morgan <bill@mrgn.org>
parents: 9
diff changeset
140 curRow <- 0
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
141 } else: {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
142 curRow = curRow + 1
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
143 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
144 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
145 grid <- #[ ("#" byte: 0) ("#" byte: 0) ("#" byte: 0) ( "#" byte: 0) (" " byte: 0) ("#" byte: 0) ( "#" byte: 0) ("#" byte: 0) ("#" byte: 0)]
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
146 fresh <- new: grid 3 3
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
147 fresh
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
148 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
149 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
150
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
151 testMoves <- {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
152 myStep <- 0
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
153 {
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
154 print: (string: myStep)
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
155 myStep <- myStep + 1
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
156 if: myStep > 5 {"A"} else: {"W"}
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
157 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
158 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
159
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
160 readFile <- :path {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
161 fd <- os open: path (os O_RDONLY)
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
162 print: "fd: " . fd . "\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
163 if: fd < 0 { "" } else: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
164 cur <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
165 part <- ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
166 while: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
167 part <- os read: fd 128
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
168 print: "read: " . part . "\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
169 part != ""
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
170 } do: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
171 cur <- cur . part
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
172 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
173 os close: fd
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
174 cur
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
175 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
176 }
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
177
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
178 getMove <- {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
179 os read: 0 1
3
bb29dcd46cbf Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
180 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
181
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
182 main <- :args {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
183 if: (args length) < 2 {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
184 print: "usage: sim filename\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
185 } else: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
186 print: (args get: 1) . "\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
187 text <- readFile: (args get: 1)
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
188 simState <- state fromStr: text
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
189 while: { if: (simState ended) {false} else: {true} } do: {
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
190 print: "step...\n"
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
191 simState advance: (getMove: )
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
192 }
5
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
193 }
be946b2a2cbc initial barf into simulator file
William Morgan <bill@mrgn.org>
parents: 3
diff changeset
194 }
8
5941e6b3684c Read map file in simulator
Mike Pavone <pavone@retrodev.com>
parents: 6
diff changeset
195
3
bb29dcd46cbf Put dummy code in placeholder source files. Create makefile.
Mike Pavone <pavone@retrodev.com>
parents: 0
diff changeset
196 }
11
f28e465e9ee6 tried to unf*ck, ashamed rebarfing
William Morgan <bill@mrgn.org>
parents: 10
diff changeset
197 }