Skip to content

Commit

Permalink
Print the register allocation table instead of memory
Browse files Browse the repository at this point in the history
  • Loading branch information
z-silver committed Nov 25, 2024
1 parent cc4a985 commit e95398c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 9 additions & 2 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ module Option = struct
let ( let+ ) = Option.bind
end

let show_registers (registers : int Lib.Compiler.RegisterMap.t) : string =
let open Lib.Compiler.RegisterMap in
BatSeq.fold_left
(fun acc (term, register) ->
acc ^ "\n" ^ Lib.Ast.show term ^ " = " ^ string_of_int register)
"" (to_seq registers)

let _ =
let open Option in
let+ content =
Expand All @@ -14,9 +21,9 @@ let _ =
None
| decls_queries ->
let initialComputer = Lib.Machine.initialize () in
let finalStore =
let compiler, _ =
Lib.Compiler.compile
(decls_queries, Lib.Compiler.initialize (), initialComputer.store)
in
print_endline @@ Lib.Machine.show_store finalStore;
print_endline @@ show_registers compiler.registers;
None
10 changes: 5 additions & 5 deletions lib/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ type t = { registers : int RegisterMap.t; terms : term_queue }

let initialize () : t = { registers = RegisterMap.empty; terms = FT.empty }

let rec compile : Ast.t list * t * Cell.t Store.t -> Cell.t Store.t = function
| [], _, store -> store
let rec compile : Ast.t list * t * Cell.t Store.t -> t * Cell.t Store.t =
function
| [], compiler, store -> (compiler, store)
| [ d ], compiler, store -> (
match d with
| Query _ -> store (* TODO: error handling *)
| Query _ -> (compiler, store) (* TODO: error handling *)
| Variable _ | Functor _ -> failwith "unreachable"
| Declaration { head; body } ->
let _, new_store = compile_declaration head body compiler store in
new_store)
compile_declaration head body compiler store)
| _, _, _ -> failwith "TODO"

and compile_loop : t -> Cell.t Store.t -> t * Cell.t Store.t =
Expand Down

0 comments on commit e95398c

Please sign in to comment.