update code format
This commit is contained in:
@@ -1,32 +1,31 @@
|
||||
open Core
|
||||
open Hack
|
||||
|
||||
let read_file file =
|
||||
let not_empty str = not (String.is_empty str) in
|
||||
List.filter (In_channel.read_lines file) ~f:(not_empty)
|
||||
let read_file file =
|
||||
let not_empty str = not (String.is_empty str) in
|
||||
List.filter (In_channel.read_lines file) ~f:not_empty
|
||||
;;
|
||||
|
||||
let outfile file = String.concat [Filename.chop_extension file; ".hack"];;
|
||||
let outfile file = String.concat [ Filename.chop_extension file; ".hack" ]
|
||||
|
||||
let gen_hack file =
|
||||
let assembly = read_file file in
|
||||
let binary = Translate.translate assembly in
|
||||
let outchan = Out_channel.create (outfile file) in
|
||||
Out_channel.output_lines outchan binary;
|
||||
Out_channel.close outchan;
|
||||
Out_channel.close outchan
|
||||
;;
|
||||
|
||||
let param =
|
||||
let open Command.Param in
|
||||
anon ("filename" %: string)
|
||||
anon ("filename" %: string)
|
||||
;;
|
||||
|
||||
let command =
|
||||
Command.basic
|
||||
~summary:"Translate <filename>.asm to <filename>.hack"
|
||||
~readme: (fun () -> "Assembler for project 6 of Nand2Tetris")
|
||||
(Command.Param.map param ~f:(fun filename ->
|
||||
(fun () -> gen_hack filename)))
|
||||
~readme:(fun () -> "Assembler for project 6 of Nand2Tetris")
|
||||
(Command.Param.map param ~f:(fun filename () -> gen_hack filename))
|
||||
;;
|
||||
|
||||
let () = Command_unix.run command;;
|
||||
let () = Command_unix.run command
|
||||
|
Reference in New Issue
Block a user