From ee5ca040c771e34eb241fce78edff1f92fdb0816 Mon Sep 17 00:00:00 2001 From: tali Date: Wed, 29 Nov 2023 16:48:24 -0500 Subject: [PATCH] add runtime value data type --- lib/runtime/value.ml | 19 +++++++++++++++++++ lib/spice.ml | 1 + 2 files changed, 20 insertions(+) create mode 100644 lib/runtime/value.ml diff --git a/lib/runtime/value.ml b/lib/runtime/value.ml new file mode 100644 index 0000000..6d471f3 --- /dev/null +++ b/lib/runtime/value.ml @@ -0,0 +1,19 @@ +type t = + | Nil + | True + | False + | Int of int64 +(* | Obj of vtable * slots *) + +let equal v1 v2 = + match v1, v2 with + | Int x, Int y -> Int64.equal x y + | _, _ -> v1 == v2 + +let to_string = function + | Nil -> "nil" + | True -> "true" + | False -> "false" + | Int n -> Int64.to_string n + +let pp ppf v = Format.pp_print_string ppf (to_string v) diff --git a/lib/spice.ml b/lib/spice.ml index 92ffb97..4d53073 100644 --- a/lib/spice.ml +++ b/lib/spice.ml @@ -1,6 +1,7 @@ module Syn = Spice_syntax.Ast module Lir = Spice_lower.Lir module Code = Spice_runtime.Code +module Value = Spice_runtime.Value exception Error of string