Move stdlib out of spec — clean spec/library boundary

spec/ now contains only the language definition (5 files):
  evaluator.sx, parser.sx, primitives.sx, render.sx, special-forms.sx

lib/ contains code written IN the language (8 files):
  stdlib.sx, types.sx, freeze.sx, content.sx,
  bytecode.sx, compiler.sx, vm.sx, callcc.sx

Test files follow source: spec/tests/ for core language tests,
lib/tests/ for library tests (continuations, freeze, types, vm).

Updated all consumers:
- JS/Python/OCaml bootstrappers: added lib/ to source search paths
- OCaml bridge: spec_dir for parser/render, lib_dir for compiler/freeze
- JS test runner: scans spec/tests/ (always) + lib/tests/ (--full)
- OCaml test runner: scans spec/tests/, lib tests via explicit request
- Docker dev mounts: added ./lib:/app/lib:ro

Tests: 1041 JS standard, 1322 JS full, 1101 OCaml — all pass

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-24 23:18:30 +00:00
parent 50871780a3
commit f3f70cc00b
26 changed files with 109 additions and 64 deletions

View File

@@ -70,10 +70,11 @@ def compile_ref_to_js(
"""
from datetime import datetime, timezone
# Source directories: core spec and web framework
# Source directories: core spec, standard library, web framework
_source_dirs = [
os.path.join(_PROJECT, "spec"), # Core spec
os.path.join(_PROJECT, "web"), # Web framework
os.path.join(_PROJECT, "spec"), # Core language spec
os.path.join(_PROJECT, "lib"), # Standard library (stdlib, compiler, vm, ...)
os.path.join(_PROJECT, "web"), # Web framework
]
bridge = _get_bridge()

View File

@@ -270,6 +270,7 @@ env["pop-suite"] = function() {
// Load test framework
const projectDir = path.join(__dirname, "..", "..");
const specTests = path.join(projectDir, "spec", "tests");
const libTests = path.join(projectDir, "lib", "tests");
const webTests = path.join(projectDir, "web", "tests");
const frameworkSrc = fs.readFileSync(path.join(specTests, "test-framework.sx"), "utf8");
@@ -278,17 +279,17 @@ for (const expr of frameworkExprs) {
Sx.eval(expr, env);
}
// Load compiler + VM spec when running full tests
// Load compiler + VM from lib/ when running full tests
if (fullBuild) {
const specDir = path.join(projectDir, "spec");
for (const specFile of ["bytecode.sx", "compiler.sx", "vm.sx"]) {
const specPath = path.join(specDir, specFile);
if (fs.existsSync(specPath)) {
const src = fs.readFileSync(specPath, "utf8");
const libDir = path.join(projectDir, "lib");
for (const libFile of ["bytecode.sx", "compiler.sx", "vm.sx"]) {
const libPath = path.join(libDir, libFile);
if (fs.existsSync(libPath)) {
const src = fs.readFileSync(libPath, "utf8");
const exprs = Sx.parse(src);
for (const expr of exprs) {
try { Sx.eval(expr, env); } catch (e) {
console.error(`Error loading ${specFile}: ${e.message}`);
console.error(`Error loading ${libFile}: ${e.message}`);
}
}
}
@@ -300,28 +301,32 @@ const args = process.argv.slice(2).filter(a => !a.startsWith("--"));
let testFiles = [];
if (args.length > 0) {
// Specific test files
// Specific test files — search spec, lib, and web test dirs
for (const arg of args) {
const name = arg.endsWith(".sx") ? arg : `${arg}.sx`;
const specPath = path.join(specTests, name);
const libPath = path.join(libTests, name);
const webPath = path.join(webTests, name);
if (fs.existsSync(specPath)) testFiles.push(specPath);
else if (fs.existsSync(libPath)) testFiles.push(libPath);
else if (fs.existsSync(webPath)) testFiles.push(webPath);
else console.error(`Test file not found: ${name}`);
}
} else {
// Tests requiring optional modules (only run with --full)
const requiresFull = new Set(["test-continuations.sx", "test-continuations-advanced.sx", "test-types.sx", "test-freeze.sx", "test-vm.sx"]);
// All spec tests
// All spec tests (core language — always run)
for (const f of fs.readdirSync(specTests).sort()) {
if (f.startsWith("test-") && f.endsWith(".sx") && f !== "test-framework.sx") {
if (!fullBuild && requiresFull.has(f)) {
console.log(`Skipping ${f} (requires --full)`);
continue;
}
testFiles.push(path.join(specTests, f));
}
}
// Library tests (only with --full — require compiler, vm, signals, etc.)
if (fullBuild) {
for (const f of fs.readdirSync(libTests).sort()) {
if (f.startsWith("test-") && f.endsWith(".sx")) {
testFiles.push(path.join(libTests, f));
}
}
}
}
// Run tests