From 8ab15b5f6c2e0696e1a2b50cd72632bb2f0d0622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BE=AA?= Date: Wed, 4 Dec 2024 22:03:36 +1100 Subject: [PATCH] up --- .../shared/src/main/scala/chester/eval/Eval.scala | 10 +++++++--- .../shared/src/main/scala/chester/runtime/Value.scala | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/interpreter/shared/src/main/scala/chester/eval/Eval.scala b/interpreter/shared/src/main/scala/chester/eval/Eval.scala index 53c4ebc1c..73aae4d93 100644 --- a/interpreter/shared/src/main/scala/chester/eval/Eval.scala +++ b/interpreter/shared/src/main/scala/chester/eval/Eval.scala @@ -1,10 +1,14 @@ package chester.eval import chester.runtime.Value -import chester.syntax.core.TermT +import chester.syntax.core.* case class EvalContext() -object Eval { - def evalNoEffect[T<:TermT[T]](ctx: EvalContext, code: T): Value = ??? +case class Eval[Term<:TermT[Term]]() { + type BooleanTerm = BooleanTermC[Term] + def evalNoEffect(ctx: EvalContext, code: Term): Value = code match { + case b: BooleanTerm => Value(b.value) + case _ => ??? + } } diff --git a/interpreter/shared/src/main/scala/chester/runtime/Value.scala b/interpreter/shared/src/main/scala/chester/runtime/Value.scala index 7f43500b8..d9fe60970 100644 --- a/interpreter/shared/src/main/scala/chester/runtime/Value.scala +++ b/interpreter/shared/src/main/scala/chester/runtime/Value.scala @@ -5,7 +5,11 @@ import spire.math.Rational import scala.collection.immutable.HashMap import scala.language.implicitConversions -opaque type Value = Vector[Any] | Int | BigInt | String | Symbol | HashMap[Any, Any] | Rational | Double | Function[Any, Any] -type OpenValue = Vector[Value] | Int | BigInt | String | Symbol | HashMap[Value, Value] | Rational | Double | Function[Vector[Value], Value] +opaque type Value = Vector[Any] | Boolean | Int | BigInt | String | Symbol | HashMap[Any, Any] | Rational | Double | Function[Any, Any] +type OpenValue = Vector[Value] | Boolean |Int | BigInt | String | Symbol | HashMap[Value, Value] | Rational | Double | Function[Vector[Value], Value] inline implicit def viewValue(x: Value): OpenValue = x.asInstanceOf[OpenValue] + +inline implicit def packValue(x: OpenValue): Value = x.asInstanceOf[Value] + +inline def Value(x: OpenValue | Value): Value = x.asInstanceOf[Value] \ No newline at end of file