`Object` was a terrible name for this, for obvious reasons.
catseye
9 years ago
200 | 200 | |
201 | 201 | -- |
202 | 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 | -- | |
205 | data ContObj = Ctx (Map Name Object) | |
206 | | Obj Object | |
207 | | Objs [Object] | |
203 | -- It can be a context (environment), a single value, or a list of values. | |
204 | -- | |
205 | data ContObj = Ctx (Map Name Value) | |
206 | | Obj Value | |
207 | | Objs [Value] | |
208 | 208 | |
209 | 209 | -- |
210 | 210 | -- A continuation represents the remaining (sub-)computation(s) in a |
221 | 221 | f contObj -- straightforward enuff |
222 | 222 | |
223 | 223 | -- |
224 | -- An object is anything else. Including, maybe, a continuation. | |
225 | -- | |
226 | data Object = IntVal Integer | |
227 | | ObjVal String (Map Name Object) | |
228 | | ContVal (Map Name Object) Continuation | |
224 | -- A value may be: | |
225 | -- an unbounded integer | |
226 | -- an object (which has a class name and a set of named attributes) | |
227 | -- a continuation value (which is an environment @ a continuation) | |
228 | -- null | |
229 | -- | |
230 | data Value = IntVal Integer | |
231 | | ObjVal String (Map Name Value) | |
232 | | ContVal (Map Name Value) Continuation | |
229 | 233 | | Null |
230 | 234 | deriving (Show, Eq) |
231 | 235 | |
242 | 246 | print (evalProg prog) |
243 | 247 | |
244 | 248 | --------------------------------------------------- |
245 | evalProg :: Program -> Object | |
249 | evalProg :: Program -> Value | |
246 | 250 | |
247 | 251 | evalProg p = |
248 | 252 | case (getClass "Main" p) of |
287 | 291 | set formal actual (buildContext formals actuals) |
288 | 292 | |
289 | 293 | --------------------------------------------------- |
290 | evalStatement :: Program -> (Map Name Object) -> Statement -> Continuation -> ContObj | |
294 | evalStatement :: Program -> (Map Name Value) -> Statement -> Continuation -> ContObj | |
291 | 295 | |
292 | 296 | evalStatement p ctx (Block []) cc = |
293 | 297 | Ctx ctx |
313 | 317 | Just _ -> error ("Attempted re-assignment of bound name " ++ name)) |
314 | 318 | |
315 | 319 | --------------------------------------------------- |
316 | evalExpr :: Program -> (Map Name Object) -> Expr -> Continuation -> ContObj | |
320 | evalExpr :: Program -> (Map Name Value) -> Expr -> Continuation -> ContObj | |
317 | 321 | |
318 | 322 | evalExpr p ctx (Get ["self"]) cc = |
319 | 323 | continue cc $ Obj $ ContVal EmptyMap cc |