From 856e74cb5e2011d6d3d9dfeb2cf70b1d94188165 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 25 Oct 2021 19:57:06 -0700 Subject: [PATCH] Make eval primitive object test pass --- schala-lang/language/src/tree_walk_eval/mod.rs | 9 ++++++--- schala-lang/language/src/tree_walk_eval/test.rs | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/schala-lang/language/src/tree_walk_eval/mod.rs b/schala-lang/language/src/tree_walk_eval/mod.rs index 29a3fde..16f0cc7 100644 --- a/schala-lang/language/src/tree_walk_eval/mod.rs +++ b/schala-lang/language/src/tree_walk_eval/mod.rs @@ -136,9 +136,9 @@ enum Primitive { impl Primitive { fn to_repl(&self) -> String { match self { - Primitive::Object { type_id, items, .. } => { - format!("{}{}", type_id.local_name(), paren_wrapped(items.iter().map(|item| item.to_repl()))) - }, + Primitive::Object { type_id, items, .. } if items.len() == 0 => format!("{}", type_id.local_name()), + Primitive::Object { type_id, items, .. } => + format!("{}{}", type_id.local_name(), paren_wrapped(items.iter().map(|item| item.to_repl()))), Primitive::Literal(lit) => match lit { Literal::Nat(n) => format!("{}", n), Literal::Int(i) => format!("{}", i), @@ -258,6 +258,9 @@ impl<'a> State<'a> { Primitive::unit() }, Expression::Call { box f, args } => self.call_expression(f, args)?, + Expression::Callable(Callable::DataConstructor { type_id, arity, tag }) if arity == 0 => Primitive::Object { + type_id, tag, items: vec![] + }, Expression::Callable(func) => Primitive::Callable(func), Expression::ReductionError(e) => return Err(e.into()), }) diff --git a/schala-lang/language/src/tree_walk_eval/test.rs b/schala-lang/language/src/tree_walk_eval/test.rs index 9a67963..80e4a9c 100644 --- a/schala-lang/language/src/tree_walk_eval/test.rs +++ b/schala-lang/language/src/tree_walk_eval/test.rs @@ -70,9 +70,9 @@ fn adt_output_1() { type Option = Some(T) | None let a = Option::None let b = Option::Some(10) -(a, b) +(b, a) "#; - eval_assert(source, "(Option::None, Option::Some(10))"); + eval_assert(source, "(Some(10), None)"); } /*