Sfoglia il codice sorgente

fully force tuples before printing

Getty Ritter 2 anni fa
parent
commit
39ec2574f9
1 ha cambiato i file con 16 aggiunte e 0 eliminazioni
  1. 16 0
      src/interp.rs

+ 16 - 0
src/interp.rs

@@ -270,6 +270,7 @@ impl State {
         match stmt {
             Stmt::Puts(expr) => {
                 let val = self.eval(*expr, &None)?;
+                let val = self.force(val)?;
                 println!("{}", val.to_string());
             }
 
@@ -323,6 +324,21 @@ impl State {
         Ok(())
     }
 
+    fn force(&self, val: Value) -> Result<Value, Error> {
+        match val {
+            Value::Tup(values) => {
+                Ok(Value::Tup(values.into_iter().map(|t| {
+                    if let Thunk::Expr(e, env) = t {
+                        Ok(Thunk::Value(self.eval(e, &env)?))
+                    } else {
+                        Ok(t)
+                    }
+                }).collect::<Result<Vec<Thunk>, Error>>()?))
+            }
+            _ => Ok(val),
+        }
+    }
+
     fn eval(&self, expr_ref: ExprRef, env: &Env) -> Result<Value, Error> {
         let expr = &self.ast.borrow()[expr_ref];
         match expr {