cl-interpret: Tuple structs + fix tuple member access
This commit is contained in:
		@@ -6,7 +6,8 @@ use cl_ast::{format::FmtAdapter, ExprKind, Sym};
 | 
			
		||||
use super::{
 | 
			
		||||
    builtin::Builtin,
 | 
			
		||||
    error::{Error, IResult},
 | 
			
		||||
    function::Function, Callable, Environment,
 | 
			
		||||
    function::Function,
 | 
			
		||||
    Callable, Environment,
 | 
			
		||||
};
 | 
			
		||||
use std::{collections::HashMap, ops::*, rc::Rc};
 | 
			
		||||
 | 
			
		||||
@@ -40,6 +41,8 @@ pub enum ConValue {
 | 
			
		||||
    RangeInc(Integer, Integer),
 | 
			
		||||
    /// A value of a product type
 | 
			
		||||
    Struct(Box<(Sym, HashMap<Sym, ConValue>)>),
 | 
			
		||||
    /// A value of a product type with anonymous members
 | 
			
		||||
    TupleStruct(Box<(Sym, Box<[ConValue]>)>),
 | 
			
		||||
    /// An entire namespace
 | 
			
		||||
    Module(Box<HashMap<Sym, Option<ConValue>>>),
 | 
			
		||||
    /// A quoted expression
 | 
			
		||||
@@ -298,6 +301,20 @@ impl std::fmt::Display for ConValue {
 | 
			
		||||
                }
 | 
			
		||||
                ')'.fmt(f)
 | 
			
		||||
            }
 | 
			
		||||
            ConValue::TupleStruct(parts) => {
 | 
			
		||||
                let (name, tuple) = parts.as_ref();
 | 
			
		||||
                if !name.is_empty() {
 | 
			
		||||
                    write!(f, "{name}")?;
 | 
			
		||||
                }
 | 
			
		||||
                '('.fmt(f)?;
 | 
			
		||||
                for (idx, element) in tuple.iter().enumerate() {
 | 
			
		||||
                    if idx > 0 {
 | 
			
		||||
                        ", ".fmt(f)?
 | 
			
		||||
                    }
 | 
			
		||||
                    element.fmt(f)?
 | 
			
		||||
                }
 | 
			
		||||
                ')'.fmt(f)
 | 
			
		||||
            }
 | 
			
		||||
            ConValue::Struct(parts) => {
 | 
			
		||||
                let (name, map) = parts.as_ref();
 | 
			
		||||
                use std::fmt::Write;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user