git @ Cat's Eye Technologies Deturgenchry / 9dc1690
`Object` was a terrible name for this, for obvious reasons. catseye 9 years ago
1 changed file(s) with 17 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
200200
201201 --
202202 -- 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]
208208
209209 --
210210 -- A continuation represents the remaining (sub-)computation(s) in a
221221 f contObj -- straightforward enuff
222222
223223 --
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
229233 | Null
230234 deriving (Show, Eq)
231235
242246 print (evalProg prog)
243247
244248 ---------------------------------------------------
245 evalProg :: Program -> Object
249 evalProg :: Program -> Value
246250
247251 evalProg p =
248252 case (getClass "Main" p) of
287291 set formal actual (buildContext formals actuals)
288292
289293 ---------------------------------------------------
290 evalStatement :: Program -> (Map Name Object) -> Statement -> Continuation -> ContObj
294 evalStatement :: Program -> (Map Name Value) -> Statement -> Continuation -> ContObj
291295
292296 evalStatement p ctx (Block []) cc =
293297 Ctx ctx
313317 Just _ -> error ("Attempted re-assignment of bound name " ++ name))
314318
315319 ---------------------------------------------------
316 evalExpr :: Program -> (Map Name Object) -> Expr -> Continuation -> ContObj
320 evalExpr :: Program -> (Map Name Value) -> Expr -> Continuation -> ContObj
317321
318322 evalExpr p ctx (Get ["self"]) cc =
319323 continue cc $ Obj $ ContVal EmptyMap cc