diff --git a/README.md b/README.md index fca4beb..5e12f51 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ - [Why Coderive?](#why-coderive) - [Getting Started](#getting-started) - [Language Features](#language-features) +- [Latest in src](#latest-in-src) +- [Validation Snapshot](#validation-snapshot) - [Examples](#examples) - [Web Playground](#web-playground) - [License](#license) @@ -330,6 +332,39 @@ out(report) --- +## Latest in src + +Recent `src/**/*.cod` programs and std modules now showcase: + +- **Unsafe pointers and fixed buffers** (`*T`, `T[n]`, `&`, `*`, pointer arithmetic) in `test/unsafe/*`. +- **Static imports** for methods/fields in `test/staticimports*`. +- **Lambda auto-currying** forms like `\(a) \(b) ...` plus classic tuple lambdas in `test/lambda/*`. +- **Union + runtime type checks** via `int|text` and `is` in `test/typesliterals/*`. +- **Range and formula optimizations** across lazy arrays, multi-array dependencies, and recurrence tests. +- **Expanded standard library coverage** in `std/math`, `std/scimath`, and `std/json` with comprehensive demo suites. + +--- + +## Validation Snapshot + +Current demo validation status from `src/main/cod/demo/src/main/test`: + +- `CodP-TAC parity runner` (`cod.runner.CodPTACParityRunner`, excluding `*Invalid*.cod`): **48/48 passed**. +- `LazyLoop.cod` parity: **passed**. +- Direct `CommandRunner` scans (same non-invalid set) highlight remaining runtime limitations: + - `LazyLoop.cod` previously hit a stack overflow error during conditional-formula-style parity value reads. This update fixes the runtime recursion issue without changing demo behavior. + - `ConditionalFormulaOptimization.cod` can still trigger a stack overflow error. + - Input-driven demos (`Interactive.cod`, `IO.cod`, `Parity.cod`) fail without real stdin values. + - `HelloWorld.cod`, `JsonStandardLibraryComprehensive.cod`, `OOPConstructor.cod`, `SuperThis.cod`, and `test/unsafe/*` currently expose parser/runtime issues when executed directly via `CommandRunner`. + +Checked invalid demos (`*Invalid*.cod`) confirm currently unsupported/invalid patterns: + +- Reassigning constants after declaration. +- Declaring constants without initializer. +- Malformed self-call forms (`<~` without call target/parentheses, or invalid level-call syntax in methods). + +--- + ## Examples The [`examples/`](examples/) directory has ready-to-run programs: diff --git a/src/main/java/cod/interpreter/handler/AssignmentHandler.java b/src/main/java/cod/interpreter/handler/AssignmentHandler.java index 4a326bb..c1ad5f2 100644 --- a/src/main/java/cod/interpreter/handler/AssignmentHandler.java +++ b/src/main/java/cod/interpreter/handler/AssignmentHandler.java @@ -189,7 +189,7 @@ private Object handleIndexAssignment(IndexAccess indexAccess, Object newValue, E NaturalArray natural = (NaturalArray) arrayObj; long index = expressionHandler.toLongIndex(indexObj); ensureNoActiveBorrow(arrayObj, index, ctx); - Object previous = natural.get(index); + Object previous = natural.peekMaterialized(index); natural.set(index, newValue); ctx.trackValueReplacement(previous, newValue); return newValue; diff --git a/src/main/java/cod/range/NaturalArray.java b/src/main/java/cod/range/NaturalArray.java index bc572ab..b2ae161 100644 --- a/src/main/java/cod/range/NaturalArray.java +++ b/src/main/java/cod/range/NaturalArray.java @@ -773,11 +773,7 @@ public Object get(long index) { index = size + index; } - try { - checkBounds(index); - } catch (ProgramError e) { - throw e; - } + checkBounds(index); // ========== TRACKING ========== if (tracked) { @@ -879,6 +875,27 @@ public Object get(long index, boolean withConversion) { return value; } + /** + * Returns a previously materialized value for an index without triggering + * formula evaluation. + */ + public Object peekMaterialized(long index) { + if (index < 0) { + long size = size(); + index = size + index; + } + + checkBounds(index); + + if (isMutable && cache != null && cache.containsKey(index)) { + return cache.get(index); + } + if (computedCache != null && computedCache.containsKey(index)) { + return computedCache.get(index); + } + return null; + } + // Convert value to string based on its type private Object convertToString(Object value) { if (value == null) return "none";