Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use prelude when possible #247

Merged
merged 2 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions JS-Interpreters/ecmaref6/section 22/section_22.2.esl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* Copyright (C) 2022-2025 formalsec programmers
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -932,8 +932,8 @@ function TypedArrayFrom(constructor, items, mapfn, thisArg, strict) {
/* i. Let Pk be ToString(k). */
Pk := ToString(k);
/* ii. Let kValue be the first element of values and remove that element from values. */
kValue := l_nth(values, 0);
values := l_remove_nth(values, 0);
kValue := hd values;
values := tl values;
/* iii. If mapping is true, then */
if (mapping) {
/* 1. Let mappedValue be Call(mapfn, T, «kValue, k»). */
Expand Down
4 changes: 3 additions & 1 deletion bench/runner/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(executable
(name main)
(libraries prelude rusage smtml.prelude))
(flags
(:standard -open Smtml_prelude))
(libraries bos fpath fmt rusage smtml.prelude))
2 changes: 1 addition & 1 deletion bench/runner/main.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Bos
open Smtml_prelude.Result
open Result

let timeout = 300
let symbolic = Tool.symbolic ()
Expand Down
4 changes: 2 additions & 2 deletions bin/commands/cmd_execute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ let setup_program_harness code (interp : Prog.t) (harness : Fpath.t) :
Log.debug "Sucessfuly linked JS harness '%a' to interpreter." Fpath.pp harness;
Ok result.heap

let setup_execution code (jsinterp : Enums.JSInterp.t) (harness : Fpath.t option) :
(Prog.t * Value.t Heap.t option) Result.t =
let setup_execution code (jsinterp : Enums.JSInterp.t) (harness : Fpath.t option)
: (Prog.t * Value.t Heap.t option) Result.t =
let finterp = Enums.JSInterp.interp jsinterp in
let* interp = Cmd_compile.compile code true (Fpath.v finterp) in
match harness with
Expand Down
7 changes: 4 additions & 3 deletions bin/commands/cmd_interpret.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ module InterpreterMetrics = struct
(pp_el pp_counter) counter

let log (profiler : Enums.InterpProfiler.t) (metrics : t) : unit =
if profiler == None then () else Log.esl "Execution metrics:%a" pp metrics
if Enums.InterpProfiler.equal profiler None then ()
else Log.esl "Execution metrics:%a" pp metrics
end

module InterpreterInstrument = struct
Expand Down Expand Up @@ -143,8 +144,8 @@ module InterpreterInstrument = struct
(module Interpreter_tooling.Default (Tracer) (Debugger) (Profiler) (Monitor))
end

let interpret_partial code (entry : Interpreter.IEntry.t) (config : Options.config)
(prog : Prog.t) : Interpreter.IResult.t =
let interpret_partial code (entry : Interpreter.IEntry.t)
(config : Options.config) (prog : Prog.t) : Interpreter.IResult.t =
let instrument = config.instrument in
let module Instrument = (val InterpreterInstrument.intrument instrument) in
let module ConcreteInterpreter = Interpreter.M (Instrument) in
Expand Down
11 changes: 8 additions & 3 deletions bin/enums.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(* Copyright (C) 2022-2025 formalsec programmers
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*)
Expand Down Expand Up @@ -132,6 +132,11 @@ module InterpProfiler = struct

let all () : t list = [ None; Time; Full ]

let equal a b =
match (a, b) with
| (None, None) | (Time, Time) | (Full, Full) -> true
| ((None | Time | Full), _) -> false

let pp (ppf : Format.formatter) (profiler : t) : unit =
match profiler with
| None -> Fmt.string ppf "none"
Expand Down
5 changes: 3 additions & 2 deletions bin/testing/test_runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ let execute code (env : Prog.t * Value.t Heap.t option)
let skip_test (record : Test_record.t) : Test_record.t Result.t =
Ok { record with result = Skipped }

let execute_test code (env : Prog.t * Value.t Heap.t option) (record : Test_record.t)
(interp_profiler : Enums.InterpProfiler.t) : Test_record.t Result.t =
let execute_test code (env : Prog.t * Value.t Heap.t option)
(record : Test_record.t) (interp_profiler : Enums.InterpProfiler.t) :
Test_record.t Result.t =
let interp_config = interp_config interp_profiler in
let* input = set_test_flags record in
let streams = Log.Redirect.capture Shared in
Expand Down
4 changes: 1 addition & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
(mdx :with-test)
(ppx_inline_test :with-test)
(prelude
(and
(>= "0.5")
:with-test))
(>= "0.5"))
(rusage :with-test)
(bisect_ppx
(and
Expand Down
2 changes: 1 addition & 1 deletion ecma-sl.opam
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ depends: [
"ppx_deriving"
"mdx" {with-test}
"ppx_inline_test" {with-test}
"prelude" {>= "0.5" & with-test}
"prelude" {>= "0.5"}
"rusage" {with-test}
"bisect_ppx" {>= "2.5.0" & with-test & with-dev-setup}
]
Expand Down
16 changes: 8 additions & 8 deletions src/base/base.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
(* Copyright (C) 2022-2025 formalsec programmers
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*)
open Prelude

let default_hashtbl_sz : int ref = ref 16

Expand All @@ -29,13 +30,12 @@ let make_counter (init : int) (step : int) : counter =

let make_name_generator (base : string) : unit -> string =
let (next, _) = make_counter 0 1 in
fun () -> base ^ string_of_int (next ())
fun () -> Fmt.str "%s%d" base (next ())

let ordinal_suffix (n : int) : string =
string_of_int n
^
if n mod 100 / 10 = 1 then "th"
else match n mod 10 with 1 -> "st" | 2 -> "nd" | 3 -> "rd" | _ -> "th"
Fmt.str "%d%s" n
( if n mod 100 / 10 = 1 then "th"
else match n mod 10 with 1 -> "st" | 2 -> "nd" | 3 -> "rd" | _ -> "th" )

type formated_time = int * int * int * int

Expand Down
7 changes: 4 additions & 3 deletions src/base/cont.ml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
(* Copyright (C) 2022-2025 formalsec programmers
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*)
open Prelude

type 'a t = ('a -> unit) -> unit

Expand Down
2 changes: 1 addition & 1 deletion src/base/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
(public_name ecma-sl.base)
(name eslBase)
(modules base cont font log io string terminal)
(libraries unix fmt)
(libraries fmt prelude unix)
(instrumentation
(backend bisect_ppx)))
10 changes: 6 additions & 4 deletions src/base/font.ml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
(* Copyright (C) 2022-2025 formalsec programmers
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*)

open Prelude

module Config = struct
let colored = ref true
end

let colored (fdesc : Unix.file_descr option) (ppf : Format.formatter) : bool =
!Config.colored
&& Option.fold ~none:true ~some:Terminal.colored fdesc
&& (ppf == Fmt.stdout || ppf == Fmt.stderr)
&& (phys_equal ppf Fmt.stdout || phys_equal ppf Fmt.stderr)

type font_v =
| Normal
Expand Down
30 changes: 14 additions & 16 deletions src/base/io.ml
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
(* Copyright (C) 2022-2025 formalsec programmers
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*)
open Prelude

let fin (process_f : in_channel -> 'a) (file : string) : 'a =
let ic = open_in file in
Fun.protect ~finally:(fun () -> close_in ic) (fun () -> process_f ic)
let[@inline] fin (process_f : in_channel -> 'a) (file : string) : 'a =
In_channel.with_open_text file process_f

let fout (process_f : out_channel -> 'a) (file : string) : 'a =
let oc = open_out file in
Fun.protect ~finally:(fun () -> close_out oc) (fun () -> process_f oc)
let[@inline] fout (process_f : out_channel -> 'a) (file : string) : 'a =
Out_channel.with_open_text file process_f

let read_in_channel (ic : in_channel) : string =
let in_sz = in_channel_length ic in
really_input_string ic in_sz
let[@inline] read_in_channel (ic : in_channel) : string =
In_channel.input_all ic

let write_out_channel (data : string) (oc : out_channel) : unit =
output_string oc data
let[@inline] write_out_channel (data : string) (oc : out_channel) : unit =
Out_channel.output_string oc data

let read_file (file : string) : string = fin read_in_channel file
let[@inline] read_file (file : string) : string = fin read_in_channel file

let write_file (file : string) (data : string) : unit =
let[@inline] write_file (file : string) (data : string) : unit =
fout (write_out_channel data) file
6 changes: 3 additions & 3 deletions src/base/log.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(* Copyright (C) 2022-2025 formalsec programmers
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*)
Expand Down
10 changes: 5 additions & 5 deletions src/base/string.ml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
(* Copyright (C) 2022-2025 formalsec programmers
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*)

include Stdlib.String
open Prelude
include String

let substr ?(left : int option) ?(right : int option) (text : string) : string =
let left' = Option.value ~default:0 left in
Expand Down
Loading
Loading