Add pipe operator, with-update, retry/fallback, reason, parallel, trace, contract, deploy

Implements 8 new language features:
- |> pipe operator: a |> f desugars to f(a), left-associative chains
- with record update: let b = a with { field: val } — non-destructive struct update
- retry/fallback: retry N times { ... } fallback { ... } with counter-based loop codegen
- reason: AI inference primitive calling soma /v1/chat/completions at runtime
- parallel: concurrent execution block returning a Map of named results via threads
- trace: zero-cost observability block emitting TraceBegin/TraceEnd with ms timing
- requires: precondition annotation on fn, emits ContractCheck bytecode at entry
- deploy: deployment-as-syntax posting to soma /v1/deploy at runtime

All features thread through lexer → parser/AST → codegen → runtime interpreter.
This commit is contained in:
Will Anderson
2026-04-28 12:04:45 -05:00
parent f2202e0e5e
commit afd99f5e0d
10 changed files with 868 additions and 59 deletions
+52
View File
@@ -194,6 +194,28 @@ impl Formatter {
}
}
}
Stmt::Retry { count, body, fallback, .. } => {
out.push_str(&format!("{ind}retry "));
self.fmt_expr(out, count, depth);
out.push_str(" times {\n");
for s in body {
self.fmt_stmt(out, s, depth + 1);
}
out.push_str(&format!("{ind}}}"));
if let Some(fb) = fallback {
out.push_str(" fallback {\n");
for s in fb {
self.fmt_stmt(out, s, depth + 1);
}
out.push_str(&format!("{ind}}}"));
}
out.push('\n');
}
Stmt::Deploy { fn_name, route, target, .. } => {
out.push_str(&format!("{ind}deploy {fn_name} to \"{route}\" via {target}\n"));
}
}
}
@@ -339,6 +361,36 @@ impl Formatter {
out.push_str(&fields_str.join(", "));
out.push_str(" }");
}
Expr::With { base, updates } => {
self.fmt_expr(out, base, depth);
out.push_str(" with { ");
for (k, v) in updates {
out.push_str(&format!("{k}: "));
self.fmt_expr(out, v, depth);
out.push_str(", ");
}
out.push('}');
}
Expr::Reason { query } => {
out.push_str(&format!("reason {:?}", query));
}
Expr::Parallel { entries } => {
out.push_str("parallel { ");
for (name, e) in entries {
out.push_str(&format!("{name}: "));
self.fmt_expr(out, e, depth);
out.push_str(", ");
}
out.push('}');
}
Expr::Trace { label, body } => {
out.push_str(&format!("trace {:?} {{\n", label));
for s in body {
self.fmt_stmt(out, s, depth + 1);
}
out.push_str(&format!("{}}}", self.indent(depth)));
}
}
}