From 09434966e49054759422fab0b5d706678e8c2f08 Mon Sep 17 00:00:00 2001 From: OOHASHI Daichi Date: Mon, 11 Mar 2019 23:02:35 +0900 Subject: [PATCH] build src/* as a private library --- .gitignore | 1 - bin/dune | 6 +++++ bin/satysfi.ml | 1 + src/backend/base85.ml | 63 ------------------------------------------- src/dune | 3 +-- src/frontend/main.ml | 2 +- src/frontend/main.mli | 8 +----- 7 files changed, 10 insertions(+), 74 deletions(-) create mode 100644 bin/dune create mode 100644 bin/satysfi.ml delete mode 100644 src/backend/base85.ml diff --git a/.gitignore b/.gitignore index 96dc44a8f..e0dd548ae 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ *.out *.html obsolete/*.txt -bin/ old/ test/ *.png diff --git a/bin/dune b/bin/dune new file mode 100644 index 000000000..76405d7ce --- /dev/null +++ b/bin/dune @@ -0,0 +1,6 @@ +(executable + (name satysfi) + (public_name satysfi) + (libraries main) + (preprocess no_preprocessing) +) diff --git a/bin/satysfi.ml b/bin/satysfi.ml new file mode 100644 index 000000000..6c61511ff --- /dev/null +++ b/bin/satysfi.ml @@ -0,0 +1 @@ +let () = Main.main () diff --git a/src/backend/base85.ml b/src/backend/base85.ml deleted file mode 100644 index a7d2f0d24..000000000 --- a/src/backend/base85.ml +++ /dev/null @@ -1,63 +0,0 @@ - -let print_for_debug msg = - () - -open Unsigned - - -let get_byte s i = Char.code (String.get s i) - -let get_uint32 (s : string) (i : int) : uint32 = - let b0 = get_byte s i in - let b1 = get_byte s (i + 1) in - let b2 = get_byte s (i + 2) in - let b3 = get_byte s (i + 3) in - let s0 = UInt32.of_int ((b0 lsl 8) lor b1) in - let s1 = UInt32.of_int ((b2 lsl 8) lor b3) in - let ans = UInt32.logor (UInt32.shift_left s0 16) s1 in - let () = print_for_debug (Printf.sprintf "Q(%d %d %d %d)\n" b0 b1 b2 b3) in (* for debug *) - let () = print_for_debug (string_of_int (UInt32.to_int s0)) in (* for debug *) - let () = print_for_debug (string_of_int (UInt32.to_int s1)) in (* for debug *) - let () = print_for_debug ("2 * " ^ (string_of_int (UInt32.to_int (UInt32.div ans (UInt32.of_int 2))))) in (* for debug *) - ans - - -let decompose_85ary_5 n = - let q4 = UInt32.of_int (85 * 85 * 85 * 85) in - let q3 = UInt32.of_int (85 * 85 * 85) in - let q2 = UInt32.of_int (85 * 85) in - let q1 = UInt32.of_int 85 in - let (x0, r0) = (UInt32.div n q4, UInt32.rem n q4) in - let (x1, r1) = (UInt32.div r0 q3, UInt32.rem r0 q3) in - let (x2, r2) = (UInt32.div r1 q2, UInt32.rem r1 q2) in - let (x3, x4) = (UInt32.div r2 q1, UInt32.rem r2 q1) in - let (y0, y1, y2, y3, y4) = (UInt32.to_int x0, UInt32.to_int x1, UInt32.to_int x2, UInt32.to_int x3, UInt32.to_int x4) in - let () = print_for_debug (Printf.sprintf "(%d %d %d %d %d)\n" y0 y1 y2 y3 y4) in (* for debug *) - (y0, y1, y2, y3, y4) - - -let convert_to_base85_string (x0, x1, x2, x3, x4) = - let single x = - let () = print_for_debug ("C " ^ (string_of_int ((x + (Char.code '!'))))) in (* for debug *) - Char.chr (x + (Char.code '!')) - in - let tup = (single x0, single x1, single x2, single x3, single x4) in - match tup with - | ('!', '!', '!', '!', '!') -> "z" - | (c0, c1, c2, c3, c4) -> Printf.sprintf "%c%c%c%c%c" c0 c1 c2 c3 c4 - - -let encode (str : string) = - let len = String.length str in - let chop = (4 - (len mod 4)) mod 4 in - let len4s = len + chop in - let rec aux (i : int) (acc : string list) = - if i >= len4s then acc else - let n = get_uint32 str i in - let strenc = convert_to_base85_string (decompose_85ary_5 n) in - aux (i + 4) (strenc :: acc) - in - let acc = aux 0 [] in - let strenc = String.concat "" (List.rev acc) in - let lenenc = String.length strenc in - (String.sub strenc 0 (lenenc - chop)) ^ "~>" diff --git a/src/dune b/src/dune index 7c228ed68..c3db12432 100644 --- a/src/dune +++ b/src/dune @@ -1,6 +1,5 @@ -(executable +(library (name main) - (public_name satysfi) (flags (-w -3 -bin-annot -thread -unsafe-string)) (libraries str batteries diff --git a/src/frontend/main.ml b/src/frontend/main.ml index 38ba1b881..38010c724 100644 --- a/src/frontend/main.ml +++ b/src/frontend/main.ml @@ -989,7 +989,7 @@ let setup_root_dirs () = | _ :: _ -> Config.initialize ds -let () = +let main () = error_log_environment (fun () -> let curdir = Sys.getcwd () in Arg.parse (arg_spec_list curdir) (handle_anonimous_arg curdir) ""; diff --git a/src/frontend/main.mli b/src/frontend/main.mli index 53894b461..86f37aa4f 100644 --- a/src/frontend/main.mli +++ b/src/frontend/main.mli @@ -1,7 +1 @@ -open Types -open Typeenv -(* -val main : Typeenv.t -> environment -> string list -> string -> unit - -val error_log_environment : (unit -> unit) -> unit -*) +val main : unit -> unit