structure MipsFrame : FRAME = struct datatype frame = Frame of (access list (* formals *) (* * instructions I don't really understand this?*) * int (* locals allocated so far *) * Temp.label (* name of fun label *) ) datatype access = InFrame of int | InReg of Temp.temp fun newFrame (name, formals: bool list) = (* Do we actually have to add the size / number of saved registers to the inFrame(number)? *) (*map the bool list onto the access list, accumulating the count of local params along the way *) let fun mapBools(escapes::[], depth, regsAllocated) = if (escapes orelse (regsAllocated >= 4)) then ([InFrame(4 * depth)], depth+1) else ([Inreg (newlabel depth)], depth+1) | mapBools (escapes::tail, depth, regsAllocated) = if (escapes orelse (regsAllocated >= 4)) then (InFrame (4 * depth)::#1(mapBools(tail, depth+1, regsAllocated)), depth+1) else (InReg(newlabel depth)::#1(mapBools(tail, depth+1, regsAllocated+1)), depth+1) val (access', depth') = mapBools (formals,0,0) in (access' ,blah ,depth' ,Temp.newlabel(name)) end (* ----------------------------------------------------------------- *) fun name (MipsFrame.Frame (_, _, _, n) = n; (* ----------------------------------------------------------------- *) fun formals (MipsFrame.Frame (f, _, _, _) = f; (* ----------------------------------------------------------------- *) fun allocLocal (frame:frame, escapes:bool) = (* how do we decide when to allocate something in a register? for now lets just put everything on the frame *) if (bool) then (