Summary
L3 from the DVM-BASIC language agenda (P1): first-class RAM arrays — DIM a(n) AS type, a[i] get/set, arrlen. Gives contracts list semantics instead of hand-rolled scalar keys, and composes with L1's FOR loops for iteration.
The syntax
DIM a(10) AS Uint64 ' zero-filled array, indices 0..10 (cap 1024)
LET a[0] = 10
LET a[1] = 20
LET a[2] = a[0] + a[1] ' expression index works too (loop vars)
RETURN arrlen("a") ' 11
With L1's FOR:
FOR i = 0 TO 10
LET a[i] = i * i
NEXT i
Implementation
Variable gains Array *[]Variable — a pointer so Variable stays comparable (it's used as a map key in RamStore/SC state; a raw slice would break compilation).
DIM a(n) AS Uint64|String — detects the ( n ) form in interpret_DIM, allocates n+1 zero-filled elements, cap 1024.
a[i] read — new *ast.IndexExpr case in the evaluator (Go's parser already tokenizes a [ i ]).
LET a[i] = expr — new branch in interpret_LET; the index is evaluated (literal or expression like a loop variable), with bounds checking.
arrlen("a") — intrinsic returning the length, gated >= 10.0.0.
Consensus safety
- Arrays are Locals-only: contracts cannot
STORE an array (STORE takes scalars), so arrays never touch the serialized SC state — consensus-neutral (no state-format change).
- Gated
>= 10.0.0 like L1/L2 — pre-fork contracts can't use it.
Tests (dvm/control_flow_l3_test.go, 4 cases)
| Test |
Verifies |
TestL3_ArrayBasics |
set/read/compute + arrlen |
TestL3_ArrayForLoop |
L1+L3 compose: sum of squares 0..10 = 385 |
TestL3_StringArray |
string arrays |
TestL3_VersionGate |
DIM a(n) at 1.2.3 rejected |
Full dvm suite green.
Relationship
Branch: feature/dvm-l3-arrays in the fork liqdmetal/derohe-improvements-by-liqdmetal (stacked on feature/dvm-l2-subroutines).
Summary
L3 from the DVM-BASIC language agenda (P1): first-class RAM arrays —
DIM a(n) AS type,a[i]get/set,arrlen. Gives contracts list semantics instead of hand-rolled scalar keys, and composes with L1'sFORloops for iteration.The syntax
With L1's FOR:
Implementation
VariablegainsArray *[]Variable— a pointer so Variable stays comparable (it's used as a map key inRamStore/SC state; a raw slice would break compilation).DIM a(n) AS Uint64|String— detects the( n )form ininterpret_DIM, allocatesn+1zero-filled elements, cap 1024.a[i]read — new*ast.IndexExprcase in the evaluator (Go's parser already tokenizesa [ i ]).LET a[i] = expr— new branch ininterpret_LET; the index is evaluated (literal or expression like a loop variable), with bounds checking.arrlen("a")— intrinsic returning the length, gated>= 10.0.0.Consensus safety
STOREan array (STORE takes scalars), so arrays never touch the serialized SC state — consensus-neutral (no state-format change).>= 10.0.0like L1/L2 — pre-fork contracts can't use it.Tests (
dvm/control_flow_l3_test.go, 4 cases)TestL3_ArrayBasicsarrlenTestL3_ArrayForLoopTestL3_StringArrayTestL3_VersionGateDIM a(n)at1.2.3rejectedFull dvm suite green.
Relationship
>= 10.0.0gate and interpreter machinerymapkeysa natural return typeBranch:
feature/dvm-l3-arraysin the forkliqdmetal/derohe-improvements-by-liqdmetal(stacked onfeature/dvm-l2-subroutines).