Skip to content

add chadscript/* stdlib module resolution (router, argparse, http-utils)#79

Merged
cs01 merged 2 commits intomainfrom
worktree-chadscript-stdlib
Mar 2, 2026
Merged

add chadscript/* stdlib module resolution (router, argparse, http-utils)#79
cs01 merged 2 commits intomainfrom
worktree-chadscript-stdlib

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 2, 2026

ChadScript stdlib module resolution

Summary

Adds chadscript/* module namespace for accessing built-in stdlib modules. Moves router, argparse, and http-utils from scattered source locations into a cohesive lib/ directory and implements module resolution in both JS and native compilers.

Changes

Module Reorganization

  • Moved to lib/: router.ts, http-utils.ts (previously in src/)
  • Symlink: lib/argparse.tssrc/argparse.ts (eliminates duplication, single source of truth)
  • Imports updated: All examples and tests now use import { ... } from "chadscript/*"

Compiler Support

JS compiler (compiler.ts):

  • Resolves chadscript/* imports using __libDir from import.meta.url
  • Falls back to relative paths for local development

Native compiler (src/chad-native.ts + native-compiler-lib.ts):

  • Calls registerStdlib() at startup to register embedded stdlib files
  • Uses ChadScript.embedFile() to load lib files
  • Linker embeds stdlib files into native binary via -Wl,-sectcreate

TypeScript Config

  • Added tsconfig.json paths mapping for stdlib modules
  • Ensures IDE autocomplete and type checking work with chadscript/* imports

Files Modified

  • examples/cli-parser-demo.ts, examples/hackernews/app.ts, examples/http-server.ts, examples/string-search.ts, examples/websocket/app.ts, examples/word-count.ts
  • tests/fixtures/network/router-params.ts
  • lib/argparse.ts (symlink), lib/router.ts, lib/http-utils.ts
  • src/compiler.ts (module resolution)
  • src/native-compiler-lib.ts (stdlib registration)
  • src/chad-native.ts (startup registration)
  • tsconfig.json (path mappings)

Test Status

Run: npm run verify (or npm run verify:quick)

  • Unit tests: ✅ All pass
  • Self-hosting: ✅ Tested (native compiler can compile itself with embedded stdlib)

Benefits

  • Cleaner imports: import { Router } from "chadscript/router" vs relative paths
  • Discoverable: IDE autocomplete for stdlib modules
  • Maintainable: Single source of truth for stdlib files (symlink + embedded in native)
  • Extensible: Easy to add new stdlib modules to lib/

cs01 added 2 commits March 2, 2026 10:23
moves router.ts and http-utils.ts to lib/, symlinks lib/argparse.ts to src/argparse.ts.
both js and native compilers resolve chadscript/* imports: js uses __libDir from
import.meta.url, native uses registerStdlib/ChadScript.embedFile at startup.
@cs01 cs01 merged commit e9a6306 into main Mar 2, 2026
12 checks passed
@cs01 cs01 deleted the worktree-chadscript-stdlib branch March 2, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant