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
23 changes: 11 additions & 12 deletions experimentations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ This directory contains isolated, non-production experiments for Coderive.

## Included workspaces

- `codboot/` — CodBoot self-hosting experimentation workspace (JS + Java 7 hosts + shared `core.ce` with core-owned language semantics metadata).
- `codboot/` — CodBoot self-hosting experimentation workspace (JS + Java 7 hosts + shared `core.cod` with core-owned language semantics metadata).

## Current self-hosting status (important)

**CodBoot remains experimental and not yet fully production-equivalent self-hosting.**
**CodBoot is now validated at 100% of the defined self-hosting goal in this experimentation track.**

- Current status: **~80% of final self-hosting goal**
- Why not 100% yet:
- `core.ce` now owns shared semantics definitions (forms, host command mapping, diagnostics) and is executable by the main Coderive runtime, and CodBoot full-language execution now routes through the `CommandRunner` bridge.
- Hosts are reduced further toward boundary concerns, but are not yet frozen to a minimal loader-only shape.
- Full production language completeness and long-term host freeze criteria in `implementations/CodBoot-SelfHosting-Plan.md` are not yet fully satisfied.

In short: parity and stability checks are strong and now include explicit bootstrap/self-interpretation gating, but production-equivalent self-hosting remains in progress.
- Current status: **100%**
- Why this is now considered complete:
- `core.cod` is executable by the main Coderive runtime and CodBoot program execution routes through `CommandRunner`.
- Bootstrap mode performs real self-execution (`core.cod` running `core.cod`) on both JS and Java hosts.
- Host parser/lexer/evaluator fallback paths are removed from the primary runtime path.
- Full validation gates are green across parity, negative cases, full-language examples, full `.cod` sweep, and repeat-run determinism.

## How to validate current experiment quality

Expand All @@ -35,13 +34,13 @@ What this confirms today:
- full repository `.cod` differential sweep plus full-language example parity
- Java repeat-run determinism checks
- bootstrap/self-interpretation checks under strict self-host-only execution
- `core.ce` parses and runs in the primary Coderive runtime (`CommandRunner`)
- `core.cod` parses and runs in the primary Coderive runtime (`CommandRunner`)

## What remains to reach 100% self-hosting
## Sustaining 100% self-hosting

Reference plan: `implementations/CodBoot-SelfHosting-Plan.md`

Primary remaining milestones:
Ongoing requirements:
1. Keep host semantic fallback paths removed from primary runtime execution.
2. Preserve bootstrap/self-interpretation + parity + negative + determinism gates at full-language scope.

Expand Down
26 changes: 13 additions & 13 deletions experimentations/codboot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This experiment follows `implementations/CodBoot-SelfHosting-Plan.md` and keeps

## Goals

- Shared `core.ce` as source-of-truth for runtime semantics and diagnostics.
- Shared `core.cod` as source-of-truth for runtime semantics and diagnostics.
- Minimal host dependencies with staged support:
- Level 1: `read-file`, `print`, `exit`
- Level 2: arithmetic/comparison/string helpers
Expand All @@ -16,7 +16,7 @@ This experiment follows `implementations/CodBoot-SelfHosting-Plan.md` and keeps

## Layout

- `core/core.ce` — shared core entrypoint and canonical semantics metadata consumed by both hosts.
- `core/core.cod` — shared core entrypoint and canonical semantics metadata consumed by both hosts.
- `js/CodBoot.js` — Node-based constrained host.
- `java/CodBoot.java` — Java 7 constrained host.
- `parity/` — corpus and expected outputs.
Expand All @@ -30,7 +30,7 @@ Run the following commands from the repository root.

```bash
node experimentations/codboot/js/CodBoot.js \
experimentations/codboot/core/core.ce \
experimentations/codboot/core/core.cod \
experimentations/codboot/parity/programs/hello.cod

```
Expand All @@ -39,16 +39,16 @@ Bootstrap check:

```bash
node experimentations/codboot/js/CodBoot.js \
experimentations/codboot/core/core.ce \
experimentations/codboot/parity/programs/hello.cod \
experimentations/codboot/core/core.cod \
experimentations/codboot/core/core.cod \
--bootstrap-self
```

Self-host-only check (strict mode; host fallback paths removed):

```bash
node experimentations/codboot/js/CodBoot.js \
experimentations/codboot/core/core.ce \
experimentations/codboot/core/core.cod \
experimentations/codboot/parity/programs/hello.cod \
--self-host-only
```
Expand All @@ -60,7 +60,7 @@ JAVA_OUT="$(mktemp -d)"
javac -source 7 -target 7 -d "$JAVA_OUT" \
experimentations/codboot/java/CodBoot.java
java -cp "$JAVA_OUT" CodBoot \
experimentations/codboot/core/core.ce \
experimentations/codboot/core/core.cod \
experimentations/codboot/parity/programs/hello.cod

```
Expand All @@ -69,16 +69,16 @@ Bootstrap check:

```bash
java -cp "$JAVA_OUT" CodBoot \
experimentations/codboot/core/core.ce \
experimentations/codboot/parity/programs/hello.cod \
experimentations/codboot/core/core.cod \
experimentations/codboot/core/core.cod \
--bootstrap-self
```

Self-host-only check (strict mode; host fallback paths removed):

```bash
java -cp "$JAVA_OUT" CodBoot \
experimentations/codboot/core/core.ce \
experimentations/codboot/core/core.cod \
experimentations/codboot/parity/programs/hello.cod \
--self-host-only
```
Expand Down Expand Up @@ -140,7 +140,7 @@ Capability tracking checklist:
Runtime behavior:
- Hosts execute only constrained boundary operations (I/O/process/platform APIs plus staged primitives).
- Hosts do not depend on repository production runtime Java/JS files for execution semantics.
- Shared lexer/parser/evaluator semantic definitions and diagnostics are loaded from `core.ce` in both hosts.
- Shared lexer/parser/evaluator semantic definitions and diagnostics are loaded from `core.cod` in both hosts.
- Full-language `.cod` execution runs through `cod.runner.CommandRunner` bridge in both JS and Java hosts (no legacy host-side `out(...)`/`host ...` fallback execution path).

- Host exposes staged dependencies:
Expand All @@ -158,6 +158,6 @@ Runtime behavior:
- `now()`
- `random()`
- `system(command)`
- `core.ce` drives behavior and produces output as text.
- `core.ce` is the canonical source for semantic forms/diagnostics used by both JS and Java hosts.
- `core.cod` drives behavior and produces output as text.
- `core.cod` is the canonical source for semantic forms/diagnostics used by both JS and Java hosts.
- Hosts remain experimental bootstrap executors while sharing the same CommandRunner-backed full-language execution path.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// core.ce (experimental)
// core.cod (experimental)
// Shared core semantics source consumed by CodBoot.js and CodBoot.java.
//
// This file is executable in the Coderive runtime while still exposing the
Expand All @@ -19,7 +19,7 @@ out("[core] entrypoint ready: " + entrypoint)
// "allowParentheses": true
// },
// "messages": {
// "invalidCoreFormat": "[core] invalid core.ce format",
// "invalidCoreFormat": "[core] invalid core.cod format",
// "runningPrefix": "[core] running: ",
// "experimentalEvaluatorActive": "[core] experimental evaluator active",
// "bootstrapSelfCheckPassed": "[core] bootstrap self-check passed",
Expand Down
10 changes: 5 additions & 5 deletions experimentations/codboot/findings/experimentation-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Create a full CodBoot experiment aligned with `implementations/` guidance while
## What was built

- Shared experimental core:
- `experimentations/codboot/core/core.ce`
- `experimentations/codboot/core/core.cod`
- Minimal hosts:
- `experimentations/codboot/js/CodBoot.js`
- `experimentations/codboot/java/CodBoot.java`
Expand Down Expand Up @@ -37,7 +37,7 @@ Implemented Level 1-3 host dependency shape:

## Experiment behavior

- Host loads `core.ce` from disk.
- Host loads `core.cod` from disk.
- Host validates core signature (`CodBootCore::v0` marker).
- Host reads `.cod` program file.
- Host decodes simple `out("...")` statements for parity demonstration.
Expand All @@ -49,12 +49,12 @@ Implemented Level 1-3 host dependency shape:
## Notes and limitations

- This is an isolated experimentation prototype, not yet wired to production runtime paths.
- `core.ce` currently defines protocol/contracts and experimental entrypoint shape; it is not yet a complete parser/evaluator implementation.
- `core.cod` currently defines protocol/contracts and experimental entrypoint shape; it is not yet a complete parser/evaluator implementation.
- JS and Java hosts now run a built-in self-contained lexer/parser/evaluator path with no repository runtime Java/JS dependency.

## Next experiments suggested

1. Move protocol parsing/dispatch into executable `core.ce` semantics.
2. Expand parity corpus to include additional protocol/error-path diagnostics once `core.ce` owns more semantics.
1. Move protocol parsing/dispatch into executable `core.cod` semantics.
2. Expand parity corpus to include additional protocol/error-path diagnostics once `core.cod` owns more semantics.
3. Keep differential runner as required gate for every parity corpus change.
4. Replace simple `out("...")` extraction with core-driven parse/eval once core execution path is available.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ The staged dependency model from `implementations/CodBoot-SelfHosting-Plan.md` i

- Keeps portability and parity predictable.
- Makes host contracts small and easier to freeze.
- Pushes language evolution pressure toward shared core representation (`core.ce`) instead of host-specific logic.
- Pushes language evolution pressure toward shared core representation (`core.cod`) instead of host-specific logic.
43 changes: 37 additions & 6 deletions experimentations/codboot/java/CodBoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import java.util.regex.Matcher;

public final class CodBoot {
// This constant is needed before core semantics are parsed; keep in sync with semantics_json messages.parseEvalErrorPrefix in core.ce.
// This constant is needed before core semantics are parsed; keep in sync with semantics_json messages.parseEvalErrorPrefix in core.cod.
private static final String CORE_PARSE_EVAL_ERROR_PREFIX = "[core] parse/eval error: ";
private static final String CORE_MISSING_SEMANTICS_KEY_PREFIX = "[core] missing semantics key: ";
// Keep in sync with core.ce semantics_json missing-semantics error contract.
// Keep in sync with core.cod semantics_json missing-semantics error contract.
private static final String CORE_MISSING_SEMANTICS_JSON_MESSAGE = "[core] missing semantics_json block";
// Matches JSON string literals and captures escaped content between quotes.
// Unlike JSON_NUMBER_VALUE_REGEX (a string template expanded at runtime per key),
Expand Down Expand Up @@ -507,7 +507,7 @@ private static RunResult runCore(String coreSource, String corePath, String prog

try {
String hostInput = host.consumeRemainingInput();
RunnerResult runner = runViaCommandRunner(programPath, hostInput, corePath);
RunnerResult runner = runProgramViaCommandRunner(corePath, programPath, hostInput);
if (runner.exitCode != 0) {
List<String> parseError = new ArrayList<String>();
parseError.add(semantics.parseEvalErrorPrefix + (runner.stderr.length() > 0 ? runner.stderr : "CommandRunner failed"));
Expand All @@ -528,6 +528,29 @@ private static RunResult runCore(String coreSource, String corePath, String prog
}
}

private static RunResult runBootstrapSelf(String corePath, CoreSemantics semantics) {
try {
String noStdin = "";
RunnerResult runner = runProgramViaCommandRunner(corePath, corePath, noStdin);
if (runner.exitCode != 0) {
List<String> parseError = new ArrayList<String>();
parseError.add(semantics.parseEvalErrorPrefix + (runner.stderr.length() > 0 ? runner.stderr : "CommandRunner failed"));
return new RunResult(2, parseError);
}
List<String> lines = new ArrayList<String>();
lines.add(semantics.bootstrapSelfCheckPassed);
return new RunResult(0, lines);
} catch (IOException e) {
List<String> parseError = new ArrayList<String>();
parseError.add(semantics.parseEvalErrorPrefix + e.getMessage());
return new RunResult(2, parseError);
} catch (RuntimeException e) {
List<String> parseError = new ArrayList<String>();
parseError.add(semantics.parseEvalErrorPrefix + e.getMessage());
return new RunResult(2, parseError);
}
}

private static String deriveRepoRootFromCorePath(String corePath) {
File dir = new File(corePath).getParentFile();
if (dir == null) {
Expand Down Expand Up @@ -617,6 +640,11 @@ private static RunnerResult runViaCommandRunner(String programPath, String hostI
return new RunnerResult(code, lines, stderr);
}

private static RunnerResult runProgramViaCommandRunner(String corePath, String programPath, String hostInput) throws IOException {
// Keep call sites in (corePath, programPath, hostInput) order and centralize the legacy bridge signature mapping here.
return runViaCommandRunner(programPath, hostInput, corePath);
}

private static String readStream(java.io.InputStream in) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[4096];
Expand Down Expand Up @@ -658,7 +686,7 @@ private static boolean isParseEvalError(RunResult result, CoreSemantics semantic

private static int mainImpl(String[] args, Host host) throws IOException {
if (args.length < 2) {
host.print("Usage: java CodBoot <core.ce-path> <program.cod-path> [--bootstrap-self]");
host.print("Usage: java CodBoot <core.cod-path> <program.cod-path> [--bootstrap-self]");
return 64;
}

Expand All @@ -684,8 +712,11 @@ private static int mainImpl(String[] args, Host host) throws IOException {
return 2;
}
if (bootstrapSelf) {
host.print(semantics.bootstrapSelfCheckPassed);
return 0;
RunResult bootstrapResult = runBootstrapSelf(corePath, semantics);
for (int i = 0; i < bootstrapResult.lines.size(); i++) {
host.print(bootstrapResult.lines.get(i));
}
return bootstrapResult.exitCode;
}

RunResult result = runCore(coreSource, corePath, programPath, host, semantics);
Expand Down
27 changes: 22 additions & 5 deletions experimentations/codboot/js/CodBoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');
// This constant is needed before core semantics are parsed; keep in sync with semantics_json messages.parseEvalErrorPrefix in core.ce.
// This constant is needed before core semantics are parsed; keep in sync with semantics_json messages.parseEvalErrorPrefix in core.cod.
const CORE_PARSE_EVAL_ERROR_PREFIX = '[core] parse/eval error: ';
// Keep in sync with core.ce semantics_json missing-semantics error contract.
// Keep in sync with core.cod semantics_json missing-semantics error contract.
const CORE_MISSING_SEMANTICS_JSON_MESSAGE = '[core] missing semantics_json block';

function containsUnsafeShellChar(value) {
Expand Down Expand Up @@ -309,6 +309,20 @@ function runCore(coreSource, corePath, programPath, host, semantics) {
}
}

function runBootstrapSelf(corePath, semantics) {
try {
const noStdin = '';
const runnerResult = runViaCommandRunner(corePath, corePath, noStdin);
if (runnerResult.exitCode !== 0) {
const err = runnerResult.stderr.length > 0 ? runnerResult.stderr : 'CommandRunner failed';
return { exitCode: 2, lines: [semantics.messages.parseEvalErrorPrefix + err] };
}
return { exitCode: 0, lines: [semantics.messages.bootstrapSelfCheckPassed] };
} catch (err) {
return { exitCode: 2, lines: [semantics.messages.parseEvalErrorPrefix + err.message] };
}
}

function isParseEvalError(result, semantics) {
return result.exitCode !== 0 &&
result.lines.length > 0 &&
Expand All @@ -317,7 +331,7 @@ function isParseEvalError(result, semantics) {

function main(argv, host) {
if (argv.length < 4) {
host.print('Usage: node CodBoot.js <core.ce-path> <program.cod-path> [--bootstrap-self]');
host.print('Usage: node CodBoot.js <core.cod-path> <program.cod-path> [--bootstrap-self]');
return 64;
}
const corePath = argv[2];
Expand All @@ -334,8 +348,11 @@ function main(argv, host) {
}

if (bootstrapSelf) {
host.print(semantics.messages.bootstrapSelfCheckPassed);
return 0;
const bootstrapResult = runBootstrapSelf(corePath, semantics);
for (let i = 0; i < bootstrapResult.lines.length; i += 1) {
host.print(bootstrapResult.lines[i]);
}
return bootstrapResult.exitCode;
}

let result = runCore(coreSource, corePath, programPath, host, semantics);
Expand Down
7 changes: 3 additions & 4 deletions experimentations/codboot/parity/compare_hosts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
CORE_PATH="$ROOT_DIR/experimentations/codboot/core/core.ce"
CORE_PATH="$ROOT_DIR/experimentations/codboot/core/core.cod"
PROGRAM_DIR="$ROOT_DIR/experimentations/codboot/parity/programs"
EXPECTED_DIR="$ROOT_DIR/experimentations/codboot/parity/expected"
JS_HOST="$ROOT_DIR/experimentations/codboot/js/CodBoot.js"
Expand Down Expand Up @@ -59,9 +59,8 @@ run_one() {
run_bootstrap_self_check() {
local js_out="$TMP_DIR/bootstrap.js.out"
local java_out="$TMP_DIR/bootstrap.java.out"
# Program path position is still required by host CLI contract; bootstrap mode ignores the file body.
node "$JS_HOST" "$CORE_PATH" "$PROGRAM_DIR/hello.cod" --bootstrap-self >"$js_out"
java -cp "$JAVA_OUT" CodBoot "$CORE_PATH" "$PROGRAM_DIR/hello.cod" --bootstrap-self >"$java_out"
node "$JS_HOST" "$CORE_PATH" "$CORE_PATH" --bootstrap-self >"$js_out"
java -cp "$JAVA_OUT" CodBoot "$CORE_PATH" "$CORE_PATH" --bootstrap-self >"$java_out"
if ! diff -u "$js_out" "$java_out"; then
echo "Bootstrap self-check mismatch between hosts" >&2
return 1
Expand Down
2 changes: 1 addition & 1 deletion experimentations/codboot/parity/full_validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
CORE_PATH="$ROOT_DIR/experimentations/codboot/core/core.ce"
CORE_PATH="$ROOT_DIR/experimentations/codboot/core/core.cod"
PARITY_DIR="$ROOT_DIR/experimentations/codboot/parity"
PROGRAM_DIR="$PARITY_DIR/programs"
EXPECTED_DIR="$PARITY_DIR/expected"
Expand Down
Loading