Skip to content

Commit

Permalink
Tests: fix and accept
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Jan 13, 2023
1 parent 7ea8780 commit 3b4cf0e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
8 changes: 6 additions & 2 deletions compiler/tests-compiler/call_gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ module M1 = struct
function m(_e_,_f_){return k(_d_,_c_,_e_,_f_)}
//end
function caml_call1(f,a0)
{return f.length == 1?f(a0):runtime.caml_call_gen(f,[a0])}
{return (f.l >= 0?f.l:f.l = f.length) == 1
?f(a0)
:runtime.caml_call_gen(f,[a0])}
//end
function caml_call2(f,a0,a1)
{return f.length == 2?f(a0,a1):runtime.caml_call_gen(f,[a0,a1])}
{return (f.l >= 0?f.l:f.l = f.length) == 2
?f(a0,a1)
:runtime.caml_call_gen(f,[a0,a1])}
//end
|}]
end
Expand Down
4 changes: 3 additions & 1 deletion compiler/tests-compiler/effects_toplevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
:runtime.caml_trampoline_return(f,[a0])}
function caml_cps_call2(f,a0,a1)
{return runtime.caml_stack_check_depth()
?f.length == 2?f(a0,a1):runtime.caml_call_gen(f,[a0,a1])
?(f.l >= 0?f.l:f.l = f.length) == 2
?f(a0,a1)
:runtime.caml_call_gen(f,[a0,a1])
:runtime.caml_trampoline_return(f,[a0,a1])}
function caml_cps_exact_call2(f,a0,a1)
{return runtime.caml_stack_check_depth()
Expand Down
4 changes: 3 additions & 1 deletion compiler/tests-compiler/gh1051.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ let%expect_test _ =
{|
Warning: integer overflow: integer 0xffffffff (4294967295) truncated to 0xffffffff (-1); the generated code might be incorrect.
function caml_call2(f,a0,a1)
{return f.length == 2?f(a0,a1):runtime.caml_call_gen(f,[a0,a1])}
{return (f.l >= 0?f.l:f.l = f.length) == 2
?f(a0,a1)
:runtime.caml_call_gen(f,[a0,a1])}
//end |}];
()
12 changes: 9 additions & 3 deletions compiler/tests-compiler/gh1354.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ with Exit ->
runtime=globalThis.jsoo_runtime,
caml_wrap_exception=runtime.caml_wrap_exception;
function caml_call2(f,a0,a1)
{return f.length == 2?f(a0,a1):runtime.caml_call_gen(f,[a0,a1])}
{return (f.l >= 0?f.l:f.l = f.length) == 2
?f(a0,a1)
:runtime.caml_call_gen(f,[a0,a1])}
var
global_data=runtime.caml_get_global_data(),
Stdlib=global_data.Stdlib,
Expand Down Expand Up @@ -108,7 +110,9 @@ with Exit ->
caml_string_of_jsbytes=runtime.caml_string_of_jsbytes,
caml_wrap_exception=runtime.caml_wrap_exception;
function caml_call3(f,a0,a1,a2)
{return f.length == 3?f(a0,a1,a2):runtime.caml_call_gen(f,[a0,a1,a2])}
{return (f.l >= 0?f.l:f.l = f.length) == 3
?f(a0,a1,a2)
:runtime.caml_call_gen(f,[a0,a1,a2])}
var
global_data=runtime.caml_get_global_data(),
Stdlib=global_data.Stdlib,
Expand Down Expand Up @@ -179,7 +183,9 @@ with Exit ->
caml_string_of_jsbytes=runtime.caml_string_of_jsbytes,
caml_wrap_exception=runtime.caml_wrap_exception;
function caml_call2(f,a0,a1)
{return f.length == 2?f(a0,a1):runtime.caml_call_gen(f,[a0,a1])}
{return (f.l >= 0?f.l:f.l = f.length) == 2
?f(a0,a1)
:runtime.caml_call_gen(f,[a0,a1])}
var
global_data=runtime.caml_get_global_data(),
Stdlib=global_data.Stdlib,
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
(library
;; lib/tests/test_fun_call.ml
(name test_fun_call_75)
(enabled_if true)
(enabled_if (<> %{profile} using-effects))
(modules test_fun_call)
(libraries js_of_ocaml unix)
(inline_tests (modes js))
Expand Down
5 changes: 4 additions & 1 deletion lib/tests/gen-rules/gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ let prefix : string =

type enabled_if =
| GE5
| No_effects
| Any

let enabled_if = function
| "test_sys" -> GE5
| "test_fun_call" -> No_effects
| _ -> Any

let () =
Expand All @@ -77,5 +79,6 @@ let () =
(Hashtbl.hash prefix mod 100)
(match enabled_if basename with
| Any -> "true"
| GE5 -> "(>= %{ocaml_version} 5)")
| GE5 -> "(>= %{ocaml_version} 5)"
| No_effects -> "(<> %{profile} using-effects)")
basename)
22 changes: 11 additions & 11 deletions lib/tests/test_fun_call.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let s x =
if(x === undefined)
return "undefined"
if(typeof x === "function")
return "function#" + x.length
return "function#" + x.length + "#" + x.l
if(x.toString() == "[object Arguments]")
return "(Arguments: " + Array.prototype.slice.call(x).toString() + ")";
return x.toString()
Expand Down Expand Up @@ -96,7 +96,7 @@ let%expect_test "partial application, 0 argument call is treated like 1 argument
let%expect_test _ =
let plus = Js.wrap_callback (fun a b -> a + b) in
call_and_log plus {| (function(f){ return f(1) }) |};
[%expect {| Result: function#0 |}];
[%expect {| Result: function#0#undefined |}];
call_and_log plus {| (function(f){ return f(1)(2) }) |};
[%expect {| Result: 3 |}];
call_and_log plus {| (function(f){ return f(1,2) }) |};
Expand Down Expand Up @@ -147,7 +147,7 @@ let%expect_test "wrap_callback_strict" =
(Js.Unsafe.callback_with_arity 2 cb3)
{| (function(f){ return f(1,2,3) }) |};
[%expect {|
Result: function#0 |}];
Result: function#1#1 |}];
call_and_log
(Js.Unsafe.callback_with_arity 2 cb3)
~cont:(fun g -> g 4)
Expand All @@ -164,7 +164,7 @@ let%expect_test "wrap_callback_strict" =
Result: 0 |}];
call_and_log (Js.Unsafe.callback_with_arity 2 cb3) {| (function(f){ return f(1,2) }) |};
[%expect {|
Result: function#0 |}]
Result: function#1#1 |}]

let%expect_test "wrap_callback_strict" =
call_and_log
Expand Down Expand Up @@ -238,7 +238,7 @@ let%expect_test "partial application, 0 argument call is treated 1 argument (und
let%expect_test _ =
let plus = Js.wrap_meth_callback (fun _ a b -> a + b) in
call_and_log plus {| (function(f){ return f(1) }) |};
[%expect {| Result: function#0 |}];
[%expect {| Result: function#0#undefined |}];
call_and_log plus {| (function(f){ return f(1)(2) }) |};
[%expect {| Result: 3 |}];
call_and_log plus {| (function(f){ return f(1,2) }) |};
Expand Down Expand Up @@ -291,7 +291,7 @@ let%expect_test "wrap_meth_callback_strict" =
(Js.Unsafe.meth_callback_with_arity 2 cb4)
{| (function(f){ return f.apply("this",[1,2,3]) }) |};
[%expect {|
Result: function#0 |}];
Result: function#1#1 |}];
call_and_log
(Js.Unsafe.meth_callback_with_arity 2 cb4)
~cont:(fun g -> g 4)
Expand All @@ -309,7 +309,7 @@ let%expect_test "wrap_meth_callback_strict" =
call_and_log
(Js.Unsafe.meth_callback_with_arity 2 cb4)
{| (function(f){ return f.apply("this",[1,2]) }) |};
[%expect {| Result: function#0 |}]
[%expect {| Result: function#1#1 |}]

let%expect_test "wrap_meth_callback_strict" =
call_and_log
Expand Down Expand Up @@ -354,7 +354,7 @@ let%expect_test "partial application, extra arguments set to undefined" =
let%expect_test _ =
call_and_log cb3 ~cont:(fun g -> g 1) {| (function(f){ return f }) |};
[%expect {|
Result: function#0 |}]
Result: function#2#2 |}]

let%expect_test _ =
call_and_log cb3 ~cont:(fun g -> g 1 2 3 4) {| (function(f){ return f }) |};
Expand All @@ -369,7 +369,7 @@ let%expect_test _ =
| _ -> Printf.printf "Error: unknown"
in
f cb5;
[%expect {| Result: function#0 |}];
[%expect {| Result: function#1#1 |}];
f cb4;
[%expect {|
got 1, 1, 2, 3, done
Expand Down Expand Up @@ -399,7 +399,7 @@ let%expect_test _ =
Result: 0 |}];
f (Obj.magic cb4);
[%expect {|
Result: function#0 |}];
Result: function#1#1 |}];
f (Obj.magic cb5);
[%expect {|
Result: function#0 |}]
Result: function#2#2 |}]

0 comments on commit 3b4cf0e

Please sign in to comment.