-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: get rid of stdune from code generator
Signed-off-by: Rudi Grinberg <me@rgrinberg.com> <!-- ps-id: eb2c14ee-02d9-45df-a29a-3d85fca1759b -->
- Loading branch information
Showing
10 changed files
with
164 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,70 @@ | ||
include struct | ||
open Stdune | ||
module List = List | ||
module Id = Id | ||
module String = String | ||
module Code_error = Code_error | ||
module Comparable = Comparable | ||
module Top_closure = Top_closure | ||
module Poly = Poly | ||
module Option = Option | ||
|
||
let sprintf = sprintf | ||
let sprintf = Printf.sprintf | ||
|
||
module Option = struct | ||
include Option | ||
|
||
let map t ~f = Option.map f t | ||
|
||
let value_exn = function | ||
| None -> assert false | ||
| Some s -> s | ||
;; | ||
end | ||
|
||
module List = struct | ||
include ListLabels | ||
|
||
type ('a, 'b) skip_or_either = | ||
| Skip | ||
| Left of 'a | ||
| Right of 'b | ||
|
||
let rev_filter_partition_map = | ||
let rec loop l accl accr ~f = | ||
match l with | ||
| [] -> accl, accr | ||
| x :: l -> | ||
(match f x with | ||
| Skip -> loop l accl accr ~f | ||
| Left y -> loop l (y :: accl) accr ~f | ||
| Right y -> loop l accl (y :: accr) ~f) | ||
in | ||
fun l ~f -> loop l [] [] ~f | ||
;; | ||
|
||
let filter_partition_map l ~f = | ||
let l, r = rev_filter_partition_map l ~f in | ||
rev l, rev r | ||
;; | ||
end | ||
|
||
module String = struct | ||
include StringLabels | ||
|
||
let to_dyn = Dyn.string | ||
|
||
module Map = struct | ||
include MoreLabels.Map.Make (String) | ||
|
||
let of_list_reducei xs ~f = | ||
List.fold_left xs ~init:empty ~f:(fun map (k, v) -> | ||
update map ~key:k ~f:(function | ||
| None -> Some v | ||
| Some v' -> Some (f k v v'))) | ||
;; | ||
|
||
let of_list_map_exn xs ~f = List.map xs ~f |> of_list | ||
let union_exn x y = union ~f:(fun _ _ _ -> assert false) x y | ||
end | ||
end | ||
|
||
module Code_error = struct | ||
let raise name data = | ||
invalid_arg (sprintf "%s %s" name (Dyn.to_string (Dyn.record data))) | ||
;; | ||
end | ||
|
||
module Poly = struct | ||
let equal = Stdlib.( = ) | ||
let compare = Stdlib.compare | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.