Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/cod/range/NaturalArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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";
Expand Down