diff --git a/src/compile.ml b/src/compile.ml index 424ef471d42..3f3f6bb72e1 100644 --- a/src/compile.ml +++ b/src/compile.ml @@ -2365,7 +2365,8 @@ module Dfinity = struct let compile_static_print env s = compile_databuf_of_bytes env s ^^ G.i (Call (nr (E.built_in env "test_print"))) - let _compile_print_int env = + + let _compile_println_int env = G.i (Call (nr (E.built_in env "test_show_i32"))) ^^ G.i (Call (nr (E.built_in env "test_print"))) ^^ compile_static_print env "\n" @@ -2375,16 +2376,6 @@ module Dfinity = struct then compile_static_print env (s ^ "\n") ^^ G.i Unreachable else G.i Unreachable - let prim_printInt env = - if E.mode env = DfinityMode - then - BoxedInt.unbox env ^^ - G.i (Convert (Wasm.Values.I32 I32Op.WrapI64)) ^^ - G.i (Call (nr (E.built_in env "test_show_i32"))) ^^ - G.i (Call (nr (E.built_in env "test_print"))) - else - G.i Unreachable - let prim_print env = if E.mode env = DfinityMode then @@ -4276,10 +4267,6 @@ and compile_exp (env : E.t) exp = compile_exp_vanilla env e ^^ Text.prim_showChar env - | "printInt" -> - SR.unit, - compile_exp_vanilla env e ^^ - Dfinity.prim_printInt env | "print" -> SR.unit, compile_exp_vanilla env e ^^ diff --git a/src/prelude.ml b/src/prelude.ml index c49f55e42fa..444daaf0447 100644 --- a/src/prelude.ml +++ b/src/prelude.ml @@ -33,7 +33,7 @@ class revrange(x : Nat, y : Nat) { func charToText(c : Char) : Text = (prim "Char->Text" : Char -> Text) c; -func printInt(x : Int) { (prim "printInt" : Int -> ()) x }; +func printInt(x : Int) { print (@text_of_Int x) }; func printChar(x : Char) { print (charToText x) }; func print(x : Text) { (prim "print" : Text -> ()) x }; @@ -92,7 +92,7 @@ func btstWord64(w : Word64, amount : Word64) : Bool = (prim "btst64" : (Word64, // Internal helper functions for the show translation -// The @ in the name ensures that this connot be shadowed by user code, so +// The @ in the name ensures that this cannot be shadowed by user code, so // compiler passes can rely on them being in scope // The text_of functions do not need to be exposed; the user can just use // the show above. @@ -101,22 +101,11 @@ func @text_of_Nat(x : Nat) : Text { var text = ""; var n = x; let base = 10; + let digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; while (n > 0) { let rem = n % base; - text := (switch (rem) { - case (0) { "0" }; - case (1) { "1" }; - case (2) { "2" }; - case (3) { "3" }; - case (4) { "4" }; - case (5) { "5" }; - case (6) { "6" }; - case (7) { "7" }; - case (8) { "8" }; - case (9) { "9" }; - case (_) { assert false; "" }; - }) # text; + text := digits[rem] # text; n := n / base; }; return text; @@ -350,7 +339,6 @@ let prim = function | code -> Wasm.Utf8.encode [code] in k (Text str) | "print" -> fun v k -> Printf.printf "%s%!" (as_text v); k unit - | "printInt" -> fun v k -> Printf.printf "%d%!" (Int.to_int (as_int v)); k unit | "decodeUTF8" -> fun v k -> let s = as_text v in let open Int32 in diff --git a/src/show.ml b/src/show.ml index a0bc166f738..12d78a413dd 100644 --- a/src/show.ml +++ b/src/show.ml @@ -19,7 +19,7 @@ We can use string_of_typ here for now, it seems. let typ_id : T.typ -> string = T.string_of_typ -(* Environmemt *) +(* Environment *) (* We go through the file and collect all type arguments to `show`. We store them in `params`, indexed by their `type_id` @@ -41,7 +41,7 @@ let add_type env t : unit = (* For a concrete type `t` we want to create a function name for `show`. This name needs to be disjoint from all user-generated names. - Luckily, we are not limited in the characters to use at this point: + Luckily, we are not limited in the characters to use at this point. *) let show_name_for t = @@ -346,7 +346,7 @@ let show_for : T.typ -> Ir.dec * T.typ list = fun t -> (List.map (fun (l, t') -> let t' = T.normalize t' in l @@ no_region, - (varP (argE t')), (* Shadowing, but thats fine *) + (varP (argE t')), (* Shadowing, but that's fine *) (invoke_text_of_variant t' (show_var_for t') l (argE t')) ) cts) (T.Prim T.Text) diff --git a/test/fail/ok/ast81-clash.run-ir.ok b/test/fail/ok/ast81-clash.run-ir.ok index ba6826e051b..a44cd01d45f 100644 --- a/test/fail/ok/ast81-clash.run-ir.ok +++ b/test/fail/ok/ast81-clash.run-ir.ok @@ -1,4 +1,4 @@ -prelude:200.1-225.2: internal error, Env.Make(X).Clash("x") +prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") Last environment: @new_async = func diff --git a/test/fail/ok/ast81-clash.run-low.ok b/test/fail/ok/ast81-clash.run-low.ok index ba6826e051b..a44cd01d45f 100644 --- a/test/fail/ok/ast81-clash.run-low.ok +++ b/test/fail/ok/ast81-clash.run-low.ok @@ -1,4 +1,4 @@ -prelude:200.1-225.2: internal error, Env.Make(X).Clash("x") +prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") Last environment: @new_async = func diff --git a/test/fail/ok/ast81-clash.run.ok b/test/fail/ok/ast81-clash.run.ok index ba6826e051b..a44cd01d45f 100644 --- a/test/fail/ok/ast81-clash.run.ok +++ b/test/fail/ok/ast81-clash.run.ok @@ -1,4 +1,4 @@ -prelude:200.1-225.2: internal error, Env.Make(X).Clash("x") +prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") Last environment: @new_async = func diff --git a/test/fail/ok/ast81-clash.tc.ok b/test/fail/ok/ast81-clash.tc.ok index ba6826e051b..a44cd01d45f 100644 --- a/test/fail/ok/ast81-clash.tc.ok +++ b/test/fail/ok/ast81-clash.tc.ok @@ -1,4 +1,4 @@ -prelude:200.1-225.2: internal error, Env.Make(X).Clash("x") +prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") Last environment: @new_async = func diff --git a/test/fail/ok/ast81-clash.wasm.stderr.ok b/test/fail/ok/ast81-clash.wasm.stderr.ok index ba6826e051b..a44cd01d45f 100644 --- a/test/fail/ok/ast81-clash.wasm.stderr.ok +++ b/test/fail/ok/ast81-clash.wasm.stderr.ok @@ -1,4 +1,4 @@ -prelude:200.1-225.2: internal error, Env.Make(X).Clash("x") +prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") Last environment: @new_async = func diff --git a/test/run-dfinity/ok/data-params.dvm-run.ok b/test/run-dfinity/ok/data-params.dvm-run.ok index 39f0db3e291..c1ac61e2e3c 100644 --- a/test/run-dfinity/ok/data-params.dvm-run.ok +++ b/test/run-dfinity/ok/data-params.dvm-run.ok @@ -16,7 +16,7 @@ 1006211 Foo1: 1006211 Foo2: 1006211 -1317141123 +10000001006211 1 3 6