Add server-side builtins, import system, and http_serve for Neuron Code rewrite
- Import resolution: resolve_imports() pre-processes import statements by reading and concatenating referenced .el files before compilation - http_serve builtin: tiny_http-based server on configurable port; POST /axon/message stores request in __request__ state, invokes handle_request entry point via sub-interpreter, reads __response__ state for reply - New builtins: blake3_hash, uuid_new, fs_list_recursive, fs_mkdir, fs_exists, path_join, path_parent, str_trim, str_contains, str_replace, str_starts_with, str_ends_with, str_last_index_of, json_get, json_array_push, json_array_len, now_millis, http_get, http_post, int_to_str - Catch-all arms in el-types and el-compiler for new AST variants (Import, ProtocolDef, ImplDef, Closure, Try, MapLiteral, TypeExpr::Result, TypeExpr::Map) - Parser: decorators field on FnDef, import/protocol/impl parsing
This commit is contained in:
@@ -55,6 +55,10 @@ pub enum TypeExpr {
|
||||
Optional(Box<TypeExpr>),
|
||||
/// A function type: `fn(A, B) -> C`
|
||||
Fn { params: Vec<TypeExpr>, return_type: Box<TypeExpr> },
|
||||
/// `Result<T, E>` — built-in error-propagation type
|
||||
Result { ok: Box<TypeExpr>, err: Box<TypeExpr> },
|
||||
/// `Map<K, V>` — built-in key-value map type
|
||||
Map { key: Box<TypeExpr>, value: Box<TypeExpr> },
|
||||
}
|
||||
|
||||
// ── Patterns (for match arms) ─────────────────────────────────────────────────
|
||||
@@ -103,6 +107,17 @@ pub enum Expr {
|
||||
Path { segments: Vec<String> },
|
||||
/// Index expression: `arr[0]`
|
||||
Index { object: Box<Expr>, index: Box<Expr> },
|
||||
/// Closure: `|x: Int| x * 2` or `|x: Int| -> Int { x * 2 }`
|
||||
Closure {
|
||||
params: Vec<Param>,
|
||||
return_type: Option<TypeExpr>,
|
||||
body: Box<Expr>,
|
||||
span: Span,
|
||||
},
|
||||
/// Try operator: `expr?` — unwraps Result, propagates error
|
||||
Try(Box<Expr>),
|
||||
/// Map literal: `{"key": value, ...}`
|
||||
MapLiteral(Vec<(Expr, Expr)>),
|
||||
}
|
||||
|
||||
// ── Match arm ─────────────────────────────────────────────────────────────────
|
||||
@@ -114,6 +129,27 @@ pub struct MatchArm {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
// ── Decorators ────────────────────────────────────────────────────────────────
|
||||
|
||||
/// A decorator applied to a function: `@name` or `@name(args)`
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Decorator {
|
||||
pub name: String,
|
||||
pub args: Vec<Expr>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
// ── Protocol ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/// A method signature inside a protocol definition.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ProtocolMethod {
|
||||
pub name: String,
|
||||
pub params: Vec<Param>,
|
||||
pub return_type: TypeExpr,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
// ── Statements ────────────────────────────────────────────────────────────────
|
||||
|
||||
/// A named parameter in a function definition.
|
||||
@@ -154,9 +190,10 @@ pub enum Stmt {
|
||||
Return(Expr, Span),
|
||||
/// A bare expression used as a statement (usually a call).
|
||||
Expr(Expr, Span),
|
||||
/// `fn name(params) -> ReturnType { body }`
|
||||
/// `fn name(params) -> ReturnType { body }` (with optional decorators)
|
||||
FnDef {
|
||||
name: String,
|
||||
decorators: Vec<Decorator>,
|
||||
params: Vec<Param>,
|
||||
return_type: TypeExpr,
|
||||
body: Vec<Stmt>,
|
||||
@@ -185,6 +222,26 @@ pub enum Stmt {
|
||||
Seed(SeedStmt, Span),
|
||||
/// `assert <expr>`
|
||||
Assert(Expr, Span),
|
||||
/// `import std::collections::Map` or `from pkg import { A, B }`
|
||||
Import {
|
||||
path: Vec<String>,
|
||||
names: Vec<String>,
|
||||
alias: Option<String>,
|
||||
span: Span,
|
||||
},
|
||||
/// `protocol Name { method sigs... }`
|
||||
ProtocolDef {
|
||||
name: String,
|
||||
methods: Vec<ProtocolMethod>,
|
||||
span: Span,
|
||||
},
|
||||
/// `impl Protocol for TypeName { fn ... }`
|
||||
ImplDef {
|
||||
protocol_name: String,
|
||||
type_name: String,
|
||||
methods: Vec<Stmt>,
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
// ── Top-level program ─────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user