diff --git a/js/acutis_js.ml b/js/acutis_js.ml index 6e7377b8..27542b66 100644 --- a/js/acutis_js.ml +++ b/js/acutis_js.ml @@ -99,13 +99,10 @@ module Concurrent = struct let buffer_create () = new%js Js.array_empty - let buffer_add_string (b : buffer) s = - b##push (promise (Js.string s)) |> ignore - - let buffer_add_promise (b : buffer) p = + let buffer_append (b : buffer) p = b##push (Promise.then_ p @@ fun s -> promise (Js.string s)) |> ignore - let buffer_to_promise (b : buffer) = + let buffer_contents (b : buffer) = Promise.then_ (Promise.all b) @@ fun a -> promise (a##join (Js.string "") |> Js.to_string) end diff --git a/lib/instruct.ml b/lib/instruct.ml index 0a4ecba4..4e45885e 100644 --- a/lib/instruct.ml +++ b/lib/instruct.ml @@ -140,16 +140,14 @@ module type SEM = sig (** {1 Buffers.} *) type buffer - (** This type is not a typical "buffer" since it must work with promises. The - language may implement it however is most suitable. *) + (** A buffer of concurrent string promises. *) val buffer_create : unit -> buffer exp - val buffer_add_string : buffer exp -> string exp -> unit stmt - val buffer_add_promise : buffer exp -> string promise exp -> unit stmt + val buffer_append : buffer exp -> string promise exp -> unit stmt (** These are lambdas to minimize generated code. *) - val buffer_to_promise : (buffer -> string promise) exp + val buffer_contents : (buffer -> string promise) exp val escape : (string -> string) exp (** {1 Mutable stacks.} *) @@ -278,7 +276,7 @@ end = struct type runtime = { comps : (data hashtbl -> string promise) hashtbl exp; - buffer_to_promise : (buffer -> string promise) exp; + buffer_contents : (buffer -> string promise) exp; escape : (string -> string) exp; } @@ -289,8 +287,8 @@ end = struct let parse_escape runtime buf esc x = match esc with - | C.No_escape -> buffer_add_string buf x - | C.Escape -> buffer_add_string buf (runtime.escape @@ x) + | C.No_escape -> buffer_append buf (promise x) + | C.Escape -> buffer_append buf (promise (runtime.escape @@ x)) let fmt runtime buf esc x = function | C.Fmt_string -> parse_escape runtime buf esc (Data.to_string x) @@ -482,7 +480,7 @@ end = struct aux hd tl let rec node runtime buffer props = function - | C.Text s -> buffer_add_string buffer (string s) + | C.Text s -> buffer_append buffer (promise (string s)) | C.Echo (echs, fmt, default, esc) -> echoes runtime buffer props esc default fmt echs | C.Match (blocks, data, { tree; exits }) -> @@ -539,7 +537,7 @@ end = struct s1 |: s2)) | Component (name, _, blocks, dict) -> construct_blocks runtime buffer blocks props (fun blocks buffer -> - buffer_add_promise buffer + buffer_append buffer (runtime.comps.%{string name} @@ construct_data_hashtbl blocks props dict)) @@ -556,19 +554,17 @@ end = struct |> Seq.map (fun (i, block) -> let$ buffer = ("buffer", buffer_create ()) in let s1 = nodes runtime buffer props block in - let s2 = - blocks.%(int i) <- runtime.buffer_to_promise @@ buffer - in + let s2 = blocks.%(int i) <- runtime.buffer_contents @@ buffer in s1 |: s2) |> join_stmts in let s2 = - buffer_add_promise buffer + buffer_append buffer (bind (promise_array blocks) (lambda (fun blocks_resolved -> let$ buffer = ("buffer", buffer_create ()) in let s1 = f blocks_resolved buffer in - let s2 = return (runtime.buffer_to_promise @@ buffer) in + let s2 = return (runtime.buffer_contents @@ buffer) in s1 |: s2))) in s1 |: s2 @@ -1067,9 +1063,9 @@ end = struct compiled.C.components ([], []) in let$ escape = ("acutis_escape", escape) in - let$ buffer_to_promise = ("buffer_to_promise", buffer_to_promise) in + let$ buffer_contents = ("buffer_contents", buffer_contents) in let$ comps = ("components", hashtbl_create ()) in - let runtime = { escape; comps; buffer_to_promise } in + let runtime = { escape; comps; buffer_contents } in let s1 = List.to_seq externals |> Seq.map (fun (k, tys, v) -> @@ -1091,7 +1087,7 @@ end = struct lambda (fun props -> let$ buffer = ("buffer", buffer_create ()) in let s1 = nodes runtime buffer props v in - let s2 = return (buffer_to_promise @@ buffer) in + let s2 = return (buffer_contents @@ buffer) in s1 |: s2)) |> join_stmts in @@ -1150,7 +1146,7 @@ end = struct let s3 = let$ buffer = ("buffer", buffer_create ()) in let s1 = nodes runtime buffer props compiled.nodes in - let s2 = return (buffer_to_promise @@ buffer) in + let s2 = return (buffer_contents @@ buffer) in s1 |: s2 in s1 |: s2 |: s3)) @@ -1270,9 +1266,8 @@ module MakeTrans let bind a f = fwde (F.bind (bwde a) (bwde f)) let promise_array a = fwde (F.promise_array (bwde a)) let buffer_create () = fwde (F.buffer_create ()) - let buffer_add_string b s = fwds (F.buffer_add_string (bwde b) (bwde s)) - let buffer_add_promise b p = fwds (F.buffer_add_promise (bwde b) (bwde p)) - let buffer_to_promise = fwde F.buffer_to_promise + let buffer_append b s = fwds (F.buffer_append (bwde b) (bwde s)) + let buffer_contents = fwde F.buffer_contents let escape = fwde F.escape let stack_create () = fwde (F.stack_create ()) let stack_is_empty s = fwde (F.stack_is_empty (bwde s)) @@ -1459,9 +1454,8 @@ let pp (type a) pp_import ppf c = type buffer let buffer_create () = F.dprintf "(buffer_create)" - let buffer_add_string = F.dprintf "(@[buffer_add_string@ %t@ %t@])" - let buffer_add_promise = F.dprintf "(@[buffer_add_promise@ %t@ %t@])" - let buffer_to_promise = F.dprintf "(buffer_to_promise)" + let buffer_append = F.dprintf "(@[buffer_append@ %t@ %t@])" + let buffer_contents = F.dprintf "(buffer_contents)" let escape = F.dprintf "(escape)" type 'a stack diff --git a/lib/printJs.ml b/lib/printJs.ml index db853001..b0baa622 100644 --- a/lib/printJs.ml +++ b/lib/printJs.ml @@ -263,10 +263,9 @@ module MakeJavaScript (M : JSMODULE) : type buffer let buffer_create () = array [||] - let buffer_add_string b s = stmt (b.!("push") @@ s) - let buffer_add_promise = buffer_add_string + let buffer_append b s = stmt (b.!("push") @@ s) - let buffer_to_promise = + let buffer_contents = lambda (fun a -> return (bind (promise_array a) diff --git a/lib/render.ml b/lib/render.ml index b25eef18..2bf87d7f 100644 --- a/lib/render.ml +++ b/lib/render.ml @@ -16,9 +16,8 @@ module type CONCURRENT = sig val bind : 'a promise -> ('a -> 'b promise) -> 'b promise val promise_array : 'a promise array -> 'a array promise val buffer_create : unit -> buffer - val buffer_add_string : buffer -> string -> unit - val buffer_add_promise : buffer -> string promise -> unit - val buffer_to_promise : buffer -> string promise + val buffer_append : buffer -> string promise -> unit + val buffer_contents : buffer -> string promise end module type DECODABLE = sig @@ -315,7 +314,6 @@ module MakeString = Make (struct let bind = ( |> ) let promise_array = Fun.id let buffer_create () = Buffer.create 1024 - let buffer_add_string = Buffer.add_string - let buffer_add_promise = Buffer.add_string - let buffer_to_promise = Buffer.contents + let buffer_append = Buffer.add_string + let buffer_contents = Buffer.contents end) diff --git a/lib/render.mli b/lib/render.mli index 9e03ce7b..dd7ad3fd 100644 --- a/lib/render.mli +++ b/lib/render.mli @@ -20,9 +20,8 @@ module type CONCURRENT = sig val bind : 'a promise -> ('a -> 'b promise) -> 'b promise val promise_array : 'a promise array -> 'a array promise val buffer_create : unit -> buffer - val buffer_add_string : buffer -> string -> unit - val buffer_add_promise : buffer -> string promise -> unit - val buffer_to_promise : buffer -> string promise + val buffer_append : buffer -> string promise -> unit + val buffer_contents : buffer -> string promise end module type DECODABLE = sig diff --git a/test/parse-test.t/run.t b/test/parse-test.t/run.t index 834c9e66..8fdb54a9 100644 --- a/test/parse-test.t/run.t +++ b/test/parse-test.t/run.t @@ -876,41 +876,41 @@ Print the optimized form Print the runtime instructions $ acutis template.acutis component.acutis component2.acutis --printinst (let$ acutis_escape/0 = (escape)) - (let$ buffer_to_promise/0 = (buffer_to_promise)) + (let$ buffer_contents/0 = (buffer_contents)) (let$ components/0 = (hashtbl_create)) (unit) (components/0.%{"Component2"} <- (lambda arg/0 ((let$ buffer/0 = (buffer_create)) - (buffer_add_string buffer/0 - (acutis_escape/0 @@ (Data.to_string (arg/0.%{"children"})))) - (buffer_add_string buffer/0 "\n") - (return (buffer_to_promise/0 @@ buffer/0))))) + (buffer_append buffer/0 + (promise (acutis_escape/0 @@ (Data.to_string (arg/0.%{"children"}))))) + (buffer_append buffer/0 (promise "\n")) + (return (buffer_contents/0 @@ buffer/0))))) (components/0.%{"Component"} <- (lambda arg/1 ((let$ buffer/1 = (buffer_create)) - (buffer_add_string buffer/1 - (acutis_escape/0 @@ (Data.to_string (arg/1.%{"a_prop"})))) - (buffer_add_string buffer/1 "\n") - (buffer_add_string buffer/1 - (acutis_escape/0 @@ (Data.to_string (arg/1.%{"c_prop"})))) - (buffer_add_string buffer/1 "\n") - (buffer_add_string buffer/1 - (acutis_escape/0 @@ (Data.to_string (arg/1.%{"d_prop"})))) - (buffer_add_string buffer/1 "\n") - (buffer_add_string buffer/1 - (acutis_escape/0 @@ (Data.to_string (arg/1.%{"f_prop"})))) - (buffer_add_string buffer/1 "\n") - (buffer_add_string buffer/1 - (acutis_escape/0 @@ (Data.to_string (arg/1.%{"g_prop"})))) - (buffer_add_string buffer/1 "\n") - (buffer_add_string buffer/1 - (acutis_escape/0 @@ (Data.to_string (arg/1.%{"h_prop"})))) - (buffer_add_string buffer/1 "\n") - (buffer_add_string buffer/1 - (acutis_escape/0 @@ (Data.to_string (arg/1.%{"i_prop"})))) - (buffer_add_string buffer/1 "\n") - (return (buffer_to_promise/0 @@ buffer/1))))) + (buffer_append buffer/1 + (promise (acutis_escape/0 @@ (Data.to_string (arg/1.%{"a_prop"}))))) + (buffer_append buffer/1 (promise "\n")) + (buffer_append buffer/1 + (promise (acutis_escape/0 @@ (Data.to_string (arg/1.%{"c_prop"}))))) + (buffer_append buffer/1 (promise "\n")) + (buffer_append buffer/1 + (promise (acutis_escape/0 @@ (Data.to_string (arg/1.%{"d_prop"}))))) + (buffer_append buffer/1 (promise "\n")) + (buffer_append buffer/1 + (promise (acutis_escape/0 @@ (Data.to_string (arg/1.%{"f_prop"}))))) + (buffer_append buffer/1 (promise "\n")) + (buffer_append buffer/1 + (promise (acutis_escape/0 @@ (Data.to_string (arg/1.%{"g_prop"}))))) + (buffer_append buffer/1 (promise "\n")) + (buffer_append buffer/1 + (promise (acutis_escape/0 @@ (Data.to_string (arg/1.%{"h_prop"}))))) + (buffer_append buffer/1 (promise "\n")) + (buffer_append buffer/1 + (promise (acutis_escape/0 @@ (Data.to_string (arg/1.%{"i_prop"}))))) + (buffer_append buffer/1 (promise "\n")) + (return (buffer_contents/0 @@ buffer/1))))) (export (lambda arg/2 ((let$ stack/0 = (stack_create)) @@ -1725,37 +1725,41 @@ Print the runtime instructions @@ "{\n a: {a: {b: string}, b: {c: false | true}},\n a_prop: string,\n b_prop: string,\n c_prop: string,\n d: string,\n dict: ,\n e: string,\n e_prop: string,\n ech_a: string,\n ech_b: false | true,\n ech_d: ?string,\n ech_e: ?string,\n ech_f: float,\n ech_i: int,\n enums: (@\"a\" | ..., @1 | ..., false | true, false | true),\n f_prop: string,\n list: [?string],\n map_d: ,\n map_l: [int],\n match_a: int,\n match_b: string,\n numbers:\n {\n exp1: float,\n exp2: float,\n exp3: float,\n frac: float,\n int: int,\n negfrac: float,\n negint: int\n },\n record: {\"!#%@\": string, a: string},\n tagged: {@tag: false} | {@tag: true, a: string},\n trim_a: string,\n trim_b: string,\n trim_c: string,\n trim_d: string,\n trim_e: string,\n trim_f: string,\n trim_g: string,\n tuple: (int, float, string)\n}") @@ arg/2)))) (let$ buffer/2 = (buffer_create)) - (buffer_add_string buffer/2 "Echoes\n") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/0.%{"ech_a"})))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (Data.string "b")))) - (buffer_add_string buffer/2 " ") + (buffer_append buffer/2 (promise "Echoes\n")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/0.%{"ech_a"}))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (Data.string "b"))))) + (buffer_append buffer/2 (promise " ")) (let$ nullable/0 = (props/0.%{"ech_d"})) (if (not (Data.equal nullable/0 (Data.int 0))) (then - (buffer_add_string buffer/2 - (Data.to_string ((Data.to_array nullable/0).%(0))))) + (buffer_append buffer/2 + (promise (Data.to_string ((Data.to_array nullable/0).%(0)))))) (else (let$ nullable/1 = (props/0.%{"ech_e"})) (if (not (Data.equal nullable/1 (Data.int 0))) (then - (buffer_add_string buffer/2 - (Data.to_string ((Data.to_array nullable/1).%(0))))) + (buffer_append buffer/2 + (promise (Data.to_string ((Data.to_array nullable/1).%(0)))))) (else - (buffer_add_string buffer/2 (Data.to_string (Data.string "f\"g"))))))) - (buffer_add_string buffer/2 "\n") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (int_to_string (Data.to_int (props/0.%{"ech_i"}))))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 - @@ (float_to_string (Data.to_float (props/0.%{"ech_f"}))))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (bool_to_string (Data.to_int (props/0.%{"ech_b"}))))) - (buffer_add_string buffer/2 "\n\nNumbers\n") + (buffer_append buffer/2 + (promise (Data.to_string (Data.string "f\"g")))))))) + (buffer_append buffer/2 (promise "\n")) + (buffer_append buffer/2 + (promise + (acutis_escape/0 @@ (int_to_string (Data.to_int (props/0.%{"ech_i"})))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise + (acutis_escape/0 + @@ (float_to_string (Data.to_float (props/0.%{"ech_f"})))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise + (acutis_escape/0 @@ (bool_to_string (Data.to_int (props/0.%{"ech_b"})))))) + (buffer_append buffer/2 (promise "\n\nNumbers\n")) (let$ arg_match/0 = [(props/0.%{"numbers"})]) (let$ props/1 = (hashtbl_copy props/0 )) (let& exit/0 = -1) @@ -1784,23 +1788,23 @@ Print the runtime instructions (then (unit) (exit/0 := 0))))))))))))))) (if (equal_int (deref exit/0) -1) (then (unit) (exit/0 := 1))) (if (equal_int (deref exit/0) 0) (then (unit)) (else (unit))) - (buffer_add_string buffer/2 "\n\nTrim") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/0.%{"trim_a"})))) - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/0.%{"trim_b"})))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/0.%{"trim_c"})))) - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/0.%{"trim_d"})))) - (buffer_add_string buffer/2 (Data.to_string (props/0.%{"trim_e"}))) - (buffer_add_string buffer/2 "\n") - (buffer_add_string buffer/2 (Data.to_string (props/0.%{"trim_f"}))) - (buffer_add_string buffer/2 (Data.to_string (props/0.%{"trim_g"}))) - (buffer_add_string buffer/2 "Comments\na ") - (buffer_add_string buffer/2 "b") - (buffer_add_string buffer/2 " c\n\nFlat match\n") + (buffer_append buffer/2 (promise "\n\nTrim")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/0.%{"trim_a"}))))) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/0.%{"trim_b"}))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/0.%{"trim_c"}))))) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/0.%{"trim_d"}))))) + (buffer_append buffer/2 (promise (Data.to_string (props/0.%{"trim_e"})))) + (buffer_append buffer/2 (promise "\n")) + (buffer_append buffer/2 (promise (Data.to_string (props/0.%{"trim_f"})))) + (buffer_append buffer/2 (promise (Data.to_string (props/0.%{"trim_g"})))) + (buffer_append buffer/2 (promise "Comments\na ")) + (buffer_append buffer/2 (promise "b")) + (buffer_append buffer/2 (promise " c\n\nFlat match\n")) (let$ arg_match/1 = [(props/0.%{"match_a"})]) (let$ props/2 = (hashtbl_copy props/0 )) (let& exit/1 = -1) @@ -1818,16 +1822,16 @@ Print the runtime instructions (then (unit)) (else (if (equal_int (deref exit/1) 1) - (then (buffer_add_string buffer/2 " ")) - (else (buffer_add_string buffer/2 " "))))) - (buffer_add_string buffer/2 "\n\nNested match\n") + (then (buffer_append buffer/2 (promise " "))) + (else (buffer_append buffer/2 (promise " ")))))) + (buffer_append buffer/2 (promise "\n\nNested match\n")) (let$ arg_match/2 = [(props/0.%{"match_b"})]) (let$ props/3 = (hashtbl_copy props/0 )) (let& exit/2 = -1) (let$ match_arg/9 = (arg_match/2.%(0))) (props/3.%{"c"} <- match_arg/9) (exit/2 := 0) - (buffer_add_string buffer/2 "\n ") + (buffer_append buffer/2 (promise "\n ")) (let$ arg_match/3 = [(props/3.%{"d"}), (props/3.%{"e"})]) (let$ props/4 = (hashtbl_copy props/3 )) (let& exit/3 = -1) @@ -1836,18 +1840,18 @@ Print the runtime instructions (props/4.%{"f"} <- match_arg/10) (props/4.%{"g"} <- match_arg/11) (exit/3 := 0) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/4.%{"c"})))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/4.%{"f"})))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/4.%{"g"})))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 "\n") - (buffer_add_string buffer/2 "\n\nMap list\n") + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/4.%{"c"}))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/4.%{"f"}))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/4.%{"g"}))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 (promise "\n")) + (buffer_append buffer/2 (promise "\n\nMap list\n")) (let& index/0 = 0) (let& cell/0 = (props/0.%{"map_l"})) (while (not (Data.equal (deref cell/0) (Data.int 0))) @@ -1869,14 +1873,15 @@ Print the runtime instructions (else (if (equal_int (deref exit/4) 1) (then - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (int_to_string (Data.to_int (props/5.%{"i"}))))) - (buffer_add_string buffer/2 " ")) - (else (buffer_add_string buffer/2 " "))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise + (acutis_escape/0 @@ (int_to_string (Data.to_int (props/5.%{"i"})))))) + (buffer_append buffer/2 (promise " "))) + (else (buffer_append buffer/2 (promise " ")))))) (incr index/0) (cell/0 := (list/0.%(1))))) - (buffer_add_string buffer/2 "\n\nMap dict\n") + (buffer_append buffer/2 (promise "\n\nMap dict\n")) (let$ match_arg/12 = (props/0.%{"map_d"})) (hashtbl_iter (Data.to_hashtbl match_arg/12) key/6 value/6 (let$ props/6 = (hashtbl_copy props/0 )) (let& exit/5 = -1) @@ -1894,16 +1899,16 @@ Print the runtime instructions (else (if (equal_int (deref exit/5) 1) (then - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/6.%{"k"})))) - (buffer_add_string buffer/2 " ")) - (else (buffer_add_string buffer/2 "\n")))))) - (buffer_add_string buffer/2 "\n\nComponent with props\n") + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/6.%{"k"}))))) + (buffer_append buffer/2 (promise " "))) + (else (buffer_append buffer/2 (promise "\n"))))))) + (buffer_append buffer/2 (promise "\n\nComponent with props\n")) (let$ blocks/0 = (array_init 3 (promise ""))) (let$ buffer/3 = (buffer_create)) - (buffer_add_string buffer/3 " ") - (blocks/0.%(0) <- (buffer_to_promise/0 @@ buffer/3)) + (buffer_append buffer/3 (promise " ")) + (blocks/0.%(0) <- (buffer_contents/0 @@ buffer/3)) (let$ buffer/4 = (buffer_create)) (let$ arg_match/4 = [(props/0.%{"a_prop"})]) (let$ props/7 = (hashtbl_copy props/0 )) @@ -1911,19 +1916,19 @@ Print the runtime instructions (let$ match_arg/13 = (arg_match/4.%(0))) (props/7.%{"b_prop"} <- match_arg/13) (exit/6 := 0) - (buffer_add_string buffer/4 " ") - (buffer_add_string buffer/4 - (acutis_escape/0 @@ (Data.to_string (props/7.%{"b_prop"})))) - (buffer_add_string buffer/4 " ") - (blocks/0.%(1) <- (buffer_to_promise/0 @@ buffer/4)) + (buffer_append buffer/4 (promise " ")) + (buffer_append buffer/4 + (promise (acutis_escape/0 @@ (Data.to_string (props/7.%{"b_prop"}))))) + (buffer_append buffer/4 (promise " ")) + (blocks/0.%(1) <- (buffer_contents/0 @@ buffer/4)) (let$ buffer/5 = (buffer_create)) (unit) - (blocks/0.%(2) <- (buffer_to_promise/0 @@ buffer/5)) - (buffer_add_promise buffer/2 + (blocks/0.%(2) <- (buffer_contents/0 @@ buffer/5)) + (buffer_append buffer/2 (bind (promise_array blocks/0) (lambda arg/6 ((let$ buffer/6 = (buffer_create)) - (buffer_add_promise buffer/6 + (buffer_append buffer/6 ((components/0.%{"Component"}) @@ (hashtbl [("a_prop", (props/0.%{"b_prop"})), @@ -1933,21 +1938,21 @@ Print the runtime instructions ("g_prop", (Data.string (arg/6.%(0)))), ("h_prop", (Data.string (arg/6.%(1)))), ("i_prop", (Data.string (arg/6.%(2))))]))) - (return (buffer_to_promise/0 @@ buffer/6)))))) - (buffer_add_string buffer/2 "\n\nComponent with implicit children\n") + (return (buffer_contents/0 @@ buffer/6)))))) + (buffer_append buffer/2 (promise "\n\nComponent with implicit children\n")) (let$ blocks/1 = (array_init 1 (promise ""))) (let$ buffer/7 = (buffer_create)) - (buffer_add_string buffer/7 " ") - (blocks/1.%(0) <- (buffer_to_promise/0 @@ buffer/7)) - (buffer_add_promise buffer/2 + (buffer_append buffer/7 (promise " ")) + (blocks/1.%(0) <- (buffer_contents/0 @@ buffer/7)) + (buffer_append buffer/2 (bind (promise_array blocks/1) (lambda arg/7 ((let$ buffer/8 = (buffer_create)) - (buffer_add_promise buffer/8 + (buffer_append buffer/8 ((components/0.%{"Component2"}) @@ (hashtbl [("children", (Data.string (arg/7.%(0))))]))) - (return (buffer_to_promise/0 @@ buffer/8)))))) - (buffer_add_string buffer/2 "\n\nPatterns\n\nTuple:\n") + (return (buffer_contents/0 @@ buffer/8)))))) + (buffer_append buffer/2 (promise "\n\nPatterns\n\nTuple:\n")) (let$ arg_match/5 = [(props/0.%{"tuple"})]) (let$ props/8 = (hashtbl_copy props/0 )) (let& exit/7 = -1) @@ -1963,9 +1968,9 @@ Print the runtime instructions (then (unit) (exit/7 := 0))))))) (if (equal_int (deref exit/7) -1) (then (unit) (exit/7 := 1))) (if (equal_int (deref exit/7) 0) - (then (buffer_add_string buffer/2 " ")) - (else (buffer_add_string buffer/2 " "))) - (buffer_add_string buffer/2 "\n\nList:\n") + (then (buffer_append buffer/2 (promise " "))) + (else (buffer_append buffer/2 (promise " ")))) + (buffer_append buffer/2 (promise "\n\nList:\n")) (let$ arg_match/6 = [(props/0.%{"list"})]) (let$ props/9 = (hashtbl_copy props/0 )) (let& exit/8 = -1) @@ -2010,16 +2015,16 @@ Print the runtime instructions (props/9.%{"_z"} <- match_arg/40) (exit/8 := 2))))))) (if (equal_int (deref exit/8) 0) - (then (buffer_add_string buffer/2 "\n")) + (then (buffer_append buffer/2 (promise "\n"))) (else (if (equal_int (deref exit/8) 1) (then - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/9.%{"a"})))) - (buffer_add_string buffer/2 "\n")) - (else (buffer_add_string buffer/2 "\n"))))) - (buffer_add_string buffer/2 "\n\nRecord:\n") + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/9.%{"a"}))))) + (buffer_append buffer/2 (promise "\n"))) + (else (buffer_append buffer/2 (promise "\n")))))) + (buffer_append buffer/2 (promise "\n\nRecord:\n")) (let$ arg_match/7 = [(props/0.%{"record"})]) (let$ props/10 = (hashtbl_copy props/0 )) (let& exit/9 = -1) @@ -2032,15 +2037,15 @@ Print the runtime instructions (if (equal_int (deref exit/9) -1) (then (unit) (exit/9 := 1))) (if (equal_int (deref exit/9) 0) (then - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/10.%{"a"})))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/10.%{"b"})))) - (buffer_add_string buffer/2 " ")) - (else (buffer_add_string buffer/2 " "))) - (buffer_add_string buffer/2 "\n\nEnum:\n") + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/10.%{"a"}))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/10.%{"b"}))))) + (buffer_append buffer/2 (promise " "))) + (else (buffer_append buffer/2 (promise " ")))) + (buffer_append buffer/2 (promise "\n\nEnum:\n")) (let$ arg_match/8 = [(props/0.%{"enums"})]) (let$ props/11 = (hashtbl_copy props/0 )) (let& exit/10 = -1) @@ -2059,9 +2064,9 @@ Print the runtime instructions (then (unit) (exit/10 := 0))))))))) (if (equal_int (deref exit/10) -1) (then (unit) (exit/10 := 1))) (if (equal_int (deref exit/10) 0) - (then (buffer_add_string buffer/2 " ")) - (else (buffer_add_string buffer/2 " "))) - (buffer_add_string buffer/2 "\n\nTagged union:\n") + (then (buffer_append buffer/2 (promise " "))) + (else (buffer_append buffer/2 (promise " ")))) + (buffer_append buffer/2 (promise "\n\nTagged union:\n")) (let$ arg_match/9 = [(props/0.%{"tagged"})]) (let$ props/12 = (hashtbl_copy props/0 )) (let& exit/11 = -1) @@ -2077,12 +2082,12 @@ Print the runtime instructions (exit/11 := 0))))) (if (equal_int (deref exit/11) 0) (then - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/12.%{"a"})))) - (buffer_add_string buffer/2 " ")) - (else (buffer_add_string buffer/2 "\n"))) - (buffer_add_string buffer/2 "\n\nDictionary:\n") + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/12.%{"a"}))))) + (buffer_append buffer/2 (promise " "))) + (else (buffer_append buffer/2 (promise "\n")))) + (buffer_append buffer/2 (promise "\n\nDictionary:\n")) (let$ arg_match/10 = [(props/0.%{"dict"})]) (let$ props/13 = (hashtbl_copy props/0 )) (let& exit/12 = -1) @@ -2099,9 +2104,10 @@ Print the runtime instructions (then (unit) (exit/12 := 0))))))))) (if (equal_int (deref exit/12) -1) (then (unit) (exit/12 := 1))) (if (equal_int (deref exit/12) 0) - (then (buffer_add_string buffer/2 " ")) - (else (buffer_add_string buffer/2 " "))) - (buffer_add_string buffer/2 "\n\n! and . precedence works correctly\n") + (then (buffer_append buffer/2 (promise " "))) + (else (buffer_append buffer/2 (promise " ")))) + (buffer_append buffer/2 + (promise "\n\n! and . precedence works correctly\n")) (let$ arg_match/11 = [(Data.array [(Data.array @@ -2123,8 +2129,9 @@ Print the runtime instructions (then (unit) (exit/13 := 0))))) (if (equal_int (deref exit/13) -1) (then (unit) (exit/13 := 1))))) (if (equal_int (deref exit/13) 0) (then (unit)) (else (unit))) - (buffer_add_string buffer/2 - "\n\nOther syntax features\n\nPatterns with }} parse correctly:\n") + (buffer_append buffer/2 + (promise + "\n\nOther syntax features\n\nPatterns with }} parse correctly:\n")) (let$ arg_match/12 = [(props/0.%{"a"})]) (let$ props/15 = (hashtbl_copy props/0 )) (let& exit/14 = -1) @@ -2133,11 +2140,11 @@ Print the runtime instructions (let$ match_arg/35 = ((Data.to_hashtbl match_arg/34).%{"b"})) (props/15.%{"b"} <- match_arg/35) (exit/14 := 0) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (props/15.%{"b"})))) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 "\n\nTrailing commas parse correctly:\n") + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (props/15.%{"b"}))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 (promise "\n\nTrailing commas parse correctly:\n")) (let$ arg_match/13 = [(Data.hashtbl (hashtbl @@ -2151,9 +2158,9 @@ Print the runtime instructions (let$ match_arg/36 = (arg_match/13.%(0))) (unit) (exit/15 := 0) - (buffer_add_string buffer/2 " ") - (buffer_add_string buffer/2 "\n\nStrings may contain line breaks:\n") - (buffer_add_string buffer/2 - (acutis_escape/0 @@ (Data.to_string (Data.string "a\nb")))) - (buffer_add_string buffer/2 "\n") - (return (buffer_to_promise/0 @@ buffer/2))))) + (buffer_append buffer/2 (promise " ")) + (buffer_append buffer/2 (promise "\n\nStrings may contain line breaks:\n")) + (buffer_append buffer/2 + (promise (acutis_escape/0 @@ (Data.to_string (Data.string "a\nb"))))) + (buffer_append buffer/2 (promise "\n")) + (return (buffer_contents/0 @@ buffer/2))))) diff --git a/test/printjs/esm-cjs.t/run.t b/test/printjs/esm-cjs.t/run.t index 586836fd..c17bff13 100644 --- a/test/printjs/esm-cjs.t/run.t +++ b/test/printjs/esm-cjs.t/run.t @@ -22,7 +22,7 @@ } return (result$0); }; - let buffer_to_promise$0 = + let buffer_contents$0 = (arg$0) => { return ( Promise.all(arg$0).then((arg$1) => { return (arg$1.join("")); }) @@ -108,8 +108,8 @@ let blocks$0 = Array.from({length: 1}, (arg$1) => { return (Promise.resolve("")); }); let buffer$1 = []; - buffer$1.push(" text "); - blocks$0[0] = buffer_to_promise$0(buffer$1); + buffer$1.push(Promise.resolve(" text ")); + blocks$0[0] = buffer_contents$0(buffer$1); buffer$0.push( Promise.all(blocks$0).then( (arg$1) => { @@ -119,12 +119,12 @@ new Map([["children", arg$1[0]]]) ) ); - return (buffer_to_promise$0(buffer$2)); + return (buffer_contents$0(buffer$2)); } ) ); - buffer$0.push("\n"); - return (buffer_to_promise$0(buffer$0)); + buffer$0.push(Promise.resolve("\n")); + return (buffer_contents$0(buffer$0)); }; $ acutis \ @@ -151,7 +151,7 @@ } return (result$0); }; - let buffer_to_promise$0 = + let buffer_contents$0 = (arg$0) => { return ( Promise.all(arg$0).then((arg$1) => { return (arg$1.join("")); }) @@ -238,8 +238,8 @@ let blocks$0 = Array.from({length: 1}, (arg$1) => { return (Promise.resolve("")); }); let buffer$1 = []; - buffer$1.push(" text "); - blocks$0[0] = buffer_to_promise$0(buffer$1); + buffer$1.push(Promise.resolve(" text ")); + blocks$0[0] = buffer_contents$0(buffer$1); buffer$0.push( Promise.all(blocks$0).then( (arg$1) => { @@ -249,10 +249,10 @@ new Map([["children", arg$1[0]]]) ) ); - return (buffer_to_promise$0(buffer$2)); + return (buffer_contents$0(buffer$2)); } ) ); - buffer$0.push("\n"); - return (buffer_to_promise$0(buffer$0)); + buffer$0.push(Promise.resolve("\n")); + return (buffer_contents$0(buffer$0)); }; diff --git a/test/printjs/printjs.t/run.t b/test/printjs/printjs.t/run.t index 566759e6..d76f96ba 100644 --- a/test/printjs/printjs.t/run.t +++ b/test/printjs/printjs.t/run.t @@ -29,7 +29,7 @@ } return (result$0); }; - let buffer_to_promise$0 = + let buffer_contents$0 = (arg$0) => { return ( Promise.all(arg$0).then((arg$1) => { return (arg$1.join("")); }) @@ -263,11 +263,13 @@ let buffer$0 = []; let nullable$0 = arg$0.get("optional"); if (!(nullable$0 === 0)) { - buffer$0.push(acutis_escape$0(nullable$0[0].toString())); + buffer$0.push( + Promise.resolve(acutis_escape$0(nullable$0[0].toString())) + ); } else { - buffer$0.push(acutis_escape$0(arg$0.get("children"))); + buffer$0.push(Promise.resolve(acutis_escape$0(arg$0.get("children")))); } - buffer$0.push("\n"); + buffer$0.push(Promise.resolve("\n")); let index$0 = 0; let cell$0 = arg$0.get("list"); while (!(cell$0 === 0)) { @@ -276,11 +278,13 @@ let exit$0 = -1; props$0.set("i", head$0); exit$0 = 0; - buffer$0.push(acutis_escape$0(props$0.get("i").toString())); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$0.get("i").toString())) + ); index$0++; cell$0 = cell$0[1]; } - return (buffer_to_promise$0(buffer$0)); + return (buffer_contents$0(buffer$0)); } ); export default (arg$0) => { @@ -1329,41 +1333,55 @@ ); } let buffer$0 = []; - buffer$0.push("Formatters\n----------\n\n%i "); - buffer$0.push(acutis_escape$0(props$0.get("big_int").toString())); - buffer$0.push("\n%f "); - buffer$0.push(acutis_escape$0(props$0.get("big_float").toString())); - buffer$0.push("\n%b "); - buffer$0.push(acutis_escape$0(props$0.get("bool1") ? "true" : "false")); - buffer$0.push("\n%b "); - buffer$0.push(acutis_escape$0(props$0.get("bool2") ? "true" : "false")); - buffer$0.push("\n\nEscaping\n--------\n\nEscaped "); - buffer$0.push(acutis_escape$0(props$0.get("dangerous"))); - buffer$0.push("\nNot escaped "); - buffer$0.push(props$0.get("dangerous")); - buffer$0.push("\n\nNullable echo chaining\n----------------------\n\n"); + buffer$0.push(Promise.resolve("Formatters\n----------\n\n%i ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$0.get("big_int").toString())) + ); + buffer$0.push(Promise.resolve("\n%f ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$0.get("big_float").toString())) + ); + buffer$0.push(Promise.resolve("\n%b ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$0.get("bool1") ? "true" : "false")) + ); + buffer$0.push(Promise.resolve("\n%b ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$0.get("bool2") ? "true" : "false")) + ); + buffer$0.push(Promise.resolve("\n\nEscaping\n--------\n\nEscaped ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$0.get("dangerous")))); + buffer$0.push(Promise.resolve("\nNot escaped ")); + buffer$0.push(Promise.resolve(props$0.get("dangerous"))); + buffer$0.push( + Promise.resolve("\n\nNullable echo chaining\n----------------------\n\n") + ); let nullable$0 = props$0.get("null_int"); if (!(nullable$0 === 0)) { - buffer$0.push(acutis_escape$0(nullable$0[0].toString())); + buffer$0.push(Promise.resolve(acutis_escape$0(nullable$0[0].toString()))); } else { let nullable$1 = props$0.get("null_float"); if (!(nullable$1 === 0)) { - buffer$0.push(acutis_escape$0(nullable$1[0].toString())); + buffer$0.push( + Promise.resolve(acutis_escape$0(nullable$1[0].toString())) + ); } else { let nullable$2 = props$0.get("null_bool"); if (!(nullable$2 === 0)) { - buffer$0.push(acutis_escape$0(nullable$2[0] ? "true" : "false")); + buffer$0.push( + Promise.resolve(acutis_escape$0(nullable$2[0] ? "true" : "false")) + ); } else { let nullable$3 = props$0.get("null_string"); if (!(nullable$3 === 0)) { - buffer$0.push(acutis_escape$0(nullable$3[0])); + buffer$0.push(Promise.resolve(acutis_escape$0(nullable$3[0]))); } else { - buffer$0.push(acutis_escape$0("pass")); + buffer$0.push(Promise.resolve(acutis_escape$0("pass"))); } } } } - buffer$0.push("\n\nMatching\n--------\n\n"); + buffer$0.push(Promise.resolve("\n\nMatching\n--------\n\n")); let arg_match$0 = [props$0.get("record").get("int_enum")]; let props$1 = new Map(props$0); let exit$0 = -1; @@ -1373,7 +1391,11 @@ } else { if (match_arg$0 === 40) { exit$0 = 1; } } - if (exit$0 === 0) { buffer$0.push("8\n"); } else { buffer$0.push("40\n"); } + if (exit$0 === 0) { + buffer$0.push(Promise.resolve("8\n")); + } else { + buffer$0.push(Promise.resolve("40\n")); + } let arg_match$1 = [props$0.get("record")]; let props$2 = new Map(props$0); let exit$1 = -1; @@ -1385,9 +1407,9 @@ if (match_arg$2 === "yes") { exit$1 = 0; } } if (exit$1 === 0) { - buffer$0.push("yes\n"); + buffer$0.push(Promise.resolve("yes\n")); } else { - buffer$0.push("no\n"); + buffer$0.push(Promise.resolve("no\n")); } let arg_match$2 = [props$0.get("tagged_record_bool")]; let props$3 = new Map(props$0); @@ -1406,11 +1428,13 @@ } } if (exit$2 === 0) { - buffer$0.push(acutis_escape$0(props$3.get("a"))); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(acutis_escape$0(props$3.get("a")))); + buffer$0.push(Promise.resolve("\n")); } else { - buffer$0.push(acutis_escape$0(props$3.get("b").toString())); - buffer$0.push("\n"); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$3.get("b").toString())) + ); + buffer$0.push(Promise.resolve("\n")); } let arg_match$3 = [props$0.get("tagged_record_int")]; let props$4 = new Map(props$0); @@ -1432,14 +1456,18 @@ } } if (exit$3 === 0) { - buffer$0.push("Fail\n"); + buffer$0.push(Promise.resolve("Fail\n")); } else { - buffer$0.push(acutis_escape$0(props$4.get("a").toString())); - buffer$0.push(" "); - buffer$0.push(acutis_escape$0(props$4.get("b"))); - buffer$0.push(" "); - buffer$0.push(acutis_escape$0(props$4.get("c") ? "true" : "false")); - buffer$0.push("\n"); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$4.get("a").toString())) + ); + buffer$0.push(Promise.resolve(" ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$4.get("b")))); + buffer$0.push(Promise.resolve(" ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$4.get("c") ? "true" : "false")) + ); + buffer$0.push(Promise.resolve("\n")); } let arg_match$4 = [props$0.get("tagged_record_open")]; let props$5 = new Map(props$0); @@ -1453,13 +1481,13 @@ } if (exit$4 === -1) { exit$4 = 1; } if (exit$4 === 0) { - buffer$0.push(" "); - buffer$0.push(acutis_escape$0(props$5.get("b"))); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(" ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$5.get("b")))); + buffer$0.push(Promise.resolve("\n")); } else { - buffer$0.push("Another tag!\n"); + buffer$0.push(Promise.resolve("Another tag!\n")); } - buffer$0.push("\n\nMapping\n-------\n\n"); + buffer$0.push(Promise.resolve("\n\nMapping\n-------\n\n")); let match_arg$9 = props$0.get("null_string_dict"); for (let x$0 of match_arg$9) { let props$6 = new Map(props$0); @@ -1474,13 +1502,13 @@ exit$5 = 1; } if (exit$5 === 0) { - buffer$0.push(acutis_escape$0(props$6.get("key"))); - buffer$0.push(" is null.\n"); + buffer$0.push(Promise.resolve(acutis_escape$0(props$6.get("key")))); + buffer$0.push(Promise.resolve(" is null.\n")); } else { - buffer$0.push(acutis_escape$0(props$6.get("key"))); - buffer$0.push(" is "); - buffer$0.push(acutis_escape$0(props$6.get("str"))); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(acutis_escape$0(props$6.get("key")))); + buffer$0.push(Promise.resolve(" is ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$6.get("str")))); + buffer$0.push(Promise.resolve("\n")); } } let index$0 = 0; @@ -1491,8 +1519,10 @@ let exit$5 = -1; props$6.set("i", head$0); exit$5 = 0; - buffer$0.push(acutis_escape$0(props$6.get("i").toString())); - buffer$0.push("\n"); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$6.get("i").toString())) + ); + buffer$0.push(Promise.resolve("\n")); index$0++; cell$0 = cell$0[1]; } @@ -1505,10 +1535,14 @@ props$6.set("i", head$0); props$6.set("key", index$1); exit$5 = 0; - buffer$0.push(acutis_escape$0(props$6.get("key").toString())); - buffer$0.push(" : "); - buffer$0.push(acutis_escape$0(props$6.get("i").toString())); - buffer$0.push("\n"); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$6.get("key").toString())) + ); + buffer$0.push(Promise.resolve(" : ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$6.get("i").toString())) + ); + buffer$0.push(Promise.resolve("\n")); index$1++; cell$1 = cell$1[1]; } @@ -1536,8 +1570,10 @@ let exit$7 = -1; props$8.set("i", head$2); exit$7 = 0; - buffer$0.push(acutis_escape$0(props$8.get("i").toString())); - buffer$0.push(" "); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$8.get("i").toString())) + ); + buffer$0.push(Promise.resolve(" ")); index$4++; cell$4 = cell$4[1]; } @@ -1547,7 +1583,7 @@ index$2++; cell$2 = cell$2[1]; } - buffer$0.push("\n\n"); + buffer$0.push(Promise.resolve("\n\n")); let index$3 = 0; let cell$3 = props$0.get("nested_nullable_list"); while (!(cell$3 === 0)) { @@ -1568,26 +1604,34 @@ } } if (exit$5 === 0) { - buffer$0.push("Level 1 null\n"); + buffer$0.push(Promise.resolve("Level 1 null\n")); } else { if (exit$5 === 1) { - buffer$0.push("Level 2 null (This shouldn't render.)\n"); + buffer$0.push( + Promise.resolve("Level 2 null (This shouldn't render.)\n") + ); } else { - buffer$0.push("Level 3 "); - buffer$0.push(acutis_escape$0(props$6.get("b") ? "true" : "false")); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve("Level 3 ")); + buffer$0.push( + Promise.resolve( + acutis_escape$0(props$6.get("b") ? "true" : "false") + ) + ); + buffer$0.push(Promise.resolve("\n")); } } index$3++; cell$3 = cell$3[1]; } buffer$0.push( - "\n\ + Promise.resolve( + "\n\ \n\ Dictionaries match correctly\n\ ----------------------------\n\ \n\ " + ) ); let arg_match$5 = [props$0.get("null_string_dict")]; let props$6 = new Map(props$0); @@ -1635,19 +1679,19 @@ } if (exit$5 === -1) { exit$5 = 3; } if (exit$5 === 0) { - buffer$0.push(" "); - buffer$0.push(acutis_escape$0(props$6.get("a"))); - buffer$0.push(" "); - buffer$0.push(acutis_escape$0(props$6.get("b"))); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(" ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$6.get("a")))); + buffer$0.push(Promise.resolve(" ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$6.get("b")))); + buffer$0.push(Promise.resolve("\n")); } else { if (exit$5 === 1) { - buffer$0.push(" Fail.\n"); + buffer$0.push(Promise.resolve(" Fail.\n")); } else { if (exit$5 === 2) { - buffer$0.push(" Pass.\n"); + buffer$0.push(Promise.resolve(" Pass.\n")); } else { - buffer$0.push(" Fail.\n"); + buffer$0.push(Promise.resolve(" Fail.\n")); } } } @@ -1686,39 +1730,41 @@ } if (exit$6 === -1) { exit$6 = 3; } if (exit$6 === 0) { - buffer$0.push(" Fail. "); - buffer$0.push(acutis_escape$0(props$7.get("a"))); - buffer$0.push(" "); - buffer$0.push(acutis_escape$0(props$7.get("b"))); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(" Fail. ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$7.get("a")))); + buffer$0.push(Promise.resolve(" ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$7.get("b")))); + buffer$0.push(Promise.resolve("\n")); } else { if (exit$6 === 1) { - buffer$0.push(" Fail.\n"); + buffer$0.push(Promise.resolve(" Fail.\n")); } else { if (exit$6 === 2) { - buffer$0.push(" Pass.\n"); + buffer$0.push(Promise.resolve(" Pass.\n")); } else { - buffer$0.push(" Fail.\n"); + buffer$0.push(Promise.resolve(" Fail.\n")); } } } buffer$0.push( - "\n\nConstructing async blocks\n-------------------------\n\n" + Promise.resolve( + "\n\nConstructing async blocks\n-------------------------\n\n" + ) ); let blocks$0 = Array.from({length: 2}, (arg$1) => { return (Promise.resolve("")); }); let buffer$1 = []; - buffer$1.push(" Nested block "); + buffer$1.push(Promise.resolve(" Nested block ")); let nullable$1 = props$0.get("null_string"); if (!(nullable$1 === 0)) { - buffer$1.push(acutis_escape$0(nullable$1[0])); + buffer$1.push(Promise.resolve(acutis_escape$0(nullable$1[0]))); } else { - buffer$1.push(acutis_escape$0("pass")); + buffer$1.push(Promise.resolve(acutis_escape$0("pass"))); } - blocks$0[0] = buffer_to_promise$0(buffer$1); + blocks$0[0] = buffer_contents$0(buffer$1); let buffer$2 = []; - buffer$2.push(" Another nested block"); - blocks$0[1] = buffer_to_promise$0(buffer$2); + buffer$2.push(Promise.resolve(" Another nested block")); + blocks$0[1] = buffer_contents$0(buffer$2); buffer$0.push( Promise.all(blocks$0).then( (arg$1) => { @@ -1732,20 +1778,20 @@ props$8.set("a", match_arg$13); props$8.set("b", match_arg$14); exit$7 = 0; - buffer$3.push(acutis_escape$0(props$8.get("a"))); - buffer$3.push(" "); - buffer$3.push(acutis_escape$0(props$8.get("b"))); - buffer$3.push("\n"); - return (buffer_to_promise$0(buffer$3)); + buffer$3.push(Promise.resolve(acutis_escape$0(props$8.get("a")))); + buffer$3.push(Promise.resolve(" ")); + buffer$3.push(Promise.resolve(acutis_escape$0(props$8.get("b")))); + buffer$3.push(Promise.resolve("\n")); + return (buffer_contents$0(buffer$3)); } ) ); - buffer$0.push("Component\n---------\n\n"); + buffer$0.push(Promise.resolve("Component\n---------\n\n")); let blocks$1 = Array.from({length: 1}, (arg$1) => { return (Promise.resolve("")); }); let buffer$3 = []; - buffer$3.push("Children prop"); - blocks$1[0] = buffer_to_promise$0(buffer$3); + buffer$3.push(Promise.resolve("Children prop")); + blocks$1[0] = buffer_contents$0(buffer$3); buffer$0.push( Promise.all(blocks$1).then( (arg$1) => { @@ -1761,19 +1807,21 @@ ) ) ); - return (buffer_to_promise$0(buffer$4)); + return (buffer_contents$0(buffer$4)); } ) ); - buffer$0.push("\n\n"); + buffer$0.push(Promise.resolve("\n\n")); buffer$0.push(components$0.get("Another_function")(new Map([]))); buffer$0.push( - "\n\ + Promise.resolve( + "\n\ \n\ Complicated pattern matching\n\ ----------------------------\n\ \n\ " + ) ); let arg_match$7 = [1, 0, 3]; let props$8 = new Map(props$0); @@ -1827,22 +1875,26 @@ } } if (exit$7 === 0) { - buffer$0.push(" 0\n"); + buffer$0.push(Promise.resolve(" 0\n")); } else { if (exit$7 === 1) { - buffer$0.push(" 1 "); - buffer$0.push(acutis_escape$0(props$8.get("x").toString())); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(" 1 ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$8.get("x").toString())) + ); + buffer$0.push(Promise.resolve("\n")); } else { if (exit$7 === 2) { - buffer$0.push(" 2 "); - buffer$0.push(acutis_escape$0(props$8.get("y").toString())); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(" 2 ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$8.get("y").toString())) + ); + buffer$0.push(Promise.resolve("\n")); } else { if (exit$7 === 3) { - buffer$0.push(" 3\n"); + buffer$0.push(Promise.resolve(" 3\n")); } else { - buffer$0.push(" 4\n"); + buffer$0.push(Promise.resolve(" 4\n")); } } } @@ -1886,14 +1938,16 @@ } } if (exit$8 === 0) { - buffer$0.push("\n"); + buffer$0.push(Promise.resolve("\n")); } else { if (exit$8 === 1) { - buffer$0.push(" Pass\n"); + buffer$0.push(Promise.resolve(" Pass\n")); } else { - buffer$0.push(" "); - buffer$0.push(acutis_escape$0(props$9.get("z").toString())); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(" ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$9.get("z").toString())) + ); + buffer$0.push(Promise.resolve("\n")); } } let arg_match$9 = [[[10, 20], 99], 40]; @@ -1935,32 +1989,40 @@ } } if (exit$9 === 0) { - buffer$0.push("\n"); + buffer$0.push(Promise.resolve("\n")); } else { if (exit$9 === 1) { - buffer$0.push(" Fail\n"); + buffer$0.push(Promise.resolve(" Fail\n")); } else { - buffer$0.push(" "); - buffer$0.push(acutis_escape$0(props$10.get("z").toString())); - buffer$0.push("\n"); + buffer$0.push(Promise.resolve(" ")); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$10.get("z").toString())) + ); + buffer$0.push(Promise.resolve("\n")); } } buffer$0.push( - "String encoding\n\ + Promise.resolve( + "String encoding\n\ ---------------\n\ \n\ 😇👨‍💻😇\n\ \\\" \\ \\ \\\"\n\ \n\ " + ) + ); + buffer$0.push( + Promise.resolve(acutis_escape$0(props$0.get("unicode_string"))) ); - buffer$0.push(acutis_escape$0(props$0.get("unicode_string"))); buffer$0.push( - "\n\ + Promise.resolve( + "\n\ \n\ External JavaScript template component: stringify arbitrary data\n\ \n\ " + ) ); buffer$0.push( components$0.get("Stringify")( @@ -1980,8 +2042,8 @@ ) ) ); - buffer$0.push("\n"); - return (buffer_to_promise$0(buffer$0)); + buffer$0.push(Promise.resolve("\n")); + return (buffer_contents$0(buffer$0)); }; $ cat > run.mjs << EOF diff --git a/test/printjs/printjs_example.compiled.mjs b/test/printjs/printjs_example.compiled.mjs index 1ebb29ad..26160156 100644 --- a/test/printjs/printjs_example.compiled.mjs +++ b/test/printjs/printjs_example.compiled.mjs @@ -18,7 +18,7 @@ let acutis_escape$0 = } return (result$0); }; -let buffer_to_promise$0 = +let buffer_contents$0 = (arg$0) => { return ( Promise.all(arg$0).then((arg$1) => { return (arg$1.join("")); }) @@ -360,9 +360,9 @@ The data supplied does not match this template's interface.\n\ ); } let buffer$0 = []; - buffer$0.push("

Blog posts for "); - buffer$0.push(acutis_escape$0(props$0.get("siteTitle"))); - buffer$0.push("

"); + buffer$0.push(Promise.resolve("

Blog posts for ")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$0.get("siteTitle")))); + buffer$0.push(Promise.resolve("

")); let index$0 = 0; let cell$0 = props$0.get("blogPosts"); while (!(cell$0 === 0)) { @@ -381,7 +381,11 @@ The data supplied does not match this template's interface.\n\ props$1.set("name", match_arg$1); props$1.set("title", match_arg$5); exit$0 = 0; - buffer$0.push("\n
\n
\n "); + buffer$0.push( + Promise.resolve( + "\n
\n
\n " + ) + ); let arg_match$0 = [props$1.get("image")]; let props$2 = new Map(props$1); let exit$1 = -1; @@ -398,29 +402,39 @@ The data supplied does not match this template's interface.\n\ exit$1 = 1; } if (!(exit$1 === 0)) { - buffer$0.push("\"");\n "); + buffer$0.push(Promise.resolve("\""));\n ")); } - buffer$0.push("

"); - buffer$0.push(acutis_escape$0(props$1.get("title"))); - buffer$0.push("

\n By "); + buffer$0.push(Promise.resolve("

")); + buffer$0.push(Promise.resolve(acutis_escape$0(props$1.get("title")))); + buffer$0.push( + Promise.resolve("

\n By ") + ); let nullable$0 = props$1.get("name"); if (!(nullable$0 === 0)) { - buffer$0.push(acutis_escape$0(nullable$0[0])); + buffer$0.push(Promise.resolve(acutis_escape$0(nullable$0[0]))); } else { - buffer$0.push(acutis_escape$0("Anonymous")); + buffer$0.push(Promise.resolve(acutis_escape$0("Anonymous"))); } - buffer$0.push(" \n Posted on "); - buffer$0.push(acutis_escape$0(props$1.get("date"))); - buffer$0.push(" \n
\n
"); - buffer$0.push(props$1.get("content")); - buffer$0.push("
\n
\n"); + buffer$0.push( + Promise.resolve( + " \n Posted on " + ) + ); + buffer$0.push(Promise.resolve(acutis_escape$0(props$1.get("date")))); + buffer$0.push( + Promise.resolve( + " \n
\n
" + ) + ); + buffer$0.push(Promise.resolve(props$1.get("content"))); + buffer$0.push(Promise.resolve("
\n
\n")); index$0++; cell$0 = cell$0[1]; } - buffer$0.push("\n"); - return (buffer_to_promise$0(buffer$0)); + buffer$0.push(Promise.resolve("\n")); + return (buffer_contents$0(buffer$0)); }; \ No newline at end of file