Skip to content

Commit

Permalink
Remove C bindings for try_catch/try_delegate and replace with OCaml i…
Browse files Browse the repository at this point in the history
…mplementations
  • Loading branch information
peblair committed Oct 16, 2023
1 parent 1b981f7 commit 053c185
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 76 deletions.
48 changes: 0 additions & 48 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -1923,54 +1923,6 @@ CAMLprim value caml_binaryen_try_bytecode(value *argv, int argn) {
return caml_binaryen_try_native(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
}

CAMLprim value
caml_binaryen_trycatch(value _module, value _name, value _body, value _catchTags, value _catchBodies) {
CAMLparam5(_module, _name, _body, _catchTags, _catchBodies);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char *name;
if (Is_none(_name)) {
name = NULL;
} else {
name = Safe_String_val(Some_val(_name));
}
BinaryenExpressionRef body = BinaryenExpressionRef_val(_body);
_catchTags = array_of_list(_catchTags);
int catchTagsLen = array_length(_catchTags);
const char* catchTags[catchTagsLen];
for (int i = 0; i < catchTagsLen; i++) {
catchTags[i] = Safe_String_val(Field(_catchTags, i));
}
_catchBodies = array_of_list(_catchBodies);
int catchBodiesLen = array_length(_catchBodies);
BinaryenExpressionRef catchBodies[catchBodiesLen];
for (int i = 0; i < catchBodiesLen; i++) {
catchBodies[i] = BinaryenExpressionRef_val(Field(_catchBodies, i));
}
char *delegateTarget = NULL;
BinaryenExpressionRef exp = BinaryenTry(module, name, body, catchTags, catchTagsLen, catchBodies, catchBodiesLen, delegateTarget);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}

CAMLprim value
caml_binaryen_trydelegate(value _module, value _name, value _body, value _delegateTarget) {
CAMLparam4(_module, _name, _body,_delegateTarget);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
char *name;
if (Is_none(_name)) {
name = NULL;
} else {
name = Safe_String_val(Some_val(_name));
}
BinaryenExpressionRef body = BinaryenExpressionRef_val(_body);
char *delegateTarget = Safe_String_val(_delegateTarget);
int catchTagsLen = 0;
int catchBodiesLen = 0;
const char *catchTags[1] = {NULL};
BinaryenExpressionRef catchBodies[1] = {NULL};
BinaryenExpressionRef exp = BinaryenTry(module, name, body, catchTags, catchTagsLen, catchBodies, catchBodiesLen, delegateTarget);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}

CAMLprim value
caml_binaryen_throw(value _module, value _tag, value _operands) {
CAMLparam3(_module, _tag, _operands);
Expand Down
24 changes: 0 additions & 24 deletions src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -1726,30 +1726,6 @@ function caml_binaryen_try_bytecode() {
return caml_binaryen_try_native(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
}

//Provides: caml_binaryen_trycatch
//Requires: caml_jsstring_of_string, caml_list_to_js_array
function caml_binaryen_trycatch(wasm_mod, name, body, catch_tags, catch_bodies) {
return wasm_mod.try(
caml_jsstring_of_string(name),
body,
caml_list_to_js_array(catch_tags).map(caml_jsstring_of_string),
caml_list_to_js_array(catch_bodies),
null,
);
}

//Provides: caml_binaryen_trydelegate
//Requires: caml_jsstring_of_string, caml_list_to_js_array
function caml_binaryen_trydelegate(wasm_mod, name, body, delegate_target) {
return wasm_mod.try(
caml_jsstring_of_string(name),
body,
[],
[],
delegate_target ? caml_jsstring_of_string(delegate_target[1]) : null,
);
}

//Provides: caml_binaryen_throw
//Requires: caml_jsstring_of_string, caml_list_to_js_array
function caml_binaryen_throw(wasm_mod, tag, operands) {
Expand Down
6 changes: 2 additions & 4 deletions src/expression.ml
Original file line number Diff line number Diff line change
Expand Up @@ -856,13 +856,11 @@ module Try = struct
end

module Try_Catch = struct
external make : Module.t -> string option -> t -> string list -> t list -> t = "caml_binaryen_trycatch"
(** Module, name, body, catch tags, catch bodies *)
let make module_ name body catch_tags catch_bodies = Try.make module_ name body catch_tags catch_bodies None
end

module Try_Delegate = struct
external make : Module.t -> string option -> t -> string -> t = "caml_binaryen_trydelegate"
(** Module, name, body, delegate *)
let make module_ name body delegate = Try.make module_ name body [] [] (Some delegate)
end

module Throw = struct
Expand Down

0 comments on commit 053c185

Please sign in to comment.