Skip to content

Commit

Permalink
chore: fix formatter & format the code (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Mar 9, 2021
1 parent 0160a5a commit b9c485a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 31 deletions.
8 changes: 4 additions & 4 deletions js/expression.ml
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 |]

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions 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)
2 changes: 1 addition & 1 deletion src/dune
Expand Up @@ -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
Expand Down
26 changes: 16 additions & 10 deletions 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. *)
Expand All @@ -22,15 +24,17 @@ 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. *)

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. *)

Expand All @@ -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"
Expand All @@ -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"

Expand Down
7 changes: 5 additions & 2 deletions test/test.ml
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion virtual/expression.mli
Expand Up @@ -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

Expand Down

0 comments on commit b9c485a

Please sign in to comment.