Skip to content

Commit

Permalink
start changing the default scope from Core to Base in some places
Browse files Browse the repository at this point in the history
- This is a proof of concept showing this can be done incrementally
  directory per directory.
  • Loading branch information
mbarbin committed Oct 31, 2023
1 parent 5e3b92e commit bc17c8b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 25 deletions.
2 changes: 2 additions & 0 deletions bopkit.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ depends: [
"appendable-list" {>= "v0.16" & < "v0.17"}
"ANSITerminal" {>= "0.8.3"}
"bogue" {>= "20221112"}
"base" {>= "v0.16" & < "v0.17"}
"core" {>= "v0.16" & < "v0.17"}
"core_unix" {>= "v0.16" & < "v0.17"}
"graphics" {>= "5.1.2"}
Expand All @@ -21,6 +22,7 @@ depends: [
"ppx_jane" {>= "v0.16" & < "v0.17"}
"ppx_js_style" {>= "v0.16" & < "v0.17"}
"pp" {>= "1.1.2"}
"stdio" {>= "v0.16" & < "v0.17"}
"stdune" {>= "3.11"}
"tsdl" {>= "0.9.8"}
"tsdl-image" {>= "0.6"}
Expand Down
5 changes: 3 additions & 2 deletions lib/bopkit/src/arithmetic_expression.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type t =
let log2 =
let rec aux accu n =
let nsur2 = n / 2 in
if nsur2 = 0 then accu else aux (succ accu) nsur2
if nsur2 = 0 then accu else aux (Int.succ accu) nsur2
in
aux 0
;;
Expand Down Expand Up @@ -60,7 +60,7 @@ let eval t ~parameters =
| SUB (a, b) -> eval a - eval b
| DIV (a, b) -> eval a / eval b
| MULT (a, b) -> eval a * eval b
| MOD (a, b) -> eval a mod eval b
| MOD (a, b) -> eval a % eval b
| EXP (a, b) -> Int.pow (eval a) (eval b)
| MIN (a, b) -> min (eval a) (eval b)
| MAX (a, b) -> max (eval a) (eval b)
Expand All @@ -70,6 +70,7 @@ let eval t ~parameters =
;;

let pp t =
let module Format = Stdlib.Format in
let rec aux formatter = function
| ADD (t1, t2) -> Format.fprintf formatter "%a + %a" aux t1 aux_closed t2
| SUB (t1, t2) ->
Expand Down
4 changes: 2 additions & 2 deletions lib/bopkit/src/comment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type t =

let parse text =
let text = String.strip text in
with_return (fun { return } ->
With_return.with_return (fun { return } ->
if String.length text < 2 then return None;
if not (Char.equal text.[0] '/') then return None;
let newlines = String.count text ~f:(fun c -> Char.equal c '\n') in
Expand Down Expand Up @@ -77,7 +77,7 @@ let parse_exn comment =
let render = function
| Single_line { is_documentation_comment; text } ->
let prefix = if is_documentation_comment then "///" else "//" in
[ (if String.is_empty text then prefix else sprintf "%s %s" prefix text) ]
[ (if String.is_empty text then prefix else Printf.sprintf "%s %s" prefix text) ]
| Multiple_lines { is_documentation_comment; lines } ->
if is_documentation_comment
then
Expand Down
4 changes: 2 additions & 2 deletions lib/bopkit/src/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name bopkit)
(public_name bopkit.bopkit)
(flags -w +a-4-40-42-44-66 -warn-error +a -open Core)
(libraries appendable-list bit_utils core error_log parsing_utils pp)
(flags -w +a-4-40-42-44-66 -warn-error +a -open Base)
(libraries appendable-list base bit_utils error_log parsing_utils pp)
(preprocess
(pps ppx_jane ppx_js_style -check-doc-comments)))
4 changes: 2 additions & 2 deletions lib/bopkit/src/expand_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ let eval_variable (variable : Netlist.variable) ~error_log ~parameters
let expand_const_variable (variable : Expanded_netlist.variable) =
match variable with
| Signal { name } -> [ name ]
| Internal i -> [ sprintf "#%d#" i ]
| Internal i -> [ Printf.sprintf "#%d#" i ]
| Bus { loc = _; name; indexes } ->
let suffixes = expand_indexes indexes ~f:(fun i -> sprintf "[%d]" i) in
let suffixes = expand_indexes indexes ~f:(fun i -> Printf.sprintf "[%d]" i) in
List.map suffixes ~f:(fun suffix -> name ^ suffix)
;;

Expand Down
4 changes: 2 additions & 2 deletions lib/bopkit/src/or_eval_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ include Monad.Make (struct
end)

let with_return f =
with_return (fun return ->
With_return.with_return (fun return ->
Ok (f ~error:(With_return.prepend return ~f:(fun e -> Error e))))
;;

let propagate ~error = function
let propagate ~(error : _ With_return.return) = function
| Ok e -> e
| Error e -> error.return e
;;
Expand Down
4 changes: 2 additions & 2 deletions lib/bopkit/src/or_eval_error.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type 'a t = ('a, Eval_error.t) Result.t [@@deriving sexp_of]
include Applicative.S with type 'a t := 'a t
include Monad.S with type 'a t := 'a t

val with_return : (error:Eval_error.t return -> 'a) -> 'a t
val propagate : error:Eval_error.t return -> 'a t -> 'a
val with_return : (error:Eval_error.t With_return.return -> 'a) -> 'a t
val propagate : error:Eval_error.t With_return.return -> 'a t -> 'a
val ok : 'a t -> f:(Eval_error.t -> 'a) -> 'a
val ok_exn : 'a t -> error_log:Error_log.t -> loc:Loc.t -> 'a
8 changes: 4 additions & 4 deletions lib/bopkit/src/parameter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Value = struct

let to_syntax = function
| Int d -> Int.to_string d
| String s -> sprintf "%S" s
| String s -> Printf.sprintf "%S" s
;;
end

Expand All @@ -22,9 +22,9 @@ let arg_type =
| None -> failwith "Invalid parameter argument. Expected 'name=value'."
| Some (name, value) ->
let value : Value.t =
match int_of_string value with
| i -> Int i
| exception _ -> String value
match Int.of_string_opt value with
| Some i -> Int i
| None -> String value
in
{ name; value }
in
Expand Down
14 changes: 7 additions & 7 deletions lib/bopkit/src/string_with_vars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ let parse t =
else if Char.equal t.[i] (Syntax.close_char syntax)
then (
Queue.enqueue bounds (offset, len);
enqueue 0 0 ~is_parsing_var:None (succ i))
else enqueue offset (succ len) ~is_parsing_var (succ i)
enqueue 0 0 ~is_parsing_var:None (Int.succ i))
else enqueue offset (Int.succ len) ~is_parsing_var (Int.succ i)
| None ->
if i >= len_t
then ()
else (
match
if Char.equal t.[i] '$'
&& i <= len_t - 2
&& Char.( = ) t.[succ i] (Syntax.open_char Dollar)
&& Char.( = ) t.[Int.succ i] (Syntax.open_char Dollar)
then Some Syntax.Dollar
else if Char.equal t.[i] '%'
&& i <= len_t - 2
&& Char.( = ) t.[succ i] (Syntax.open_char Percent)
&& Char.( = ) t.[Int.succ i] (Syntax.open_char Percent)
then Some Syntax.Percent
else None
with
| Some syntax ->
if i >= len_t - 3
then error.return (Syntax_error { in_ = t })
else enqueue i 3 ~is_parsing_var:(Some syntax) (i + 2)
| None -> enqueue 0 0 ~is_parsing_var:None (succ i))
| None -> enqueue 0 0 ~is_parsing_var:None (Int.succ i))
in
let parts : Part.t Queue.t = Queue.create () in
let rec dequeue b =
Expand All @@ -90,7 +90,7 @@ let to_string ?(syntax = Syntax.Dollar) { parts } =
List.map parts ~f:(function
| Text text -> text
| Var var ->
sprintf
Printf.sprintf
"%c%c%s%c"
(Syntax.start syntax)
(Syntax.open_char syntax)
Expand All @@ -104,7 +104,7 @@ let sexp_of_t t = Sexp.Atom (to_string t)
let string_of_var ~parameters v =
Or_eval_error.with_return (fun ~error ->
match Parameters.find parameters ~parameter_name:v with
| Some (Parameter.Value.Int i) -> string_of_int i
| Some (Parameter.Value.Int i) -> Int.to_string i
| Some (Parameter.Value.String s) -> s
| None ->
error.return (Free_variable { name = v; candidates = Parameters.keys parameters }))
Expand Down
14 changes: 12 additions & 2 deletions lib/bopkit/test/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
(library
(name bopkit_test)
(flags -w +a-4-40-41-42-44-66 -warn-error +a -open Core -open Bopkit)
(libraries core bopkit pp)
(flags
-w
+a-4-40-41-42-44-66
-warn-error
+a
-open
Base
-open
Stdio
-open
Bopkit)
(libraries base bopkit pp stdio)
(inline_tests)
(preprocess
(pps ppx_jane ppx_js_style -check-doc-comments)))

0 comments on commit bc17c8b

Please sign in to comment.