+ val nargs = length l
+ val nstack = if (nargs <= 4)
+ then 0
+ else nargs - 4
+ val stackb = nstack * 1
+ fun argdest 1 = (X.REG X.R0, [])
+ | argdest 2 = (X.REG X.R1, [])
+ | argdest 3 = (X.REG X.R2, [])
+ | argdest 4 = (X.REG X.R3, [])
+ | argdest n =
+ let
+ val t = Temp.new "argdest"
+ val t2 = Temp.new "argptr"
+ in
+ (X.TEMP t, (* Dude, I *love* this shit. *)
+ [ X.INSN (X.AL, X.MOVLIT (X.TEMP t2, Word.fromInt (0x10000 - (n - 4 + 1)))),
+ X.INSN (X.AL, X.ADD (X.TEMP t2, X.REG X.SP)),
+ X.INSN (X.AL, X.STO (X.TEMP t2, X.TEMP t)) ] )
+ end
+
+ val dests = List.tabulate (nargs, fn x => argdest (x+1))
+ val hf = List.map hasfixed l
+ val (d_hf, l_hf) = ListPair.unzip (ListPair.foldr
+ (fn (a,b,c) => if b then a::c else c)
+ nil
+ (ListPair.zip (dests,l), hf)
+ )
+ val (d_nohf, l_nohf) = ListPair.unzip (ListPair.foldr
+ (fn (a,b,c) => if b then c else a::c)
+ nil
+ (ListPair.zip (dests,l), hf)
+ )
+ val temps = List.map (fn _ => Temp.new ("arg")) l_hf
+ val argevals_hf = List.map
+ (fn (t,exp) => munch_exp (X.TEMP t) exp)
+ (ListPair.zip (temps, l_hf))
+ val argpushes = List.map
+ (fn ((dest, _), t) => [X.INSN (X.AL, X.MOV (dest, X.TEMP t))])
+ (ListPair.zip (d_hf, temps))
+ val argevals_nohf = List.map
+ (fn ((d,_),exp) => munch_exp d exp)
+ (ListPair.zip (d_nohf, l_nohf))
+ val shittodo = List.concat (List.map (fn (_, shit) => shit) (d_hf @ d_nohf))
+
+ val t_stackb = Temp.new ("stackb")
+ val t_target = Temp.new ("target")