diff --git a/.husky/pre-commit b/.husky/pre-commit
old mode 100644
new mode 100755
diff --git a/BUILDING.md b/BUILDING.md
index 5e031fea..6e90c8a6 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -40,6 +40,22 @@ npm run build
`scripts/build-vendor.sh` clones and builds static archives for libgc, cJSON, libuv, tree-sitter, and libwebsockets into `vendor/`. It's idempotent — re-running skips already-built libraries.
+## Run
+
+After building, the compiler is available as a Node.js script:
+
+```bash
+node dist/chad-node.js build hello.ts -o hello
+./hello
+```
+
+For a ~10x faster compiler, build the native binary once:
+
+```bash
+node dist/chad-node.js build src/chad-native.ts -o .build/chad
+# Now tests and scripts auto-use .build/chad instead of node dist/chad-node.js
+```
+
## Verify
```bash
@@ -95,11 +111,13 @@ bash scripts/build-target-sdk.sh
## Self-Hosting (Stage 0)
-ChadScript can compile its own compiler to a native binary:
+ChadScript can compile its own compiler to a native binary (this is what `scripts/self-hosting.sh` automates):
```bash
-chad build src/chad-native.ts -o /tmp/chad-stage0
+# Stage 0: Node.js compiler produces a native binary
+node dist/chad-node.js build src/chad-native.ts -o /tmp/chad-stage0
+# Stage 1: that native binary recompiles itself
/tmp/chad-stage0 build src/chad-native.ts -o /tmp/chad-stage1
```
diff --git a/c_bridges/yyjson-bridge.c b/c_bridges/yyjson-bridge.c
index ac230206..f7393046 100644
--- a/c_bridges/yyjson-bridge.c
+++ b/c_bridges/yyjson-bridge.c
@@ -104,6 +104,20 @@ void *csyyjson_create_obj(void) {
return (void *)doc;
}
+void *csyyjson_create_arr(void) {
+ yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
+ if (!doc) return NULL;
+ yyjson_mut_val *root = yyjson_mut_arr(doc);
+ if (!root) { yyjson_mut_doc_free(doc); return NULL; }
+ yyjson_mut_doc_set_root(doc, root);
+ return (void *)doc;
+}
+
+void *csyyjson_mut_arr_add_obj(void *doc, void *arr) {
+ if (!doc || !arr) return NULL;
+ return (void *)yyjson_mut_arr_add_obj((yyjson_mut_doc *)doc, (yyjson_mut_val *)arr);
+}
+
void *csyyjson_mut_get_root(void *doc) {
if (!doc) return NULL;
return (void *)yyjson_mut_doc_get_root((yyjson_mut_doc *)doc);
diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts
index 1a900d3b..797473e1 100644
--- a/docs/.vitepress/config.mts
+++ b/docs/.vitepress/config.mts
@@ -17,13 +17,6 @@ export default defineConfig({
languages: [llvmGrammar],
},
- transformPageData(pageData) {
- const mdPath = path.resolve(__dirname, '..', pageData.relativePath)
- try {
- pageData.frontmatter.__rawMarkdown = fs.readFileSync(mdPath, 'utf-8')
- } catch {}
- },
-
themeConfig: {
search: {
provider: 'local'
@@ -40,11 +33,11 @@ export default defineConfig({
{
text: 'Getting Started',
items: [
- { text: 'Language Support', link: '/language/limitations' },
+ { text: 'About ChadScript', link: '/language/architecture' },
{ text: 'Installation', link: '/getting-started/installation' },
{ text: 'Examples', link: '/getting-started/quickstart' },
- { text: 'How it Works', link: '/language/architecture' },
{ text: 'CLI Reference', link: '/getting-started/cli' },
+ { text: 'Supported Features', link: '/language/limitations' },
{ text: 'Debugging', link: '/getting-started/debugging' }
]
},
@@ -84,12 +77,6 @@ export default defineConfig({
{ text: 'Benchmarks', link: '/benchmarks' }
]
},
- {
- text: 'Resources',
- items: [
- { text: 'FAQ', link: '/faq' }
- ]
- }
],
socialLinks: [
diff --git a/docs/.vitepress/theme/CopyMarkdown.vue b/docs/.vitepress/theme/CopyMarkdown.vue
index 291cdc84..a2d7087e 100644
--- a/docs/.vitepress/theme/CopyMarkdown.vue
+++ b/docs/.vitepress/theme/CopyMarkdown.vue
@@ -1,29 +1,49 @@
+
diff --git a/docs/.vitepress/theme/ExampleTabs.vue b/docs/.vitepress/theme/ExampleTabs.vue
index 5c9b27a3..1ef0381d 100644
--- a/docs/.vitepress/theme/ExampleTabs.vue
+++ b/docs/.vitepress/theme/ExampleTabs.vue
@@ -19,9 +19,18 @@ const examples = [
{
label: 'HTTP Server',
file: 'server.ts',
- code: `ChadScript.embedDir("./public");
+ code: `// Static files baked into the binary at compile time
+ChadScript.embedDir("./public");
+
+const posts = [{ id: 1, title: "Hello World", likes: 42 }];
function handleRequest(req: HttpRequest): HttpResponse {
+ // JSON REST API
+ if (req.path === "/api/posts") {
+ return { status: 200, body: JSON.stringify(posts), headers: "" };
+ }
+ // Fallback: serve embedded static files (.html, .css, etc.)
+ // Content-Type is inferred from the file extension
return ChadScript.serveEmbedded(req.path);
}
@@ -57,18 +66,18 @@ sqlite.close(db);`,
async function main() {
const results = await Promise.all([
- fetch("https://api.github.com/repos/cs01/ChadScript"),
+ fetch("https://api.github.com/repos/vuejs/vue"),
fetch("https://api.github.com/repos/facebook/react"),
]);
- const cs = JSON.parse(results[0].text());
+ const vue = JSON.parse(results[0].text());
const react = JSON.parse(results[1].text());
- console.log("ChadScript: " + cs.stargazers_count + " stars");
+ console.log("Vue: " + vue.stargazers_count + " stars");
console.log("React: " + react.stargazers_count + " stars");
}
main();`,
run: '$ chad run stars.ts',
- output: `ChadScript: mass stars\nReact: 235k stars`,
+ output: `Vue: 208k stars\nReact: 235k stars`,
},
]
diff --git a/docs/.vitepress/theme/IRShowcase.vue b/docs/.vitepress/theme/IRShowcase.vue
index bfcbb4db..5c1056f4 100644
--- a/docs/.vitepress/theme/IRShowcase.vue
+++ b/docs/.vitepress/theme/IRShowcase.vue
@@ -1,77 +1,24 @@
+
+