Anyone else done with Project 3? If not and you want to meet, give me a call: (214) 404-8096. Until then I’ll post some thoughts on the project.
Allthe work is in cps.sml’s cps function. Basically, you’re just connecting work you recursively did with the current computation (whether it’s a binop, apply, tuple, etc)

The cps function has 3 args: ce, ko, and kl. Now you may be wondering “Well when the heck do I use ko and kl??” That’s easy:

  • ko : this will be NONE when there is nothing left to do after computing ce
  • kl : this is ALWAYS appended to, and NEVER removed from. You will have to append every continuation created to it

Suggested ordering for implementing the body of cps:

  1. LetRec : Simple let fun ... without applications.
  2. App : Get Tail and NonTail working. This should be the first time you’ll create a continuation. So you’ll need: Label, Id, RetVal, Ret. make sure you prepend the cont you created before returning!
  3. BinOp, UnOp : The tough part’s done (assuming you tested app thoroughly) so these should two should be a breeze. Notes: Take advantage of buildSimpleCont. You can’t test if you are evaluating binops correctly until you have ref‘s done
  4. Fn
  5. Tuple : Here, I used List.foldr 3 times Notes: Take advantage of buildSimpleCont. You can’t test if you are evaluating tuples in the right order until you can create side-effects
  6. Ith, SetIth : These are needed for refs
  7. Retest Binops and Tuples. Create a test and run it in SML/NJ and compare. Note: Assignments in MiniML don’t return unit.
  8. If
  9. Constructor
  10. Error

Once you decide to try out test-map.mml I’d suggest unsetting the noisy flag (cps-interp.sml line 382). Otherwise you’ll be sitting around for hours waiting for the compiler to print.

Some tests to get started:

let fun f(x) = x in 13 end
let fun f(x) = x in f(13) end
(*make sure applying f not just returning 13*)
let fun f(x) = 7 in f(13) end
(*tail and nontail*)
let fun f(x) = let fun g(y) = x in g end in (f(13)) 7 end

Happy coding!

Advertisements