1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980open!Importlet%expect_test_=letfx=x*2inletgx=x+3inprint_s[%sexp(f@@5:int)];[%expect{| 10 |}];print_s[%sexp(g@@f@@5:int)];[%expect{| 13 |}];print_s[%sexp(f@@g@@5:int)];[%expect{| 16 |}];;let%expect_test"exp is present at the toplevel"=print_s[%sexp(2**8:int)];[%expect{| 256 |}];;(* The goal of these tests is to check the behavior of layout-polymorphic primitives like
[ignore]. We use ppx_template as a convenient way to bind functions of different
layouts to mangled identifiers that we can access with [@kind] syntax. This prevents
some code duplication, and makes it obvious which layout(s) we're testing. *)module%test[@name"layout polymorphism"]_=[%templateinclude(structtypet=int[@@kindimmediate]andt=nativeint#[@@kindword]andt=int32#[@@kindbits32]andt=int64#[@@kindbits64]andt=float#[@@kindfloat64]let[@kindimmediate]zero()=0and[@kindword]zero()=#0nand[@kindbits32]zero()=#0land[@kindbits64]zero()=#0Land[@kindfloat64]zero()=#0.let[@kindimmediate]is_zero=function|0->true|_->falseand[@kindword]is_zero=function|#0n->true|_->falseand[@kindbits32]is_zero=function|#0l->true|_->falseand[@kindbits64]is_zero=function|#0L->true|_->falseand[@kindfloat64]is_zero=function|#0.->true|_->false;;end:sig[@@@kind.defaultk=(immediate,word,bits32,bits64,float64)]typet:kvalzero:unit->(t[@kindk])valis_zero:(t[@kindk])->boolend)[@@@kindk=(immediate,word,bits32,bits64,float64)](* Ignore a value with each of the specified layouts. *)let%test_unit"ignore"=ignore((zero[@kindk])():(t[@kindk]))(* Apply [Fn.id >> is_zero] to a value with each of the specified layouts. *)let%test"apply/revapply identity"=Fn.id@@(zero[@kindk])()|>(is_zero[@kindk])(* As above but testing %opaque rather than %identity. *)let%test"apply/revapply opaque"=Sys.opaque_identity@@(zero[@kindk])()|>(is_zero[@kindk]);;]