finish engram-lang: protocols, decorators, imports, Result, closures, stdlib, integration tests

This commit is contained in:
Will Anderson
2026-04-27 20:22:23 -05:00
parent 316c0a85ce
commit c427a0adc0
32 changed files with 2878 additions and 32 deletions
+25
View File
@@ -16,6 +16,13 @@ pub enum Value {
Nil,
/// A list of values (used for `activate` results and array literals).
List(Vec<Value>),
/// A key-value map — used for struct instances and Map<K,V> literals.
/// Stored as a Vec of pairs to keep ordering and remain Serialize-friendly.
Map(Vec<(String, Value)>),
/// A Result<T,E> value — Ok variant.
ResultOk(Box<Value>),
/// A Result<T,E> value — Err variant.
ResultErr(Box<Value>),
}
impl std::fmt::Display for Value {
@@ -30,6 +37,12 @@ impl std::fmt::Display for Value {
let items: Vec<_> = vs.iter().map(|v| v.to_string()).collect();
write!(f, "[{}]", items.join(", "))
}
Value::Map(pairs) => {
let items: Vec<_> = pairs.iter().map(|(k, v)| format!("{k}: {v}")).collect();
write!(f, "{{{}}}", items.join(", "))
}
Value::ResultOk(v) => write!(f, "Ok({v})"),
Value::ResultErr(e) => write!(f, "Err({e})"),
}
}
}
@@ -89,6 +102,13 @@ pub enum Bytecode {
GetField(String),
/// Index into an array: pops index then array.
GetIndex,
/// Build a Map from the top N key-value pairs on the stack
/// (keys are strings pushed as Str, values follow each key).
BuildMap(u32),
/// Build a struct instance: pop N field values (named by fields in order), push Map.
BuildStruct { type_name: String, fields: Vec<String> },
/// Set a field on the Map on top of stack.
SetField(String),
// ── Special ───────────────────────────────────────────────────────────────
/// `activate TypeName "query"` — emit a semantic query stub.
@@ -132,6 +152,11 @@ impl std::fmt::Display for Bytecode {
Bytecode::JumpIfNot(off) => write!(f, "JUMPIFNOT {off:+}"),
Bytecode::GetField(n) => write!(f, "GETFIELD {n}"),
Bytecode::GetIndex => write!(f, "GETINDEX"),
Bytecode::BuildMap(n) => write!(f, "BUILDMAP {n}"),
Bytecode::BuildStruct { type_name, fields } => {
write!(f, "BUILDSTRUCT {type_name} [{}]", fields.join(", "))
}
Bytecode::SetField(n) => write!(f, "SETFIELD {n}"),
Bytecode::Activate { type_name, query } => {
write!(f, "ACTIVATE {type_name} \"{query}\"")
}