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