Add diagnostics spans, CLI/view input feeding, and len/str/int builtins.

Unify bytecode errors with path:line:col, support --stdin-file and live view preset stdin, and ship the S0 standard library with gold coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-04 17:26:09 +08:00
1 parent 31a4b69bbd
commit 30cd39fd8f
25 files changed
+964 -111

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
//! Built-in helpers shared by tree-walk and bytecode.
use crate::value::Value;
/// `len`: text → Unicode scalar count; list → element count.
pub fn builtin_len(v: &Value) -> Result<i64, String> {
match v {
Value::Text(s) => Ok(s.chars().count() as i64),
Value::List(xs) => Ok(xs.len() as i64),
_ => Err("len needs text or list".into()),
}
}
/// `str`: display conversion (same surface as `print`).
pub fn builtin_str(v: &Value) -> Value {
Value::Text(v.as_display())
}
/// `int`: Int passthrough; Bool → 0/1; Text → parse trimmed decimal.
pub fn builtin_int(v: &Value) -> Result<i64, String> {
match v {
Value::Int(n) => Ok(*n),
Value::Bool(true) => Ok(1),
Value::Bool(false) => Ok(0),
Value::Text(s) => {
let t = s.trim();
t.parse::<i64>()
.map_err(|_| format!("cannot convert to int: {s:?}"))
}
_ => Err("int needs int, bool, or text".into()),
}
}