module List = ListLabels
module Temp = Tiger_temp
+module T = Tiger_tree
type access =
| InFrame of {offset_from_frame_pointer : int}
; instructions : unit (* TODO: instructions for view shift *)
}
+let pointer = Temp.Temp.gen ()
+
let word_size_bits = 32
let word_size_bytes = word_size_bits / 8
let word_size = word_size_bytes
; locals_count
; instructions = () (* TODO: instructions for view shift *)
}
+
+(*failwith ("NOT IMPLEMENTED: " ^ __MODULE__ ^ ".exp")*)
+
+let exp ~access ~pointer =
+ match access with
+ | InReg {register} ->
+ T.TEMP register
+ | InFrame {offset_from_frame_pointer} ->
+ T.MEM (T.BINOP (T.PLUS, pointer, T.CONST offset_from_frame_pointer))
type access =
(* must know about static links *)
- { level : Level.t
- ; frame_access : Frame.access
+ { level : Level.t
+ ; access : Frame.access
}
let alloc_local ~level ~escapes =
{ level
- ; frame_access = Frame.alloc_local (Level.frame level) ~escapes
+ ; access = Frame.alloc_local (Level.frame level) ~escapes
}
let formals ~level =
alloc_local ~level ~escapes
)
+let not_implemented func =
+ failwith (Printf.sprintf "Not implemented: %s.%s" __MODULE__ func)
+
let rec seq = function
(* TODO: Is appending 0 OK? How else can the empty case be handled? *)
| [] -> T.EXP (T.CONST 0)
| Cx g -> g
let dummy__FIXME = Ex (T.CONST 0)
+
+let simple_var {level; access} =
+ let pointer = not_implemented "simple_var frame pointer" in
+ Ex (Frame.exp ~access ~pointer)