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:
2025-01-29 03:56:19 -06:00
parent 518fbe74a1
commit d21683ad61
9 changed files with 53 additions and 1 deletions

View File

@@ -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())
}

View File

@@ -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::*;