hclang 0.38.2 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/lib/bundle/hc-sources.js +65 -55
- package/esm/lib/execute/eval-pipe.js +1 -2
- package/esm/lib/frames/bound-method.js +2 -2
- package/esm/lib/frames/error-kind.js +34 -0
- package/esm/lib/frames/frame-expr.js +94 -13
- package/esm/lib/frames/frame-name.js +1 -3
- package/esm/lib/frames/frame-note.js +17 -14
- package/esm/lib/frames/frame-observation.js +97 -0
- package/esm/lib/frames/frame-scope-anchor.js +97 -11
- package/esm/lib/frames/frame.js +23 -2
- package/esm/lib/frames/schema-matcher.js +1 -1
- package/esm/lib/frames.js +2 -1
- package/esm/lib/ops/math.js +8 -9
- package/esm/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -1412,7 +1412,7 @@ export const HC_SOURCES = new Map([
|
|
|
1412
1412
|
"when odd, right next. It is a Count rather than all or nil because a field",
|
|
1413
1413
|
"cannot hold nil, and a Count keeps the odd phase present: a Demi in phase 1 is",
|
|
1414
1414
|
"a value, unlike the nil `.####` answers for a Frame with no Demi. Anything else",
|
|
1415
|
-
"is refused with
|
|
1415
|
+
"is refused with `$!!.invalid-demi`, a named error, as Figures refuses an",
|
|
1416
1416
|
"unsupported host. The fields are the whole state, so two Demis are `=` exactly",
|
|
1417
1417
|
"when their fields are.",
|
|
1418
1418
|
"",
|
|
@@ -1445,7 +1445,7 @@ export const HC_SOURCES = new Map([
|
|
|
1445
1445
|
"count lexically (spec a06). What a branch needs is bound as a local at method",
|
|
1446
1446
|
"level, where nested blocks read it.",
|
|
1447
1447
|
"```",
|
|
1448
|
-
".Demi {.p (
|
|
1448
|
+
".Demi {((_ ~ ([].<>)) ? {(__ .#) = 3}) ? {.p (__ .0); .l (__ .1); .r (__ .2);",
|
|
1449
1449
|
" ((((p = 2) : {p = 1}) ? {p ~ (0.<>)}) ? {(l ~ (0.<>)) ? {r ~ (0.<>)}}) ? {[",
|
|
1450
1450
|
" .phase p;",
|
|
1451
1451
|
" .left l;",
|
|
@@ -1456,9 +1456,9 @@ export const HC_SOURCES = new Map([
|
|
|
1456
1456
|
" .apply_ {.s (_ .##); .l (_^ .left); .r (_^ .right);",
|
|
1457
1457
|
" (s ~ (0.<>)) ? {((_^^ .phase) = 2) ? {@left (l + s); @phase 1;} : {@right (r + s); @phase 2;}; _^^} : {s}};",
|
|
1458
1458
|
" .scale_ {.k _; .l (_^ .left); .r (_^ .right);",
|
|
1459
|
-
" (k ~ (0.<>)) ? {@left (l * k); @right (r * k); _^^} : {invalid-scale}};",
|
|
1459
|
+
" (k ~ (0.<>)) ? {@left (l * k); @right (r * k); _^^} : {$!!.invalid-scale}};",
|
|
1460
1460
|
" .toText {“Demi(” (((_^ .phase) = 2) ? {“<>”} : {“()”}) “,” (_^ .left) “,” (_^ .right) “)”}",
|
|
1461
|
-
" ]} : {invalid-demi}};",
|
|
1461
|
+
" ]} : {$!!.invalid-demi}} : {$!!.invalid-demi}};",
|
|
1462
1462
|
"```",
|
|
1463
1463
|
"## Construction",
|
|
1464
1464
|
"",
|
|
@@ -1475,9 +1475,9 @@ export const HC_SOURCES = new Map([
|
|
|
1475
1475
|
"Anything but three Counts with phase 1 or 2 is refused",
|
|
1476
1476
|
"```",
|
|
1477
1477
|
"; Demi [3, 0, 0]",
|
|
1478
|
-
"#
|
|
1478
|
+
"# $!!.invalid-demi",
|
|
1479
1479
|
"; [Demi [2, (0 - 1), 0], Demi [2, (5 - 3), 0], Demi [2, 0], Demi 5, Demi [(5 - 3), 0, 0]]",
|
|
1480
|
-
"# [
|
|
1480
|
+
"# [$!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi, $!!.invalid-demi]",
|
|
1481
1481
|
"```",
|
|
1482
1482
|
"## Application",
|
|
1483
1483
|
"",
|
|
@@ -1608,7 +1608,7 @@ export const HC_SOURCES = new Map([
|
|
|
1608
1608
|
"; [“” (e.scale_ 2), “” (e.scale_ 0), (e.scale_ 1) = e, ((e.scale_ 2).scale_ 3) = (e.scale_ 6)]",
|
|
1609
1609
|
"# [“Demi((),24,6)”, “Demi((),0,0)”, <>, <>]",
|
|
1610
1610
|
"; e.scale_ (0 - 2)",
|
|
1611
|
-
"#
|
|
1611
|
+
"# $!!.invalid-scale",
|
|
1612
1612
|
"```",
|
|
1613
1613
|
"It is the shadow of Star on a nonempty host",
|
|
1614
1614
|
"```",
|
|
@@ -1626,13 +1626,16 @@ export const HC_SOURCES = new Map([
|
|
|
1626
1626
|
"Carets count lexically, so inside a branch `_^` is the method's own scope, not",
|
|
1627
1627
|
"the receiver. Reading a load there fails, `$!.name-missing`. Before 011.20,",
|
|
1628
1628
|
"`+` turned that failure into nil, and writing nil leaves a field as it was, so",
|
|
1629
|
-
"the deposit silently did nothing while the phase still flipped.
|
|
1630
|
-
"failure
|
|
1629
|
+
"the deposit silently did nothing while the phase still flipped. Since #467 the",
|
|
1630
|
+
"failure is the method's answer and ends it at the failed write, so even through",
|
|
1631
|
+
"a mutable name neither field changes",
|
|
1631
1632
|
"```",
|
|
1632
1633
|
"; .Wrong {[.phase 2; .left 0; .apply_ {.s (_ .##); (_^.phase = 2) ? {@left (_^.left + s); @phase 1;};}]};",
|
|
1633
|
-
"; .
|
|
1634
|
-
";
|
|
1635
|
-
"#
|
|
1634
|
+
"; .w_ (Wrong ());",
|
|
1635
|
+
"; w_ 5",
|
|
1636
|
+
"# $!.name-missing “...",
|
|
1637
|
+
"; [w_.phase, w_.left]",
|
|
1638
|
+
"# [2, 0]",
|
|
1636
1639
|
"; .Right {[.phase 2; .left 0; .apply_ {.s (_ .##); (_^.phase = 2) ? {@left (_^^.left + s); @phase 1;};}]};",
|
|
1637
1640
|
"; .r ((Right ()) 5);",
|
|
1638
1641
|
"; [r.phase, r.left]",
|
|
@@ -1698,7 +1701,7 @@ export const HC_SOURCES = new Map([
|
|
|
1698
1701
|
"```",
|
|
1699
1702
|
".gap {.x _; (x.###) ? {",
|
|
1700
1703
|
" .signed (x.###);",
|
|
1701
|
-
" (signed .< 0) ? {0 - signed} : {signed}} : {unsupported-figure}};",
|
|
1704
|
+
" (signed .< 0) ? {0 - signed} : {signed}} : {$!!.unsupported-figure}};",
|
|
1702
1705
|
"```",
|
|
1703
1706
|
"Spin retains a typed positive Count divisor. Bare `x.### / N` would accept",
|
|
1704
1707
|
"negative or fractional divisors and silently answer nil for an unsupported",
|
|
@@ -1710,7 +1713,7 @@ export const HC_SOURCES = new Map([
|
|
|
1710
1713
|
" (host.###) ? {",
|
|
1711
1714
|
" {.n <(1).<>> _; .signed (host.###);",
|
|
1712
1715
|
" (n .< 1) ? {signed / 0} : {signed / n}}} : {",
|
|
1713
|
-
" {.n _; unsupported-figure}}};",
|
|
1716
|
+
" {.n _; $!!.unsupported-figure}}};",
|
|
1714
1717
|
"```",
|
|
1715
1718
|
"Native construction, counting and comparisons need no module helpers.",
|
|
1716
1719
|
"```",
|
|
@@ -1726,7 +1729,7 @@ export const HC_SOURCES = new Map([
|
|
|
1726
1729
|
"```",
|
|
1727
1730
|
"; [([].### ? {<>} : {()}), ([[], [[]]].### ? {<>} : {()}), ([[], 5].### ? {<>} : {()}), ([.k 1; []].### ? {<>} : {()})]",
|
|
1728
1731
|
"# [<>, <>, <>, <>]",
|
|
1729
|
-
"; [(e.### ? {e} : {unsupported-figure}) = e, (e.### ? {e} : {unsupported-figure}) === e]",
|
|
1732
|
+
"; [(e.### ? {e} : {$!!.unsupported-figure}) = e, (e.### ? {e} : {$!!.unsupported-figure}) === e]",
|
|
1730
1733
|
"# [<>, <>]",
|
|
1731
1734
|
"; [[], “a”] * [[]]",
|
|
1732
1735
|
"# $!.star-domain *",
|
|
@@ -2537,7 +2540,8 @@ export const HC_SOURCES = new Map([
|
|
|
2537
2540
|
"array's properties are configuration, not routed Frames, so the constructor",
|
|
2538
2541
|
"keeps the elements in a fresh array of its own, and a channel argument that",
|
|
2539
2542
|
"declares `apply` cannot change what appending means. Anything else is refused",
|
|
2540
|
-
"with
|
|
2543
|
+
"with `$!!.invalid-router`, a named error, as `Demi` refuses with",
|
|
2544
|
+
"`$!!.invalid-demi`.",
|
|
2541
2545
|
"Any phase and any two channels are a state; nothing requires the channels to",
|
|
2542
2546
|
"be a history the router could have produced.",
|
|
2543
2547
|
"",
|
|
@@ -2573,7 +2577,7 @@ export const HC_SOURCES = new Map([
|
|
|
2573
2577
|
"the method body. What a branch needs is bound as a local at method level.",
|
|
2574
2578
|
"```",
|
|
2575
2579
|
".channel-load {.c _; (c.# = 0) ? {0} : {c.##}};",
|
|
2576
|
-
".RotorRouter {.p (
|
|
2580
|
+
".RotorRouter {((_ ~ ([].<>)) ? {(__ .#) = 3}) ? {.p (__ .0); .l (__ .1); .r (__ .2);",
|
|
2577
2581
|
" ((((p = 2) : {p = 1}) ? {p ~ (0.<>)}) ? {(l ~ ([].<>)) ? {r ~ ([].<>)}}) ? {[",
|
|
2578
2582
|
" .phase p;",
|
|
2579
2583
|
" .left (l | []);",
|
|
@@ -2584,7 +2588,7 @@ export const HC_SOURCES = new Map([
|
|
|
2584
2588
|
" .## {(channel-load (_^ .left)) + (channel-load (_^ .right))};",
|
|
2585
2589
|
" .### {(channel-load (_^ .left)) - (channel-load (_^ .right))};",
|
|
2586
2590
|
" .toText {“RotorRouter(” (((_^ .phase) = 2) ? {“<>”} : {“()”}) “,” (_^ .left) “,” (_^ .right) “)”}",
|
|
2587
|
-
" ]} : {invalid-router}};",
|
|
2591
|
+
" ]} : {$!!.invalid-router}} : {$!!.invalid-router}};",
|
|
2588
2592
|
"```",
|
|
2589
2593
|
"## Construction",
|
|
2590
2594
|
"",
|
|
@@ -2598,9 +2602,9 @@ export const HC_SOURCES = new Map([
|
|
|
2598
2602
|
"Anything but a phase of 1 or 2 and two arrays is refused",
|
|
2599
2603
|
"```",
|
|
2600
2604
|
"; RotorRouter [3, [], []]",
|
|
2601
|
-
"#
|
|
2605
|
+
"# $!!.invalid-router",
|
|
2602
2606
|
"; [RotorRouter [(5 - 3), [], []], RotorRouter [2, [], 5], RotorRouter [2, (1, 2), []], RotorRouter [2, []], RotorRouter 5]",
|
|
2603
|
-
"# [
|
|
2607
|
+
"# [$!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router, $!!.invalid-router]",
|
|
2604
2608
|
"```",
|
|
2605
2609
|
"A channel is its elements. The router keeps them in an array of its own, so a",
|
|
2606
2610
|
"channel's properties and a declared `apply` do not come with it",
|
|
@@ -2714,16 +2718,13 @@ export const HC_SOURCES = new Map([
|
|
|
2714
2718
|
"; counter_.n",
|
|
2715
2719
|
"# 2",
|
|
2716
2720
|
"```",
|
|
2717
|
-
"
|
|
2718
|
-
"
|
|
2719
|
-
"
|
|
2721
|
+
"An error is the answer of the expression that applies the router, so it is",
|
|
2722
|
+
"never routed. A diagnostic failure such as a missing name is an error too",
|
|
2723
|
+
"(#467), so it is not routed either",
|
|
2720
2724
|
"```",
|
|
2721
2725
|
"; r0 (1 / 0)",
|
|
2722
2726
|
"# $!.division-by-zero /",
|
|
2723
|
-
";
|
|
2724
|
-
"; [noted.phase, noted.left.#]",
|
|
2725
|
-
"# [1, 1]",
|
|
2726
|
-
"; noted.####",
|
|
2727
|
+
"; r0 ([].nope)",
|
|
2727
2728
|
"# $!.name-missing “...",
|
|
2728
2729
|
"```",
|
|
2729
2730
|
"Routing nil routes nothing",
|
|
@@ -2844,13 +2845,17 @@ export const HC_SOURCES = new Map([
|
|
|
2844
2845
|
"# [1, 1, 9, []]",
|
|
2845
2846
|
"```",
|
|
2846
2847
|
"Carets count lexically (spec a06). Inside a branch, `_^` is the method's own",
|
|
2847
|
-
"scope, so a router that reads its channel there reads nothing
|
|
2848
|
-
"
|
|
2848
|
+
"scope, so a router that reads its channel there reads nothing. That failure is",
|
|
2849
|
+
"the method's answer and ends it at the failed write (#467), so even through a",
|
|
2850
|
+
"mutable name the router is unchanged. `_^^` is the receiver from inside the",
|
|
2851
|
+
"branch",
|
|
2849
2852
|
"```",
|
|
2850
2853
|
"; .WrongRouter {[.phase 2; .left []; .apply_ {.x _; ((_^ .phase) = 2) ? {@left (_^ .left x); @phase 1;};}]};",
|
|
2851
|
-
"; .
|
|
2852
|
-
";
|
|
2853
|
-
"#
|
|
2854
|
+
"; .w_ (WrongRouter ());",
|
|
2855
|
+
"; w_ 5",
|
|
2856
|
+
"# $!.name-missing “...",
|
|
2857
|
+
"; [w_.phase, w_.left]",
|
|
2858
|
+
"# [2, []]",
|
|
2854
2859
|
"; .RightRouter {[.phase 2; .left []; .apply_ {.x _; ((_^ .phase) = 2) ? {@left (_^^ .left x); @phase 1;};}]};",
|
|
2855
2860
|
"; .rr ((RightRouter ()) 5);",
|
|
2856
2861
|
"; [rr.phase, rr.left]",
|
|
@@ -2904,7 +2909,7 @@ export const HC_SOURCES = new Map([
|
|
|
2904
2909
|
"# ````",
|
|
2905
2910
|
"; ``````",
|
|
2906
2911
|
"# ``````",
|
|
2907
|
-
"
|
|
2912
|
+
"```## A document publishes its characters without its fences```",
|
|
2908
2913
|
"; `one-backtick document`.body",
|
|
2909
2914
|
"# “one-backtick document”",
|
|
2910
2915
|
"; ```body with `one` and ``two`` spans```.body",
|
|
@@ -2954,29 +2959,29 @@ export const HC_SOURCES = new Map([
|
|
|
2954
2959
|
"```",
|
|
2955
2960
|
"Test types",
|
|
2956
2961
|
"```",
|
|
2957
|
-
"
|
|
2962
|
+
"```## Empty schema accepts any value```",
|
|
2958
2963
|
"; .x <> 42",
|
|
2959
2964
|
"# 42",
|
|
2960
|
-
"
|
|
2965
|
+
"```## Number enumerations```",
|
|
2961
2966
|
"; .option <1,2,3> 2",
|
|
2962
2967
|
"# .option 2",
|
|
2963
2968
|
"; @option 3",
|
|
2964
2969
|
"# 3",
|
|
2965
2970
|
"; @option 4",
|
|
2966
2971
|
"# $!.type-error .option <1, 2, 3> 4",
|
|
2967
|
-
"
|
|
2972
|
+
"```## Single value schema (constant)```",
|
|
2968
2973
|
"; .const <42> 42",
|
|
2969
2974
|
"# .const 42",
|
|
2970
2975
|
"; @const 43",
|
|
2971
2976
|
"# $!.type-error .const <42> 43",
|
|
2972
|
-
"
|
|
2977
|
+
"```## Multiple valid assignments```",
|
|
2973
2978
|
"; .x <1,2> 1",
|
|
2974
2979
|
"# 1",
|
|
2975
2980
|
"; @x 2",
|
|
2976
2981
|
"# 2",
|
|
2977
2982
|
"; @x 1",
|
|
2978
2983
|
"# 1",
|
|
2979
|
-
"
|
|
2984
|
+
"```## Original tests```",
|
|
2980
2985
|
"; <> 1",
|
|
2981
2986
|
"# <>",
|
|
2982
2987
|
"; <> ()",
|
|
@@ -2985,7 +2990,7 @@ export const HC_SOURCES = new Map([
|
|
|
2985
2990
|
"# .one 1",
|
|
2986
2991
|
"; @one 2",
|
|
2987
2992
|
"# $!.type-error .one <1> 2",
|
|
2988
|
-
"
|
|
2993
|
+
"```## Boolean and first-class type operations```",
|
|
2989
2994
|
"; ().!",
|
|
2990
2995
|
"# <>",
|
|
2991
2996
|
"; <>.!",
|
|
@@ -2998,7 +3003,7 @@ export const HC_SOURCES = new Map([
|
|
|
2998
3003
|
"# <>",
|
|
2999
3004
|
"; “Q” ~ (1).<>",
|
|
3000
3005
|
"# ()",
|
|
3001
|
-
"
|
|
3006
|
+
"```## Closure signatures apply defaults, require bare fields, and allow extras```",
|
|
3002
3007
|
"; .join-name (.first “Jane”, .last) ^ {last “, ” first};",
|
|
3003
3008
|
"; join-name (.first “John”, .last “Doe”)",
|
|
3004
3009
|
"# “Doe, John”",
|
|
@@ -3009,7 +3014,7 @@ export const HC_SOURCES = new Map([
|
|
|
3009
3014
|
"```",
|
|
3010
3015
|
"Conditionals",
|
|
3011
3016
|
"```",
|
|
3012
|
-
"
|
|
3017
|
+
"```## Binary truth table for ordinary frames and raw nil: `:` answers a frame itself```",
|
|
3013
3018
|
"; 1 ? {2 + 2}",
|
|
3014
3019
|
"# 4",
|
|
3015
3020
|
"; 1 : {2 + 2}",
|
|
@@ -3018,12 +3023,12 @@ export const HC_SOURCES = new Map([
|
|
|
3018
3023
|
"# ()",
|
|
3019
3024
|
"; () : {2 + 2}",
|
|
3020
3025
|
"# 4",
|
|
3021
|
-
"
|
|
3026
|
+
"```## The selected callable may itself return nil```",
|
|
3022
3027
|
"; 1 ? {()}",
|
|
3023
3028
|
"# ()",
|
|
3024
3029
|
"; () : {()}",
|
|
3025
3030
|
"# ()",
|
|
3026
|
-
"
|
|
3031
|
+
"```## Dotted comparisons produce Frame.all or Frame.nil predicates```",
|
|
3027
3032
|
"; 1.> 5 ? {100}",
|
|
3028
3033
|
"# ()",
|
|
3029
3034
|
"; 1.> 5 : {10}",
|
|
@@ -3032,52 +3037,52 @@ export const HC_SOURCES = new Map([
|
|
|
3032
3037
|
"# 100",
|
|
3033
3038
|
"; 5.> 1 : {10}",
|
|
3034
3039
|
"# <>",
|
|
3035
|
-
"
|
|
3040
|
+
"```## Chained conditionals answer the taken branch```",
|
|
3036
3041
|
"; 1.> 5 ? (2 * 50) : 10",
|
|
3037
3042
|
"# 10",
|
|
3038
3043
|
"; 5.> 1 ? (2 * 50) : 10",
|
|
3039
3044
|
"# 100",
|
|
3040
|
-
"
|
|
3045
|
+
"```## A taken branch that answers nil falls through to the else branch```",
|
|
3041
3046
|
"; 5.> 1 ? {()} : {10}",
|
|
3042
3047
|
"# 10",
|
|
3043
3048
|
"```",
|
|
3044
3049
|
"Figures: construct with optional children, observe with Figure answers",
|
|
3045
3050
|
"```",
|
|
3046
3051
|
"; .A []; .B [A]; .E [A, B]; .B2 [A];",
|
|
3047
|
-
"
|
|
3052
|
+
"```## Reuse and resemblance are different rungs of the equality ladder```",
|
|
3048
3053
|
"; [B = B2, B == B2, B === B2]",
|
|
3049
3054
|
"# [<>, <>, ()]",
|
|
3050
3055
|
"; (E .0) === A",
|
|
3051
3056
|
"# <>",
|
|
3052
|
-
"
|
|
3057
|
+
"```## A plain conditional answers a Figure from either branch```",
|
|
3053
3058
|
"; .same {((_ .0) === (_ .1)) ? {B} : {A}};",
|
|
3054
3059
|
"; same [B, B]",
|
|
3055
3060
|
"# [[]]",
|
|
3056
3061
|
"; same [B, B2]",
|
|
3057
3062
|
"# []",
|
|
3058
|
-
"
|
|
3063
|
+
"```## Box a branch that answers nil, so it does not fall through```",
|
|
3059
3064
|
"; .rest {((_ && {(((_ .0) = .0) ? {[()]} : {[[__ .1]]}) .0}) | []) & {_ .0}};",
|
|
3060
3065
|
"; rest E",
|
|
3061
3066
|
"# [[[]]]",
|
|
3062
|
-
"
|
|
3067
|
+
"```## Observing a Figure through a plain name does not write onto it```",
|
|
3063
3068
|
"; E & {.o _; o};",
|
|
3064
3069
|
"; E",
|
|
3065
3070
|
"# [[], [[]]]",
|
|
3066
3071
|
"```",
|
|
3067
3072
|
"Quote delimiters",
|
|
3068
3073
|
"```",
|
|
3069
|
-
"
|
|
3074
|
+
"```## Curly quotes nest without an escape character```",
|
|
3070
3075
|
"; “a “b” c”",
|
|
3071
3076
|
"# “a “b” c”",
|
|
3072
|
-
"
|
|
3077
|
+
"```## The ASCII quote is an input spelling of the same value```",
|
|
3073
3078
|
'; "ascii"',
|
|
3074
3079
|
"# “ascii”",
|
|
3075
3080
|
'; ""',
|
|
3076
3081
|
"# “”",
|
|
3077
|
-
"
|
|
3082
|
+
"```## An odd ASCII run selects nesting depth, so shorter runs are content```",
|
|
3078
3083
|
'; """x "" y"""',
|
|
3079
3084
|
'# “x "" y”',
|
|
3080
|
-
"
|
|
3085
|
+
"```## Single quotes name a resource without authorizing it```",
|
|
3081
3086
|
"; 'jsr:@swanfactory/hclang'",
|
|
3082
3087
|
"# 'jsr:@swanfactory/hclang'",
|
|
3083
3088
|
"; 'jsr:@swanfactory/hclang'.scheme",
|
|
@@ -3331,13 +3336,18 @@ export const HC_SOURCES = new Map([
|
|
|
3331
3336
|
"# <>",
|
|
3332
3337
|
"; 9.80.m == 9.8.m",
|
|
3333
3338
|
"# <>",
|
|
3334
|
-
"; 3.m == 3.0.m",
|
|
3335
|
-
"# ()",
|
|
3336
3339
|
"; 9.8.m = 9.8.kg",
|
|
3337
3340
|
"# ()",
|
|
3338
3341
|
"; 9.8.m = 9.8",
|
|
3339
3342
|
"# ()",
|
|
3340
3343
|
"```",
|
|
3344
|
+
"A Count literal has no unit suffix: `3.m` reads a missing property, so comparing",
|
|
3345
|
+
"it propagates that failure rather than answering nil. Use `3.0.m` for a typed",
|
|
3346
|
+
"number.",
|
|
3347
|
+
"```",
|
|
3348
|
+
"; 3.m == 3.0.m",
|
|
3349
|
+
"# $!.name-missing “...",
|
|
3350
|
+
"```",
|
|
3341
3351
|
"`===` asks for the same frame, and an atom owns no identity, so it is `==`:",
|
|
3342
3352
|
"different units are never the same (#358)",
|
|
3343
3353
|
"```",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EvaluationScope, Frame, FrameGroup,
|
|
1
|
+
import { EvaluationScope, Frame, FrameGroup, NilContext, } from "../frames.js";
|
|
2
2
|
import { LexPipe } from "./lex-pipe.js";
|
|
3
3
|
import { ParsePipe } from "./parse-pipe.js";
|
|
4
4
|
/** Builds the shared Lex/Parse/Eval pipeline for one HC source unit. */
|
|
@@ -87,6 +87,5 @@ function outputFailed(result, seen) {
|
|
|
87
87
|
return false;
|
|
88
88
|
seen.add(result);
|
|
89
89
|
return result.isFailedResult() ||
|
|
90
|
-
(result instanceof FrameNote && result.isDiagnosticFailure()) ||
|
|
91
90
|
result.asArray().some((item) => outputFailed(item, seen));
|
|
92
91
|
}
|
|
@@ -104,8 +104,8 @@ export class BoundMethod extends Frame {
|
|
|
104
104
|
// was built last, so a method would read another instance's fields.
|
|
105
105
|
const result = this.method.call(argument, Frame.nil, state);
|
|
106
106
|
// A mutating method answers its receiver, unless it answered an error. A
|
|
107
|
-
// diagnostic
|
|
108
|
-
//
|
|
107
|
+
// diagnostic failure such as `$!.name-missing` carries the same flag.
|
|
108
|
+
// Preserve referent checks for programmatic reference wrappers (011.20).
|
|
109
109
|
if (result.isFailedResult() || result.referent().isError())
|
|
110
110
|
return result;
|
|
111
111
|
return this.isMutating() ? state.receiver : result;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error kinds (spec a13/14 §3, §4).
|
|
3
|
+
*
|
|
4
|
+
* A kind is the namespace and reason an error renders with: `$!.reason` for a
|
|
5
|
+
* system error, made by the interpreter, and `$!!.reason` for a user error,
|
|
6
|
+
* raised by HC code. Every error's rendering begins with its kind, followed by
|
|
7
|
+
* whatever subject it carries, so the kind is read from that prefix with the
|
|
8
|
+
* reason grammar of spec 10 §6.1.
|
|
9
|
+
*
|
|
10
|
+
* A `$!.reason` literal written in HC source is a user error that still
|
|
11
|
+
* describes the system kind it was written as. A schema that holds it matches
|
|
12
|
+
* that system kind (§4), while raising it propagates the user error.
|
|
13
|
+
*/
|
|
14
|
+
const KIND = /^\$(!!?)\.([A-Za-z_][A-Za-z0-9_-]*)/;
|
|
15
|
+
/**
|
|
16
|
+
* The kind a literal was written as, stored on the frame itself. It is an own
|
|
17
|
+
* enumerable property, so `Frame.copy` (`Object.assign`) carries it to every
|
|
18
|
+
* copy, and the kind survives wherever the literal's frame is copied.
|
|
19
|
+
*/
|
|
20
|
+
const WRITTEN = Symbol("written error kind");
|
|
21
|
+
/** The kind an error renders with, `$!.reason` or `$!!.reason`, if any. */
|
|
22
|
+
export const kindOf = (error) => {
|
|
23
|
+
const match = KIND.exec(error.toString());
|
|
24
|
+
return match ? `$${match[1]}.${match[2]}` : undefined;
|
|
25
|
+
};
|
|
26
|
+
/** The reason within a kind, without its namespace. */
|
|
27
|
+
export const reasonOf = (error) => KIND.exec(error.toString())?.[2];
|
|
28
|
+
/** Records that a user error was written as the system kind `kind`. */
|
|
29
|
+
export const describeAs = (error, kind) => {
|
|
30
|
+
error[WRITTEN] = kind;
|
|
31
|
+
return error;
|
|
32
|
+
};
|
|
33
|
+
/** The kind a schema candidate names: as written, or as it renders. */
|
|
34
|
+
export const describedKind = (candidate) => candidate[WRITTEN] ?? kindOf(candidate);
|
|
@@ -102,31 +102,103 @@ export class FrameExpr extends FrameList {
|
|
|
102
102
|
// Don't add separator here - let parent FrameList handle it
|
|
103
103
|
return [body];
|
|
104
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Reduces an expression's terms left to right, with the catch operator `$!`
|
|
107
|
+
* as its one boundary (spec a13/14 §5).
|
|
108
|
+
*
|
|
109
|
+
* Spaced, `E $! H₁ $! H₂` guards everything to its left: the expression
|
|
110
|
+
* splits at each bare `$!`, and each handler part is evaluated only while
|
|
111
|
+
* the result so far is an error. A tight catcher, `x $!{H}`, is one term
|
|
112
|
+
* (a16) that handles the failure just before it: the preceding term's, or
|
|
113
|
+
* else the expression so far.
|
|
114
|
+
*/
|
|
105
115
|
static evaluateTerms(terms, scope) {
|
|
106
|
-
return terms.
|
|
116
|
+
return terms.some(isCatch)
|
|
117
|
+
? FrameExpr.catchSpaced(terms, scope)
|
|
118
|
+
: FrameExpr.reduceTerms(terms, scope);
|
|
119
|
+
}
|
|
120
|
+
static reduceTerms(terms, scope) {
|
|
121
|
+
let sum = Frame.nil;
|
|
122
|
+
for (let index = 0; index < terms.length; index++) {
|
|
123
|
+
const item = terms[index];
|
|
124
|
+
if (isCatcher(item)) {
|
|
125
|
+
if (index === 0)
|
|
126
|
+
return Frame.error("$!.catch-operand-missing");
|
|
127
|
+
// A catcher after a success has nothing to handle and is not run.
|
|
128
|
+
if (sum.isError())
|
|
129
|
+
sum = FrameExpr.handle(sum, item, scope);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
107
132
|
// A failed term is the result of the expression. In particular, a
|
|
108
133
|
// missing dot-parameter read must not be replaced by the operator or
|
|
109
|
-
// operand that follows it.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
134
|
+
// operand that follows it. Only the value itself counts: an aggregate
|
|
135
|
+
// that collected a failure is still an ordinary value its later terms
|
|
136
|
+
// can read (`[E, 7] .1` is 7), as it was before #467 flagged notes.
|
|
137
|
+
// Later terms are skipped; only a catcher can still handle it.
|
|
138
|
+
if (sum.isError())
|
|
139
|
+
continue;
|
|
140
|
+
let value = item.in(resumedScope(item, scope));
|
|
141
|
+
while (value.is.error === true && isCatcher(terms[index + 1])) {
|
|
142
|
+
value = FrameExpr.handle(value, terms[++index], scope);
|
|
143
|
+
}
|
|
144
|
+
if (value.is.error === true) {
|
|
145
|
+
sum = value;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
115
148
|
if (index === 0 && value.isSymbol() && value.is.address &&
|
|
116
|
-
Frame.SIZE_OPERATORS.includes(value.spelling()))
|
|
117
|
-
|
|
149
|
+
Frame.SIZE_OPERATORS.includes(value.spelling())) {
|
|
150
|
+
sum = value;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
118
153
|
// An explicit nil receiver still has a Size. The initial nil accumulator
|
|
119
154
|
// is not a receiver, so a leading .## remains an address (#411).
|
|
120
155
|
if (index > 0 && sum.is.void && value.isSymbol() &&
|
|
121
156
|
value.is.address &&
|
|
122
157
|
Frame.SIZE_OPERATORS.includes(value.spelling())) {
|
|
123
|
-
|
|
158
|
+
sum = value.called_by(sum);
|
|
159
|
+
continue;
|
|
124
160
|
}
|
|
125
161
|
if (index > 0 && value.is.operator === true) {
|
|
126
|
-
|
|
162
|
+
sum = value.called_by(sum, Frame.nil).atSite(scope);
|
|
163
|
+
continue;
|
|
127
164
|
}
|
|
128
|
-
|
|
129
|
-
}
|
|
165
|
+
sum = sum.call(value);
|
|
166
|
+
}
|
|
167
|
+
return sum;
|
|
168
|
+
}
|
|
169
|
+
/** `E $! H₁ $! H₂ …`: guard everything to the left of each handler. */
|
|
170
|
+
static catchSpaced(terms, scope) {
|
|
171
|
+
const parts = [[]];
|
|
172
|
+
for (const term of terms) {
|
|
173
|
+
if (isCatch(term))
|
|
174
|
+
parts.push([]);
|
|
175
|
+
else
|
|
176
|
+
parts.at(-1).push(term);
|
|
177
|
+
}
|
|
178
|
+
const [guarded, ...handlers] = parts;
|
|
179
|
+
if (guarded.length === 0)
|
|
180
|
+
return Frame.error("$!.catch-operand-missing");
|
|
181
|
+
if (handlers.some((part) => part.length === 0)) {
|
|
182
|
+
return Frame.error("$!.catch-handler-missing");
|
|
183
|
+
}
|
|
184
|
+
let result = FrameExpr.reduceTerms(guarded, scope);
|
|
185
|
+
for (const part of handlers) {
|
|
186
|
+
if (!result.isError())
|
|
187
|
+
break;
|
|
188
|
+
result = Frame.catchWith(result, () => FrameExpr.reduceTerms(part, scope));
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* A tight catcher `$!H` handles `failure` with the handler `H`. The handler
|
|
194
|
+
* is evaluated only on failure, with the observation already current, so
|
|
195
|
+
* `$#` reads it whether `H` is a closure or not.
|
|
196
|
+
*/
|
|
197
|
+
static handle(failure, catcher, scope) {
|
|
198
|
+
const body = catcher.data.slice(1);
|
|
199
|
+
if (body.length === 0)
|
|
200
|
+
return Frame.error("$!.catch-handler-missing");
|
|
201
|
+
return Frame.catchWith(failure, () => FrameExpr.evaluateTerms(body, scope));
|
|
130
202
|
}
|
|
131
203
|
schemaRetrieval(scope) {
|
|
132
204
|
if (this.data.length !== 2 || !this.data[0].isSymbol() ||
|
|
@@ -502,3 +574,12 @@ function unwrapSingleton(frame) {
|
|
|
502
574
|
}
|
|
503
575
|
return result;
|
|
504
576
|
}
|
|
577
|
+
/** The catch operator `$!`, as the lexer completes it (`FrameCatch`). */
|
|
578
|
+
function isCatch(term) {
|
|
579
|
+
return term?.className() === "FrameCatch";
|
|
580
|
+
}
|
|
581
|
+
/** A tight expression that begins with `$!`: `$!{H}` written after a term. */
|
|
582
|
+
function isCatcher(term) {
|
|
583
|
+
return term instanceof FrameExpr && term.constructor === FrameExpr &&
|
|
584
|
+
isCatch(term.asArray()[0]);
|
|
585
|
+
}
|
|
@@ -85,9 +85,7 @@ export class FrameName extends FrameAtom {
|
|
|
85
85
|
const target = scope.parameterAt(this.source.length + 1);
|
|
86
86
|
if (target)
|
|
87
87
|
return target;
|
|
88
|
-
|
|
89
|
-
missing.is.error = true;
|
|
90
|
-
return missing;
|
|
88
|
+
return FrameNote.key(this.toString(), this);
|
|
91
89
|
}
|
|
92
90
|
// Construction declares the new aggregate's parent. Method-position `.^`
|
|
93
91
|
// instead re-parents the exact original-or-copy target authorized by the
|
|
@@ -14,9 +14,6 @@ export class FrameNote extends FrameAtom {
|
|
|
14
14
|
static key(source, where) {
|
|
15
15
|
return new FrameNote("!", source, where);
|
|
16
16
|
}
|
|
17
|
-
static type(source) {
|
|
18
|
-
return new FrameNote("<>", source);
|
|
19
|
-
}
|
|
20
17
|
static index(source) {
|
|
21
18
|
return new FrameNote(">", source);
|
|
22
19
|
}
|
|
@@ -48,20 +45,13 @@ export class FrameNote extends FrameAtom {
|
|
|
48
45
|
});
|
|
49
46
|
this.up = where;
|
|
50
47
|
this.is.note = true;
|
|
48
|
+
this.is.error = this.isDiagnosticFailure();
|
|
51
49
|
this.setLabel(data, source);
|
|
52
50
|
this.id += this.data;
|
|
53
51
|
}
|
|
54
|
-
/** A diagnostic failure is an error value, though not flagged as one. */
|
|
55
|
-
isError() {
|
|
56
|
-
return super.isError() || this.isDiagnosticFailure();
|
|
57
|
-
}
|
|
58
|
-
/** Observations preserve diagnostic failures as values. */
|
|
59
|
-
observationError() {
|
|
60
|
-
return this.isDiagnosticFailure() ? this : super.observationError();
|
|
61
|
-
}
|
|
62
52
|
/** Diagnostic notes that represent failures, rather than test progress. */
|
|
63
53
|
isDiagnosticFailure() {
|
|
64
|
-
return ["!", "
|
|
54
|
+
return ["!", ">", "-"].includes(this.data);
|
|
65
55
|
}
|
|
66
56
|
in(_contexts = [Frame.nil]) {
|
|
67
57
|
return this;
|
|
@@ -83,7 +73,10 @@ export class FrameNote extends FrameAtom {
|
|
|
83
73
|
return FrameNote.NOTE_END;
|
|
84
74
|
}
|
|
85
75
|
toString() {
|
|
86
|
-
|
|
76
|
+
const label = FrameNote.SYSTEM_ERROR_LABELS.has(this.data)
|
|
77
|
+
? "!"
|
|
78
|
+
: this.data;
|
|
79
|
+
return this.string_prefix() + label + this.meta_string();
|
|
87
80
|
}
|
|
88
81
|
setLabel(data, source) {
|
|
89
82
|
const label = FrameNote.LABELS.en[data];
|
|
@@ -137,8 +130,18 @@ Object.defineProperty(FrameNote, "LABELS", {
|
|
|
137
130
|
"-": "test-fail",
|
|
138
131
|
"~": "test-unimplemented",
|
|
139
132
|
"=": "test-summary",
|
|
140
|
-
"<>": "type-mismatch",
|
|
141
133
|
">": "bounds-exceeded",
|
|
142
134
|
},
|
|
143
135
|
}
|
|
144
136
|
});
|
|
137
|
+
/**
|
|
138
|
+
* Note labels that render as a system error, `$!.<label name>` (spec a13/14
|
|
139
|
+
* §3). Every failure the interpreter reports starts with `$!`; only the
|
|
140
|
+
* testdoc report labels keep their own sigils.
|
|
141
|
+
*/
|
|
142
|
+
Object.defineProperty(FrameNote, "SYSTEM_ERROR_LABELS", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
configurable: true,
|
|
145
|
+
writable: true,
|
|
146
|
+
value: new Set(["!", ">"])
|
|
147
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Frame } from "./frame.js";
|
|
2
|
+
import { FrameAtom } from "./frame-atom.js";
|
|
3
|
+
import { FrameString } from "./frame-string.js";
|
|
4
|
+
import { describedKind, kindOf, reasonOf } from "./error-kind.js";
|
|
5
|
+
/** A symbol's spelling, without importing `FrameSymbol` (load order). */
|
|
6
|
+
const spelling = (frame) => frame.className() === "FrameSymbol"
|
|
7
|
+
? frame.spelling()
|
|
8
|
+
: undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The observations of the handlers now running, innermost last.
|
|
11
|
+
*
|
|
12
|
+
* This relies on evaluation being synchronous: a handler runs to completion
|
|
13
|
+
* inside `during`, so pushes and pops nest exactly, and `finally` pops even
|
|
14
|
+
* when evaluation throws. Nothing in `lib/` suspends evaluation (`HCLang.call`
|
|
15
|
+
* returns a promise but evaluates synchronously before resolving it). If
|
|
16
|
+
* evaluation ever suspends while a handler runs, this stack must move into the
|
|
17
|
+
* evaluation context, or `$#` would leak into an interleaved evaluation.
|
|
18
|
+
*/
|
|
19
|
+
const running = [];
|
|
20
|
+
/**
|
|
21
|
+
* What a catch handler receives (spec a13/14 §6, §7): a non-propagating view
|
|
22
|
+
* of one error.
|
|
23
|
+
*
|
|
24
|
+
* It holds the original error, never a copy, and is not itself an error.
|
|
25
|
+
* `.!` reads the original, so answering it declines or re-raises with the
|
|
26
|
+
* same frame; `.#` reads the reason as text. Any other member is missing. It
|
|
27
|
+
* prints as `$#.reason`. A schema candidate written as an error kind matches
|
|
28
|
+
* it when the kinds agree (`$# ~ <$!.division-by-zero>`).
|
|
29
|
+
*/
|
|
30
|
+
export class FrameObservation extends FrameAtom {
|
|
31
|
+
constructor(original) {
|
|
32
|
+
super();
|
|
33
|
+
Object.defineProperty(this, "original", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: original
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** The observation of the innermost running handler, if any. */
|
|
41
|
+
static current() {
|
|
42
|
+
return running.at(-1);
|
|
43
|
+
}
|
|
44
|
+
/** Runs `body` with this as the current observation. */
|
|
45
|
+
during(body) {
|
|
46
|
+
running.push(this);
|
|
47
|
+
try {
|
|
48
|
+
return body();
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
running.pop();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The original's kind, `$!.reason` or `$!!.reason`. */
|
|
55
|
+
kind() {
|
|
56
|
+
return kindOf(this.original);
|
|
57
|
+
}
|
|
58
|
+
matchesKind(candidate) {
|
|
59
|
+
const kind = this.kind();
|
|
60
|
+
return kind !== undefined && describedKind(candidate) === kind;
|
|
61
|
+
}
|
|
62
|
+
/** `.!` is the original error, `.#` its reason; nothing else is a member. */
|
|
63
|
+
call(argument, _parameter = Frame.nil) {
|
|
64
|
+
switch (spelling(argument)) {
|
|
65
|
+
case "!":
|
|
66
|
+
return this.original;
|
|
67
|
+
case "#":
|
|
68
|
+
return new FrameString(reasonOf(this.original) ?? "");
|
|
69
|
+
default:
|
|
70
|
+
return Frame.error(`$!.name-missing ${this.toString()}${argument.toString()}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
in(_input = []) {
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
toString() {
|
|
77
|
+
return `$#.${reasonOf(this.original) ?? ""}`;
|
|
78
|
+
}
|
|
79
|
+
dataString() {
|
|
80
|
+
return this.toString();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Evaluates a handler and handles `failure` with it, both with the
|
|
85
|
+
* observation as the current `$#`. A closure is called with the observation;
|
|
86
|
+
* any other value is the replacement itself. A handler that is itself an error
|
|
87
|
+
* is the result (spec a13/12 §2.3).
|
|
88
|
+
*/
|
|
89
|
+
Frame.catchWith = (failure, evaluate) => {
|
|
90
|
+
const observation = new FrameObservation(failure);
|
|
91
|
+
return observation.during(() => {
|
|
92
|
+
const handler = evaluate();
|
|
93
|
+
if (handler.isError())
|
|
94
|
+
return handler;
|
|
95
|
+
return handler.isClosure() ? handler.call(observation) : handler;
|
|
96
|
+
});
|
|
97
|
+
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Frame } from "./frame.js";
|
|
2
2
|
import { FrameAtom } from "./frame-atom.js";
|
|
3
3
|
import { FrameNote } from "./frame-note.js";
|
|
4
|
+
import { FrameObservation } from "./frame-observation.js";
|
|
4
5
|
import { FrameSymbol } from "./frame-symbol.js";
|
|
6
|
+
import { describeAs } from "./error-kind.js";
|
|
5
7
|
import { EvaluationScope } from "./evaluation-scope.js";
|
|
6
8
|
import { ScanDisposition, } from "../scan.js";
|
|
7
|
-
|
|
9
|
+
/** The testdoc report labels, the only semicolon-delimited notes left. */
|
|
10
|
+
const NOTE_PREFIXES = new Set(["+", "-", "~", "="]);
|
|
8
11
|
const complete = (frame) => ({
|
|
9
12
|
disposition: ScanDisposition.CompleteRedispatch,
|
|
10
13
|
frame,
|
|
@@ -13,22 +16,44 @@ const invalidDollar = (source, char = "") => ({
|
|
|
13
16
|
disposition: ScanDisposition.Error,
|
|
14
17
|
message: `invalid dollar form: $${source}${char === "\n" ? "\\n" : char}`,
|
|
15
18
|
});
|
|
19
|
+
const REASON = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
20
|
+
/**
|
|
21
|
+
* An error literal is a source atom; its flag is not a lexical failure.
|
|
22
|
+
*
|
|
23
|
+
* Source code raises only user errors (spec a13/14 §1). `$!!.reason` is one.
|
|
24
|
+
* `$!.reason` names the system kind: it raises the user error with the same
|
|
25
|
+
* reason, and a schema holding it matches that system kind (§4).
|
|
26
|
+
*/
|
|
27
|
+
const errorLiteral = (source) => {
|
|
28
|
+
const user = source.startsWith("!!.");
|
|
29
|
+
const reason = source.slice(user ? 3 : 2);
|
|
30
|
+
if (!REASON.test(reason))
|
|
31
|
+
return invalidDollar(source);
|
|
32
|
+
const error = Frame.error(`$!!.${reason}`);
|
|
33
|
+
return complete(user ? error : describeAs(error, `$!.${reason}`));
|
|
34
|
+
};
|
|
16
35
|
/** A boundary starts another token rather than extending a dollar form. */
|
|
17
36
|
const isBoundary = (char) => !/[$\w-]/.test(char);
|
|
18
37
|
/**
|
|
19
|
-
* Recognizes
|
|
20
|
-
*
|
|
21
|
-
*
|
|
38
|
+
* Recognizes the dollar family behind one `$` registration: the anchors `$`,
|
|
39
|
+
* `$$` and `$#`, the catch operator `$!`, the error literals `$!.reason` and
|
|
40
|
+
* `$!!.reason`, and the testdoc report notes. Longest match keeps `$$` atomic,
|
|
41
|
+
* while unsupported `$word` forms fail on their first character instead of
|
|
42
|
+
* consuming an expression.
|
|
22
43
|
*/
|
|
23
44
|
const recognizeDollar = (symbol, source = "") => {
|
|
24
45
|
const char = symbol.toString();
|
|
25
46
|
if (source === "") {
|
|
26
|
-
if (char === "$") {
|
|
47
|
+
if (char === "$" || char === "!" || char === "#") {
|
|
27
48
|
return { disposition: ScanDisposition.Consume };
|
|
28
49
|
}
|
|
29
|
-
if (NOTE_PREFIXES.has(char)
|
|
50
|
+
if (NOTE_PREFIXES.has(char)) {
|
|
30
51
|
return { disposition: ScanDisposition.Consume };
|
|
31
52
|
}
|
|
53
|
+
// The removed `$>…;` and `$<>…;` note forms stay lexical errors rather
|
|
54
|
+
// than reading as an anchor followed by an operator.
|
|
55
|
+
if (char === "<" || char === ">")
|
|
56
|
+
return invalidDollar(source, char);
|
|
32
57
|
return isBoundary(char)
|
|
33
58
|
? complete(FrameScopeAnchor.file())
|
|
34
59
|
: invalidDollar(source, char);
|
|
@@ -40,13 +65,35 @@ const recognizeDollar = (symbol, source = "") => {
|
|
|
40
65
|
? complete(FrameScopeAnchor.host())
|
|
41
66
|
: invalidDollar(source, char);
|
|
42
67
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
68
|
+
if (source === "#") {
|
|
69
|
+
return isBoundary(char)
|
|
70
|
+
? complete(new FrameObservationAnchor())
|
|
71
|
+
: invalidDollar(source, char);
|
|
72
|
+
}
|
|
73
|
+
// `$!` is the catch operator unless a dot or a second `!` follows. A word
|
|
74
|
+
// character is the removed `$!word;` note form, so it is rejected.
|
|
75
|
+
if (source === "!") {
|
|
76
|
+
if (char === "." || char === "!") {
|
|
77
|
+
return { disposition: ScanDisposition.Consume };
|
|
78
|
+
}
|
|
79
|
+
return isBoundary(char)
|
|
80
|
+
? complete(new FrameCatch())
|
|
81
|
+
: invalidDollar(source, char);
|
|
82
|
+
}
|
|
83
|
+
if (source === "!!") {
|
|
84
|
+
return char === "."
|
|
47
85
|
? { disposition: ScanDisposition.Consume }
|
|
48
86
|
: invalidDollar(source, char);
|
|
49
87
|
}
|
|
88
|
+
if (source.startsWith("!.") || source.startsWith("!!.")) {
|
|
89
|
+
const start = source.startsWith("!!.") ? 3 : 2;
|
|
90
|
+
const accepted = source.length === start
|
|
91
|
+
? /^[A-Za-z_]$/.test(char)
|
|
92
|
+
: /^[A-Za-z0-9_-]$/.test(char);
|
|
93
|
+
return accepted
|
|
94
|
+
? { disposition: ScanDisposition.Consume }
|
|
95
|
+
: errorLiteral(source);
|
|
96
|
+
}
|
|
50
97
|
if (char === FrameNote.NOTE_END) {
|
|
51
98
|
return { disposition: ScanDisposition.CompleteRedispatch };
|
|
52
99
|
}
|
|
@@ -57,8 +104,15 @@ const finishDollar = (source = "") => {
|
|
|
57
104
|
return complete(FrameScopeAnchor.file());
|
|
58
105
|
if (source === "$")
|
|
59
106
|
return complete(FrameScopeAnchor.host());
|
|
60
|
-
if (source === "
|
|
107
|
+
if (source === "#")
|
|
108
|
+
return complete(new FrameObservationAnchor());
|
|
109
|
+
if (source === "!")
|
|
110
|
+
return complete(new FrameCatch());
|
|
111
|
+
if (source === "!!")
|
|
61
112
|
return invalidDollar(source);
|
|
113
|
+
if (source.startsWith("!.") || source.startsWith("!!.")) {
|
|
114
|
+
return errorLiteral(source);
|
|
115
|
+
}
|
|
62
116
|
return {
|
|
63
117
|
disposition: ScanDisposition.Error,
|
|
64
118
|
message: `unterminated FrameNote: $${source}`,
|
|
@@ -167,3 +221,35 @@ Object.defineProperty(FrameScopeAnchor, "SYNTAX", {
|
|
|
167
221
|
fromSource: (source) => new FrameNote(source),
|
|
168
222
|
}
|
|
169
223
|
});
|
|
224
|
+
/**
|
|
225
|
+
* The catch operator `$!` (spec a13/14 §5). It is syntax: expression
|
|
226
|
+
* reduction (`FrameExpr`) recognizes it among an expression's terms, so it
|
|
227
|
+
* never evaluates as a value of its own.
|
|
228
|
+
*/
|
|
229
|
+
export class FrameCatch extends FrameAtom {
|
|
230
|
+
in(_input = []) {
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
string_prefix() {
|
|
234
|
+
return "$!";
|
|
235
|
+
}
|
|
236
|
+
toData() {
|
|
237
|
+
return "";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* `$#`, the anchor for the observation of the innermost catch handler now
|
|
242
|
+
* running (spec a13/14 §6). Outside every handler it is an error.
|
|
243
|
+
*/
|
|
244
|
+
export class FrameObservationAnchor extends FrameAtom {
|
|
245
|
+
in(_input = []) {
|
|
246
|
+
return FrameObservation.current() ??
|
|
247
|
+
Frame.error("$!.observation-missing");
|
|
248
|
+
}
|
|
249
|
+
string_prefix() {
|
|
250
|
+
return "$#";
|
|
251
|
+
}
|
|
252
|
+
toData() {
|
|
253
|
+
return "";
|
|
254
|
+
}
|
|
255
|
+
}
|
package/esm/lib/frames/frame.js
CHANGED
|
@@ -664,8 +664,8 @@ export class Frame extends MetaFrame {
|
|
|
664
664
|
return this;
|
|
665
665
|
}
|
|
666
666
|
/**
|
|
667
|
-
* Whether this value is itself an error
|
|
668
|
-
*
|
|
667
|
+
* Whether this value is itself an error, flagged as such. A diagnostic
|
|
668
|
+
* failure such as `$!.name-missing` is flagged when constructed (#467).
|
|
669
669
|
* Unlike `isFailedResult`, it never looks inside an aggregate, and unlike
|
|
670
670
|
* `observationError`, a non-finite number or a cycle is not one: those fail
|
|
671
671
|
* to be measured, not to be computed (011.20).
|
|
@@ -802,6 +802,14 @@ export class Frame extends MetaFrame {
|
|
|
802
802
|
isEqualTo(other) {
|
|
803
803
|
return this.equals(other) === Frame.all;
|
|
804
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* Whether this frame is an observed error of the kind `candidate` names
|
|
807
|
+
* (spec a13/14 §7). Only a catch handler's observation answers yes; a
|
|
808
|
+
* schema candidate written as `$!.reason` or `$!!.reason` names the kind.
|
|
809
|
+
*/
|
|
810
|
+
matchesKind(_candidate) {
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
805
813
|
/**
|
|
806
814
|
* className returns the name of the class as a string.
|
|
807
815
|
* @returns a string
|
|
@@ -1167,3 +1175,16 @@ Object.defineProperty(Frame, "globals", {
|
|
|
1167
1175
|
writable: true,
|
|
1168
1176
|
value: Frame.missing
|
|
1169
1177
|
});
|
|
1178
|
+
/**
|
|
1179
|
+
* Handles `failure` with the catch handler that `handler` evaluates to
|
|
1180
|
+
* (spec a13/14 §5). The observation is current while the handler is both
|
|
1181
|
+
* evaluated and called. `frame-observation.ts` installs the real one when it
|
|
1182
|
+
* loads; it is late bound so that expression reduction need not import it
|
|
1183
|
+
* (load order).
|
|
1184
|
+
*/
|
|
1185
|
+
Object.defineProperty(Frame, "catchWith", {
|
|
1186
|
+
enumerable: true,
|
|
1187
|
+
configurable: true,
|
|
1188
|
+
writable: true,
|
|
1189
|
+
value: (failure) => failure
|
|
1190
|
+
});
|
package/esm/lib/frames.js
CHANGED
|
@@ -22,7 +22,8 @@ export { FrameList } from "./frames/frame-list.js";
|
|
|
22
22
|
export { FrameName } from "./frames/frame-name.js";
|
|
23
23
|
export { FrameWord } from "./frames/frame-word.js";
|
|
24
24
|
export { FrameNote } from "./frames/frame-note.js";
|
|
25
|
-
export { FrameScopeAnchor, } from "./frames/frame-scope-anchor.js";
|
|
25
|
+
export { FrameCatch, FrameObservationAnchor, FrameScopeAnchor, } from "./frames/frame-scope-anchor.js";
|
|
26
|
+
export { FrameObservation } from "./frames/frame-observation.js";
|
|
26
27
|
export { FrameNumeric, NUMERIC_RANK, } from "./frames/frame-numeric.js";
|
|
27
28
|
export { FrameInt } from "./frames/frame-int.js";
|
|
28
29
|
export { FrameCount } from "./frames/frame-count.js";
|
package/esm/lib/ops/math.js
CHANGED
|
@@ -14,8 +14,7 @@ const numeric = (source, block, operation) => {
|
|
|
14
14
|
* than nil, so a failed read such as `$!.name-missing` reaches whatever uses
|
|
15
15
|
* the result. As nil it vanished: a write of nil leaves a field unchanged, so a
|
|
16
16
|
* misread load looked like an update that never landed (011.20). Ordering
|
|
17
|
-
*
|
|
18
|
-
* that answered one would take the branch.
|
|
17
|
+
* uses the same rule: diagnostic failures now short-circuit before `?` (#467).
|
|
19
18
|
*/
|
|
20
19
|
const arithmetic = (source, block, operation) => failure(source) ?? failure(block) ?? numeric(source, block, operation);
|
|
21
20
|
/** An operand that is an error value (`Frame.isError`), unwrapped. */
|
|
@@ -45,17 +44,17 @@ export const Divide = (source, block) => arithmetic(source, block, (left, right)
|
|
|
45
44
|
export const Modulo = (source, block) => arithmetic(source, block, (left, right) => left.modulo(right));
|
|
46
45
|
export const Power = (source, block) => arithmetic(source, block, (left, right) => left.power(right));
|
|
47
46
|
export const Equals = (source, block) => {
|
|
48
|
-
return source.equals(block);
|
|
47
|
+
return failure(source) ?? failure(block) ?? source.equals(block);
|
|
49
48
|
};
|
|
50
49
|
/** `==`: the same value and the same type at every node. */
|
|
51
50
|
export const TypeEquals = (source, block) => {
|
|
52
|
-
return source.typeEquals(block);
|
|
51
|
+
return failure(source) ?? failure(block) ?? source.typeEquals(block);
|
|
53
52
|
};
|
|
54
53
|
/** `===`: the same frame. Atoms, which own no identity, fall back to `==`. */
|
|
55
54
|
export const Identical = (source, block) => {
|
|
56
|
-
return source.identical(block);
|
|
55
|
+
return failure(source) ?? failure(block) ?? source.identical(block);
|
|
57
56
|
};
|
|
58
|
-
export const GreaterThan = (source, block) =>
|
|
59
|
-
export const GreaterThanOrEqual = (source, block) =>
|
|
60
|
-
export const LessThan = (source, block) =>
|
|
61
|
-
export const LessThanOrEqual = (source, block) =>
|
|
57
|
+
export const GreaterThan = (source, block) => arithmetic(source, block, (left, right) => left.greaterThan(right));
|
|
58
|
+
export const GreaterThanOrEqual = (source, block) => arithmetic(source, block, (left, right) => left.greaterThanOrEqual(right));
|
|
59
|
+
export const LessThan = (source, block) => arithmetic(source, block, (left, right) => left.lessThan(right));
|
|
60
|
+
export const LessThanOrEqual = (source, block) => arithmetic(source, block, (left, right) => left.lessThanOrEqual(right));
|
package/esm/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.40.0";
|