package bonsai
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
A library for building dynamic webapps, using Js_of_ocaml
Install
dune-project
Dependency
Authors
Maintainers
Sources
v0.17.0.tar.gz
sha256=c78c4476ee6b856846e2d0941e5965009d5e1b853e564b2b1bee61202f0b1ebb
doc/src/bonsai.test_of_bonsai_itself/test_cse_cont.ml.html
Source file test_cse_cont.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312open! Core open! Import open Bonsai_test module Bonsai = struct include Bonsai.Cont module Private = Bonsai.Private end open Bonsai.Let_syntax let dummy_value () = Bonsai.map (opaque_const_value ()) ~f:(fun () -> print_endline "computing!") ;; let use_two_unit_values a b = let%arr () = a and () = b in () ;; let sexp_of_computation c = let module Private = Bonsai.Private in c |> Private.top_level_handle |> Private.Skeleton.Computation.of_computation |> Private.Skeleton.Computation.sanitize_for_testing |> Private.Skeleton.Computation.minimal_sexp_of_t ;; let print_computation c = print_s (sexp_of_computation c) let evaluate component = print_computation component; let _handle = Handle.create ~optimize:true (Result_spec.string (module Unit)) component in () ;; let%expect_test "double-use of a Value.t" = let component _graph = let dummy = dummy_value () in let%map () = dummy and () = dummy in () in evaluate component; [%expect {| (Sub (from (Return (value (Mapn (inputs (Incr)))))) (via (Test 2)) (into ( Sub (from ( Return ( value ( Mapn ( inputs ( (Named (uid (Test 2))) (Named (uid (Test 2))))))))) (via (Test 4)) (into (Return (value (Mapn (inputs ((Named (uid (Test 4)))))))))))) computing! |}] ;; let%expect_test "double-use spanning match%sub with value previously computed" = let component _graph = let a = dummy_value () in let b = match%sub opaque_const_value true with | true -> a | false -> a in use_two_unit_values a b in evaluate component; [%expect {| (Sub (from (Return (value (Mapn (inputs (Incr)))))) (via (Test 2)) (into ( Sub (from (Return (value (Mapn (inputs (Incr)))))) (via (Test 5)) (into ( Sub (from ( Switch (match_ (Named (uid (Test 5)))) (arms ( (Return (value (Named (uid (Test 2))))) (Return (value (Named (uid (Test 2))))))))) (via (Test 6)) (into ( Sub (from ( Return ( value ( Mapn ( inputs ( (Named (uid (Test 2))) (Named (uid (Test 6))))))))) (via (Test 8)) (into (Return (value (Mapn (inputs ((Named (uid (Test 8)))))))))))))))) computing! |}] ;; let%expect_test "double-use with first use inside scope" = let component _graph = let dummy_value = dummy_value () in let a = match%sub opaque_const_value true with | true -> dummy_value | false -> dummy_value in let b = dummy_value in use_two_unit_values a b in evaluate component; [%expect {| (Sub (from (Return (value (Mapn (inputs (Incr)))))) (via (Test 2)) (into ( Sub (from (Return (value (Mapn (inputs (Incr)))))) (via (Test 5)) (into ( Sub (from ( Switch (match_ (Named (uid (Test 5)))) (arms ( (Return (value (Named (uid (Test 2))))) (Return (value (Named (uid (Test 2))))))))) (via (Test 6)) (into ( Sub (from ( Return ( value ( Mapn ( inputs ( (Named (uid (Test 6))) (Named (uid (Test 2))))))))) (via (Test 8)) (into (Return (value (Mapn (inputs ((Named (uid (Test 8)))))))))))))))) computing! |}] ;; let%expect_test "double-use inside of some subs" = let component graph = let v = dummy_value () in let subcomponent _graph = v in let a = subcomponent graph in let b = subcomponent graph in use_two_unit_values a b in evaluate component; [%expect {| (Sub (from (Return (value (Mapn (inputs (Incr)))))) (via (Test 2)) (into ( Sub (from ( Return ( value ( Mapn ( inputs ( (Named (uid (Test 2))) (Named (uid (Test 2))))))))) (via (Test 4)) (into (Return (value (Mapn (inputs ((Named (uid (Test 4)))))))))))) computing! |}] ;; let%expect_test "double-use inside of some nested subs" = let component graph = let dummy_value = dummy_value () in let subcomponent graph = let a = opaque_const () graph in let%map () = a and () = dummy_value in () in let a = subcomponent graph in let b = subcomponent graph in use_two_unit_values a b in evaluate component; [%expect {| (Sub (from (Return (value (Mapn (inputs (Incr)))))) (via (Test 2)) (into ( Sub (from (Return (value (Mapn (inputs (Incr (Named (uid (Test 2))))))))) (via (Test 5)) (into ( Sub (from (Return (value (Mapn (inputs ((Named (uid (Test 5))))))))) (via (Test 7)) (into ( Sub (from (Return (value (Mapn (inputs (Incr (Named (uid (Test 2))))))))) (via (Test 10)) (into ( Sub (from (Return (value (Mapn (inputs ((Named (uid (Test 10))))))))) (via (Test 12)) (into ( Sub (from ( Return ( value ( Mapn ( inputs ( (Named (uid (Test 7))) (Named (uid (Test 12))))))))) (via (Test 14)) (into (Return (value (Mapn (inputs ((Named (uid (Test 14)))))))))))))))))))) computing! |}] ;; let%expect_test "double-use inside supercomponent" = let component graph = let i = opaque_const () graph in let dummy_value = dummy_value () in let subcomponent _graph = let%map () = i and () = dummy_value in print_endline "more computing" in let a = subcomponent graph in let b = subcomponent graph in use_two_unit_values a b in evaluate component; [%expect {| (Sub (from (Return (value (Mapn (inputs (Incr)))))) (via (Test 2)) (into ( Sub (from (Return (value (Mapn (inputs (Incr (Named (uid (Test 2))))))))) (via (Test 5)) (into ( Sub (from (Return (value (Mapn (inputs ((Named (uid (Test 5))))))))) (via (Test 7)) (into ( Sub (from (Return (value (Mapn (inputs (Incr (Named (uid (Test 2))))))))) (via (Test 9)) (into ( Sub (from (Return (value (Mapn (inputs ((Named (uid (Test 9))))))))) (via (Test 11)) (into ( Sub (from ( Return ( value ( Mapn ( inputs ( (Named (uid (Test 7))) (Named (uid (Test 11))))))))) (via (Test 13)) (into (Return (value (Mapn (inputs ((Named (uid (Test 13)))))))))))))))))))) computing! more computing more computing |}] ;; let%expect_test "double-use with first use inside scope" = let component graph = let subcomponent graph = let path = Bonsai.path_id graph in let%map path = path in print_endline ("computing " ^ path); path in let a = subcomponent graph in let b = subcomponent graph in let%map a = a and b = b in a ^ " " ^ b in let handle = Handle.create ~optimize:false (Result_spec.string (module String)) component in [%expect {| computing bonsai_path_y computing bonsai_path_x |}]; Handle.show handle; [%expect {| bonsai_path_x bonsai_path_y |}] ;;
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>