Rename ContV to something less easily confused with ContVal...
catseye
11 years ago
198 | 198 | |
199 | 199 | -- ========== RUNTIME ========== -- |
200 | 200 | |
201 | -- | |
202 | -- A ContObj is what continuations pass along to each other. | |
203 | -- It can be a context (environment), a single object, or a list of objects. | |
204 | -- | |
201 | 205 | data ContObj = Ctx (Map Name Object) |
202 | 206 | | Obj Object |
203 | 207 | | Objs [Object] |
204 | 208 | |
205 | 209 | type Continuation = ContObj -> ContObj |
206 | 210 | |
207 | data ContV = ContV Continuation | |
208 | instance Show ContV where | |
209 | show (ContV _) = "" | |
210 | instance Eq ContV where | |
211 | ContV _ == ContV _ = False | |
211 | data ContJ = ContJ Continuation | |
212 | instance Show ContJ where | |
213 | show (ContJ _) = "" | |
214 | instance Eq ContJ where | |
215 | ContJ _ == ContJ _ = False | |
212 | 216 | |
213 | 217 | data Object = IntVal Integer |
214 | 218 | | ObjVal String (Map Name Object) |
215 | | ContVal (Map Name Object) ContV | |
219 | | ContVal (Map Name Object) ContJ | |
216 | 220 | | Null |
217 | 221 | deriving (Show, Eq) |
218 | 222 | |
239 | 243 | Nothing -> error "No Main class with main() method found" |
240 | 244 | Just mainMethod -> |
241 | 245 | let |
242 | final = ContV id | |
246 | final = ContJ id | |
243 | 247 | r = callMethod p (ContVal EmptyMap final) mainMethod [] |
244 | 248 | in |
245 | 249 | case r of |
260 | 264 | case (length actuals) - (length formals) of |
261 | 265 | 0 -> |
262 | 266 | let |
263 | self = (ContVal EmptyMap (ContV id)) -- NO NOT REALLY | |
267 | self = (ContVal EmptyMap (ContJ id)) -- NO NOT REALLY | |
264 | 268 | ctx = buildContext formals actuals |
265 | 269 | ctx' = set "self" self ctx |
266 | 270 | ctx'' = set "other" other ctx' |
292 | 296 | |
293 | 297 | evalStatement p ctx (Transfer dest e) _ = |
294 | 298 | evalExpr p ctx e (\(Obj value) -> |
295 | evalExpr p ctx dest (\(Obj (ContVal m (ContV k))) -> | |
299 | evalExpr p ctx dest (\(Obj (ContVal m (ContJ k))) -> | |
296 | 300 | k $ Obj value)) |
297 | 301 | |
298 | 302 | evalStatement p ctx (Assign name e) cc = |
318 | 322 | let |
319 | 323 | Just klass = getClass className p |
320 | 324 | Just method = getMethod methodName klass |
321 | newOther = ContVal ctx $ ContV cc | |
325 | newOther = ContVal ctx $ ContJ cc | |
322 | 326 | in |
323 | 327 | callMethod p newOther method actuals)) |
324 | 328 |