conlang: Add Quote expression as a hack for testing
Possibly removed later, or replaced with something that turns Conlang AST nodes into Conlang data structures.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//! Values in the dynamically typed AST interpreter.
|
||||
//!
|
||||
//! The most permanent fix is a temporary one.
|
||||
use cl_ast::{format::FmtAdapter, Sym};
|
||||
use cl_ast::{format::FmtAdapter, ExprKind, Sym};
|
||||
|
||||
use super::{
|
||||
error::{Error, IResult},
|
||||
@@ -42,6 +42,8 @@ pub enum ConValue {
|
||||
Struct(Box<(Sym, HashMap<Sym, ConValue>)>),
|
||||
/// An entire namespace
|
||||
Module(Box<HashMap<Sym, Option<ConValue>>>),
|
||||
/// A quoted expression
|
||||
Quote(Box<ExprKind>),
|
||||
/// A callable thing
|
||||
Function(Rc<Function>),
|
||||
/// A built-in function
|
||||
@@ -165,6 +167,7 @@ from! {
|
||||
&str => ConValue::String,
|
||||
String => ConValue::String,
|
||||
Rc<str> => ConValue::String,
|
||||
ExprKind => ConValue::Quote,
|
||||
Function => ConValue::Function,
|
||||
Vec<ConValue> => ConValue::Tuple,
|
||||
&'static dyn BuiltIn => ConValue::BuiltIn,
|
||||
@@ -319,6 +322,9 @@ impl std::fmt::Display for ConValue {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
ConValue::Quote(q) => {
|
||||
write!(f, "`{q}`")
|
||||
}
|
||||
ConValue::Function(func) => {
|
||||
write!(f, "{}", func.decl())
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ impl Interpret for ExprKind {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
match self {
|
||||
ExprKind::Empty => Ok(ConValue::Empty),
|
||||
ExprKind::Quote(q) => q.interpret(env),
|
||||
ExprKind::Let(v) => v.interpret(env),
|
||||
ExprKind::Assign(v) => v.interpret(env),
|
||||
ExprKind::Modify(v) => v.interpret(env),
|
||||
@@ -174,6 +175,13 @@ impl Interpret for ExprKind {
|
||||
}
|
||||
}
|
||||
|
||||
impl Interpret for Quote {
|
||||
fn interpret(&self, _env: &mut Environment) -> IResult<ConValue> {
|
||||
// TODO: squoosh down into a ConValue?
|
||||
Ok(ConValue::Quote(self.quote.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
mod assignment {
|
||||
/// Pattern matching engine for assignment
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user