Commit 89c8694
Path D: array writes (ArrSetNamed, ArrayIndexAssign) + cross-fn float
Adds mutable array writes to the dual-band JIT. Combined with
Path A.4's read support, JIT'd OMC fns can now build, fill, and
read arrays of arbitrary content within a single fn call —
unlocking the build-then-process pattern that most numerical
algorithms use (including the harmonic libraries).
What's new:
- Op::ArrSetNamed(name) handler: optimized form the compiler
emits for `arr_set(name, idx, val)`. Pops value+index, looks
up the named array slot, GEPs slot+1 (skip length prefix),
stores value. Pushes a placeholder (0) on stack so the
trailing Pop the compiler emits doesn't underflow.
- Op::ArrayIndexAssign(name) handler: same semantics, used for
`name[idx] = val` syntax. No placeholder push (statement form).
- New helper emit_array_set_named consolidates both. Loads the
array's pointer from the named slot's <2 x i64>, extracts α
(the i64-bit-pattern pointer), inttoptr, GEP, store value's α.
Beta semantics on writes: the value's β is discarded. Arrays
hold scalar α only; reads via ArrayIndex splat back into matched
(α, α) bands. This is a deliberate MVP choice — true β tracking
through arrays would need parallel storage or a wider element
type. The "harmonic array" type stays open as future work.
Tests added (3 total):
- jit_array_write_with_arr_set: build squares array via arr_set
in a loop, verify a known slot
- jit_array_write_then_sum: build squares, then sum them. Verifies
sum_of_squares(10) = 285, sum_of_squares(5) = 30
- cross_fn_float_passing: documents the structural cross-fn-float
capability AND its limitation: callee with untyped params emits
Op::Add (int) on the float bit-pattern, producing wrong values.
Cross-fn float math today requires explicit conversion at the
fn boundary via to_int/to_float, OR statically-typed parameters
in the OMC compiler (which is a separate compiler-side task).
What's still NOT covered:
- Op::ArrPushNamed (dynamic resize): our arrays are stack alloca
with fixed length-at-NewArray-time. Push would need malloc/realloc
or pre-allocated capacity. Out of scope for this MVP.
- Op::SafeArrSetNamed (H.5.2 self-healing variant): folds the
index to nearest Fibonacci attractor and Euclidean-mods by length.
Unused in the harmonic libs we want to JIT, so deferred.
- Cross-fn float passing where callee untyped: same compiler-side
story as Path A.2's missing DivFloat — requires the bytecode
compiler to emit AddFloat/SubFloat/MulFloat when call-site type
info is available.
Workspace: 41 codegen tests pass (1 IR + 4 cross-fn + 6 arrays
+ 5 dual-band + 5 dispatch + 4 floats + 3 harmony + 5 phi_shadow
+ 8 scalar). Smoke + harmonic-lib + 149 core tests still green.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 8db4dc2 commit 89c8694
3 files changed
Lines changed: 208 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
395 | 420 | | |
396 | 421 | | |
397 | 422 | | |
| |||
837 | 862 | | |
838 | 863 | | |
839 | 864 | | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
840 | 944 | | |
841 | 945 | | |
842 | 946 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 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 | + | |
92 | 150 | | |
93 | 151 | | |
94 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 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 | + | |
80 | 126 | | |
81 | 127 | | |
82 | 128 | | |
| |||
0 commit comments