@@ -140,16 +140,14 @@ module type SEM = sig
140
140
(* * {1 Buffers.} *)
141
141
142
142
type buffer
143
- (* * This type is not a typical "buffer" since it must work with promises. The
144
- language may implement it however is most suitable. *)
143
+ (* * A buffer of concurrent string promises. *)
145
144
146
145
val buffer_create : unit -> buffer exp
147
- val buffer_add_string : buffer exp -> string exp -> unit stmt
148
- val buffer_add_promise : buffer exp -> string promise exp -> unit stmt
146
+ val buffer_append : buffer exp -> string promise exp -> unit stmt
149
147
150
148
(* * These are lambdas to minimize generated code. *)
151
149
152
- val buffer_to_promise : (buffer -> string promise ) exp
150
+ val buffer_contents : (buffer -> string promise ) exp
153
151
val escape : (string -> string ) exp
154
152
155
153
(* * {1 Mutable stacks.} *)
@@ -278,7 +276,7 @@ end = struct
278
276
279
277
type runtime = {
280
278
comps : (data hashtbl -> string promise ) hashtbl exp ;
281
- buffer_to_promise : (buffer -> string promise ) exp ;
279
+ buffer_contents : (buffer -> string promise ) exp ;
282
280
escape : (string -> string ) exp ;
283
281
}
284
282
@@ -289,8 +287,8 @@ end = struct
289
287
290
288
let parse_escape runtime buf esc x =
291
289
match esc with
292
- | C. No_escape -> buffer_add_string buf x
293
- | C. Escape -> buffer_add_string buf (runtime.escape @@ x)
290
+ | C. No_escape -> buffer_append buf (promise x)
291
+ | C. Escape -> buffer_append buf (promise ( runtime.escape @@ x) )
294
292
295
293
let fmt runtime buf esc x = function
296
294
| C. Fmt_string -> parse_escape runtime buf esc (Data. to_string x)
@@ -482,7 +480,7 @@ end = struct
482
480
aux hd tl
483
481
484
482
let rec node runtime buffer props = function
485
- | C. Text s -> buffer_add_string buffer (string s)
483
+ | C. Text s -> buffer_append buffer (promise ( string s) )
486
484
| C. Echo (echs , fmt , default , esc ) ->
487
485
echoes runtime buffer props esc default fmt echs
488
486
| C. Match (blocks , data , { tree; exits } ) ->
@@ -539,7 +537,7 @@ end = struct
539
537
s1 |: s2))
540
538
| Component (name , _ , blocks , dict ) ->
541
539
construct_blocks runtime buffer blocks props (fun blocks buffer ->
542
- buffer_add_promise buffer
540
+ buffer_append buffer
543
541
(runtime.comps.% {string name}
544
542
@@ construct_data_hashtbl blocks props dict))
545
543
@@ -556,19 +554,17 @@ end = struct
556
554
|> Seq. map (fun (i , block ) ->
557
555
let $ buffer = (" buffer" , buffer_create () ) in
558
556
let s1 = nodes runtime buffer props block in
559
- let s2 =
560
- blocks.% (int i) < - runtime.buffer_to_promise @@ buffer
561
- in
557
+ let s2 = blocks.% (int i) < - runtime.buffer_contents @@ buffer in
562
558
s1 |: s2)
563
559
|> join_stmts
564
560
in
565
561
let s2 =
566
- buffer_add_promise buffer
562
+ buffer_append buffer
567
563
(bind (promise_array blocks)
568
564
(lambda (fun blocks_resolved ->
569
565
let $ buffer = (" buffer" , buffer_create () ) in
570
566
let s1 = f blocks_resolved buffer in
571
- let s2 = return (runtime.buffer_to_promise @@ buffer) in
567
+ let s2 = return (runtime.buffer_contents @@ buffer) in
572
568
s1 |: s2)))
573
569
in
574
570
s1 |: s2
@@ -1067,9 +1063,9 @@ end = struct
1067
1063
compiled.C. components ([] , [] )
1068
1064
in
1069
1065
let $ escape = (" acutis_escape" , escape) in
1070
- let $ buffer_to_promise = (" buffer_to_promise " , buffer_to_promise ) in
1066
+ let $ buffer_contents = (" buffer_contents " , buffer_contents ) in
1071
1067
let $ comps = (" components" , hashtbl_create () ) in
1072
- let runtime = { escape; comps; buffer_to_promise } in
1068
+ let runtime = { escape; comps; buffer_contents } in
1073
1069
let s1 =
1074
1070
List. to_seq externals
1075
1071
|> Seq. map (fun (k , tys , v ) ->
@@ -1091,7 +1087,7 @@ end = struct
1091
1087
lambda (fun props ->
1092
1088
let $ buffer = (" buffer" , buffer_create () ) in
1093
1089
let s1 = nodes runtime buffer props v in
1094
- let s2 = return (buffer_to_promise @@ buffer) in
1090
+ let s2 = return (buffer_contents @@ buffer) in
1095
1091
s1 |: s2))
1096
1092
|> join_stmts
1097
1093
in
@@ -1150,7 +1146,7 @@ end = struct
1150
1146
let s3 =
1151
1147
let $ buffer = (" buffer" , buffer_create () ) in
1152
1148
let s1 = nodes runtime buffer props compiled.nodes in
1153
- let s2 = return (buffer_to_promise @@ buffer) in
1149
+ let s2 = return (buffer_contents @@ buffer) in
1154
1150
s1 |: s2
1155
1151
in
1156
1152
s1 |: s2 |: s3))
@@ -1270,9 +1266,8 @@ module MakeTrans
1270
1266
let bind a f = fwde (F. bind (bwde a) (bwde f))
1271
1267
let promise_array a = fwde (F. promise_array (bwde a))
1272
1268
let buffer_create () = fwde (F. buffer_create () )
1273
- let buffer_add_string b s = fwds (F. buffer_add_string (bwde b) (bwde s))
1274
- let buffer_add_promise b p = fwds (F. buffer_add_promise (bwde b) (bwde p))
1275
- let buffer_to_promise = fwde F. buffer_to_promise
1269
+ let buffer_append b s = fwds (F. buffer_append (bwde b) (bwde s))
1270
+ let buffer_contents = fwde F. buffer_contents
1276
1271
let escape = fwde F. escape
1277
1272
let stack_create () = fwde (F. stack_create () )
1278
1273
let stack_is_empty s = fwde (F. stack_is_empty (bwde s))
@@ -1459,9 +1454,8 @@ let pp (type a) pp_import ppf c =
1459
1454
type buffer
1460
1455
1461
1456
let buffer_create () = F. dprintf " (buffer_create)"
1462
- let buffer_add_string = F. dprintf " (@[buffer_add_string@ %t@ %t@])"
1463
- let buffer_add_promise = F. dprintf " (@[buffer_add_promise@ %t@ %t@])"
1464
- let buffer_to_promise = F. dprintf " (buffer_to_promise)"
1457
+ let buffer_append = F. dprintf " (@[buffer_append@ %t@ %t@])"
1458
+ let buffer_contents = F. dprintf " (buffer_contents)"
1465
1459
let escape = F. dprintf " (escape)"
1466
1460
1467
1461
type 'a stack
0 commit comments