Implement Phase I tree-walk interpreter for all examples.
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>
This commit is contained in:
1 parent
69b626e919
commit
a29bf6e97b
12 files changed
+1791
-61
No files matched your search
@@ -0,0 +1,42 @@
|
||||
//! 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())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user