Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions src/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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 ^^
Expand Down
20 changes: 4 additions & 16 deletions src/prelude.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/show.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/fail/ok/ast81-clash.run-ir.ok
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fail/ok/ast81-clash.run-low.ok
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fail/ok/ast81-clash.run.ok
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fail/ok/ast81-clash.tc.ok
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fail/ok/ast81-clash.wasm.stderr.ok
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/run-dfinity/ok/data-params.dvm-run.ok
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
1006211
Foo1: 1006211
Foo2: 1006211
1317141123
10000001006211
1
3
6
Expand Down