Parse functions, calls, returns, branches, loops, tables, and imports so marqdo run passes the examples gold suite (M2–M4). Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1021 B
Rust
43 lines
1021 B
Rust
//! Runtime values (Phase I).
|
|
|
|
use std::fmt;
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub enum Value {
|
|
None,
|
|
Bool(bool),
|
|
Int(i64),
|
|
Text(String),
|
|
/// Single-column table rows (v0); multi-column later.
|
|
List(Vec<Value>),
|
|
}
|
|
|
|
impl Value {
|
|
pub fn truthy(&self) -> bool {
|
|
match self {
|
|
Value::None => false,
|
|
Value::Bool(b) => *b,
|
|
Value::Int(n) => *n != 0,
|
|
Value::Text(s) => !s.is_empty(),
|
|
Value::List(xs) => !xs.is_empty(),
|
|
}
|
|
}
|
|
|
|
pub fn as_display(&self) -> String {
|
|
match self {
|
|
Value::None => "None".into(),
|
|
Value::Bool(true) => "True".into(),
|
|
Value::Bool(false) => "False".into(),
|
|
Value::Int(n) => n.to_string(),
|
|
Value::Text(s) => s.clone(),
|
|
Value::List(_) => "<list>".into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for Value {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(f, "{}", self.as_display())
|
|
}
|
|
}
|