Mercurial > repos > icfp2012
comparison src/sim.tp @ 20:50a456168c25
Split readFd out of readFile for use in lifter. Add code to read map from stdin to lifter using code in sim
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 14 Jul 2012 12:33:01 -0700 |
parents | 26cfb964fe81 |
children | be6d1cf7b7d7 |
comparison
equal
deleted
inserted
replaced
19:7f2aba75c449 | 20:50a456168c25 |
---|---|
168 myStep <- myStep + 1 | 168 myStep <- myStep + 1 |
169 if: myStep > 5 {"A"} else: {"W"} | 169 if: myStep > 5 {"A"} else: {"W"} |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 readFile <- :path { | 173 readFd <- :fd { |
174 fd <- os open: path (os O_RDONLY) | |
175 if: fd < 0 { "" } else: { | 174 if: fd < 0 { "" } else: { |
176 cur <- "" | 175 cur <- "" |
177 part <- "" | 176 part <- "" |
178 while: { | 177 while: { |
179 part <- os read: fd 128 | 178 part <- os read: fd 128 |
180 part != "" | 179 part != "" |
181 } do: { | 180 } do: { |
182 cur <- cur . part | 181 cur <- cur . part |
183 } | 182 } |
184 os close: fd | |
185 cur | 183 cur |
186 } | 184 } |
185 } | |
186 | |
187 readFile <- :path { | |
188 fd <- os open: path (os O_RDONLY) | |
189 out <- readFd: fd | |
190 os close: fd | |
191 out | |
187 } | 192 } |
188 | 193 |
189 getMove <- { | 194 getMove <- { |
190 os read: 0 1 | 195 os read: 0 1 |
191 } | 196 } |