diff --git a/js/expression.ml b/js/expression.ml index e0aaf8af..ef176a01 100644 --- a/js/expression.ml +++ b/js/expression.ml @@ -3,7 +3,7 @@ open Js_of_ocaml.Js.Unsafe type t = int -let block ?(return_type=Type.auto) wasm_mod name children = +let block ?(return_type = Type.auto) wasm_mod name children = meth_call wasm_mod "block" [| inject (string name); @@ -85,7 +85,7 @@ let global_set wasm_mod name value = let scope = get wasm_mod "global" in meth_call scope "set" [| inject (string name); inject value |] -let load wasm_mod byts ?(signed=false) offset align typ ptr = +let load wasm_mod byts ?(signed = false) offset align typ ptr = meth_call global##.binaryen "_BinaryenLoad" [| inject wasm_mod; @@ -148,11 +148,11 @@ let drop wasm_mod value = meth_call wasm_mod "drop" [| inject value |] let return wasm_mod value = meth_call wasm_mod "return" [| inject value |] -let memory_size wasm_mod = +let memory_size wasm_mod = let scope = get wasm_mod "memory" in meth_call scope "size" [||] -let memory_grow wasm_mod value = +let memory_grow wasm_mod value = let scope = get wasm_mod "memory" in meth_call scope "grow" [| inject value |] diff --git a/package.json b/package.json index 1b4e643a..52a1537d 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "scripts": { "test": "esy b dune runtest", - "format": "esy b dune build @fmt --auto-promote" + "format": "dune build @fmt --auto-promote" }, "installConfig": { "pnp": false diff --git a/src/config/library_flags.ml b/src/config/library_flags.ml index aed09514..f7720e87 100644 --- a/src/config/library_flags.ml +++ b/src/config/library_flags.ml @@ -1,17 +1,16 @@ module C = Configurator.V1 let () = - C.main ~name:"library_flags" (fun c -> - let default = [] in + C.main ~name:"library_flags" (fun c -> + let default = [] in - let library_flags = - match C.ocaml_config_var c "system" with - | Some("macosx") -> - (* These flags preserve the original C error behavior *) - ["-cclib"; "-Wl,-keep_dwarf_unwind"] - | Some(_) -> default - | None -> default - in + let library_flags = + match C.ocaml_config_var c "system" with + | Some "macosx" -> + (* These flags preserve the original C error behavior *) + [ "-cclib"; "-Wl,-keep_dwarf_unwind" ] + | Some _ -> default + | None -> default + in - C.Flags.write_sexp "library_flags.sexp" library_flags - ) + C.Flags.write_sexp "library_flags.sexp" library_flags) diff --git a/src/dune b/src/dune index 2d3b32bd..e14d7f81 100644 --- a/src/dune +++ b/src/dune @@ -12,7 +12,7 @@ (flags -O2 -Wall -Wextra)) (foreign_archives binaryen) (library_flags - (:include ./config/library_flags.sexp)) + (:include ./config/library_flags.sexp)) (c_library_flags -lstdc++ -lpthread)) (rule diff --git a/src/expression.ml b/src/expression.ml index 4a111bd4..7dad68fc 100644 --- a/src/expression.ml +++ b/src/expression.ml @@ -1,9 +1,11 @@ type t -external block : Module.t -> string -> t list -> Type.t -> t = "caml_binaryen_block" -let block ?(return_type=Type.auto) wasm_mod name exprs = - block wasm_mod name exprs return_type +external block : Module.t -> string -> t list -> Type.t -> t + = "caml_binaryen_block" + (** Module, block name, expression list. *) +let block ?(return_type = Type.auto) wasm_mod name exprs = + block wasm_mod name exprs return_type external if_ : Module.t -> t -> t -> t -> t = "caml_binaryen_if" (** Module, condition, true branch, false branch. False branch may be null. *) @@ -22,7 +24,8 @@ external call : Module.t -> string -> t list -> Type.t -> t = "caml_binaryen_call" (** Module, function name, params, return type. *) -external call_indirect : Module.t -> string -> t -> t list -> Type.t -> Type.t -> t +external call_indirect : + Module.t -> string -> t -> t list -> Type.t -> Type.t -> t = "caml_binaryen_call_indirect__bytecode" "caml_binaryen_call_indirect" (** Module, table, function value, params, params type, return type. *) @@ -30,7 +33,8 @@ external return_call : Module.t -> string -> t list -> Type.t -> t = "caml_binaryen_return_call" (** Module, function name, params, return type. *) -external return_call_indirect : Module.t -> string -> t -> t list -> Type.t -> Type.t -> t +external return_call_indirect : + Module.t -> string -> t -> t list -> Type.t -> Type.t -> t = "caml_binaryen_return_call_indirect__bytecode" "caml_binaryen_return_call_indirect" (** Module, table, function value, params, params type, return type. *) @@ -53,9 +57,10 @@ external global_set : Module.t -> string -> t -> t = "caml_binaryen_global_set" external load : Module.t -> int -> bool -> int -> int -> Type.t -> t -> t = "caml_binaryen_load__bytecode" "caml_binaryen_load" -let load wasm_mod bytes ?(signed=false) offset align ty ptr = - load wasm_mod bytes signed offset align ty ptr + (** Module, num_bytes, ?signed, offset, align, type, ptr. *) +let load wasm_mod bytes ?(signed = false) offset align ty ptr = + load wasm_mod bytes signed offset align ty ptr external store : Module.t -> int -> int -> int -> t -> t -> Type.t -> t = "caml_binaryen_store__bytecode" "caml_binaryen_store" @@ -67,10 +72,11 @@ external unary : Module.t -> Op.t -> t -> t = "caml_binaryen_unary" external binary : Module.t -> Op.t -> t -> t -> t = "caml_binaryen_binary" -external select : Module.t -> t -> t -> t -> Type.t -> t = "caml_binaryen_select" -let select wasm_mod cond tru fals = - select wasm_mod cond tru fals Type.auto +external select : Module.t -> t -> t -> t -> Type.t -> t + = "caml_binaryen_select" + (** Module, condition, true branch, false branch. *) +let select wasm_mod cond tru fals = select wasm_mod cond tru fals Type.auto external drop : Module.t -> t -> t = "caml_binaryen_drop" diff --git a/test/test.ml b/test/test.ml index cf2a5322..1d5a9145 100644 --- a/test/test.ml +++ b/test/test.ml @@ -13,11 +13,14 @@ let y () = Expression.local_get wasm_mod 1 Type.int32 let load = Expression.load wasm_mod 1 ~signed:true 0 0 Type.int32 (y ()) -let select = Expression.select wasm_mod (Expression.const wasm_mod (Literal.int32 1l)) (x ()) load +let select = + Expression.select wasm_mod + (Expression.const wasm_mod (Literal.int32 1l)) + (x ()) load let bin = Expression.binary wasm_mod Op.add_int32 select (y ()) -let add = Expression.block wasm_mod ~return_type:Type.int32 "add" [bin] +let add = Expression.block wasm_mod ~return_type:Type.int32 "add" [ bin ] (* Create the add function *) let adder = Function.add_function wasm_mod "adder" params results [||] add diff --git a/virtual/expression.mli b/virtual/expression.mli index 72c34fe0..19da2b39 100644 --- a/virtual/expression.mli +++ b/virtual/expression.mli @@ -16,7 +16,8 @@ val call_indirect : Module.t -> string -> t -> t list -> Type.t -> Type.t -> t val return_call : Module.t -> string -> t list -> Type.t -> t -val return_call_indirect : Module.t -> string -> t -> t list -> Type.t -> Type.t -> t +val return_call_indirect : + Module.t -> string -> t -> t list -> Type.t -> Type.t -> t val local_get : Module.t -> int -> Type.t -> t