Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / examples / ffi / test_quot.sml
CommitLineData
7f918cf1
CE
1(* By default _import is external *)
2val c_quot = _import "c_quot" private pure: Int8.int * Int8.int -> Int8.int;
3
4(* By default _export is public *)
5val sml_quot = _export "sml_quot": (Int8.int * Int8.int -> Int8.int) -> unit;
6val _ = sml_quot Int8.quot
7
8val call_sml_quot = _import "call_sml_quot" public reentrant: unit -> unit;
9
10val x : Int8.int = ~1
11val y : Int8.int = 10
12
13val z = Int8.quot (x, y)
14val c_z = c_quot (x, y)
15
16val bad_z =
17 let
18 val x : Int8.int = ~1
19 val x : Word8.word = 0wxFF
20 val x : Int32.int = Word8.toInt x
21 val y : Int8.int = 10
22 val y : Word8.word = 0wx0A
23 val y : Int32.int = Word8.toInt y
24 val z : Int32.int = Int32.quot (x, y)
25 val z = Int8.fromInt z
26 in
27 z
28 end
29
30val () =
31 print (concat [" bad_z = ", Int8.toString bad_z, "\n",
32 " z = ", Int8.toString z, "\n",
33 " c_z = ", Int8.toString c_z, "\n"])
34val () = call_sml_quot ()