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:
@@ -126,6 +126,24 @@ pub enum Expr {
|
||||
fields: Vec<(String, Expr)>,
|
||||
span: Span,
|
||||
},
|
||||
/// Record update: `a with { field: new_val }`
|
||||
With {
|
||||
base: Box<Expr>,
|
||||
updates: Vec<(String, Expr)>,
|
||||
},
|
||||
/// AI inference: `reason "query"`
|
||||
Reason {
|
||||
query: String,
|
||||
},
|
||||
/// Concurrent execution: `parallel { name: expr, ... }`
|
||||
Parallel {
|
||||
entries: Vec<(String, Expr)>,
|
||||
},
|
||||
/// Trace block: `trace "label" { stmts }`
|
||||
Trace {
|
||||
label: String,
|
||||
body: Vec<Stmt>,
|
||||
},
|
||||
}
|
||||
|
||||
// ── Match arm ─────────────────────────────────────────────────────────────────
|
||||
@@ -198,7 +216,7 @@ pub enum Stmt {
|
||||
Return(Expr, Span),
|
||||
/// A bare expression used as a statement (usually a call).
|
||||
Expr(Expr, Span),
|
||||
/// `fn name<T, E>(params) -> ReturnType { body }` (with optional decorators)
|
||||
/// `fn name<T, E>(params) -> ReturnType [requires cond] { body }` (with optional decorators)
|
||||
FnDef {
|
||||
name: String,
|
||||
decorators: Vec<Decorator>,
|
||||
@@ -206,6 +224,8 @@ pub enum Stmt {
|
||||
type_params: Vec<String>,
|
||||
params: Vec<Param>,
|
||||
return_type: TypeExpr,
|
||||
/// Optional precondition: `requires expr`
|
||||
requires: Option<Box<Expr>>,
|
||||
body: Vec<Stmt>,
|
||||
span: Span,
|
||||
},
|
||||
@@ -252,6 +272,20 @@ pub enum Stmt {
|
||||
methods: Vec<Stmt>,
|
||||
span: Span,
|
||||
},
|
||||
/// `retry N times { ... } fallback { ... }`
|
||||
Retry {
|
||||
count: Expr,
|
||||
body: Vec<Stmt>,
|
||||
fallback: Option<Vec<Stmt>>,
|
||||
span: Span,
|
||||
},
|
||||
/// `deploy fn_name to "/route" via target`
|
||||
Deploy {
|
||||
fn_name: String,
|
||||
route: String,
|
||||
target: String,
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
// ── Top-level program ─────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user