From c48859717d847f4492a0c3cc76e8f8b0b38fcc10 Mon Sep 17 00:00:00 2001
From: Son Ho
Date: Wed, 13 Dec 2023 16:54:10 +0100
Subject: Update the extraction to handle casts between integers/bools

---
 backends/lean/Base/Primitives/Scalar.lean | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'backends/lean/Base/Primitives/Scalar.lean')

diff --git a/backends/lean/Base/Primitives/Scalar.lean b/backends/lean/Base/Primitives/Scalar.lean
index db522df2..a8eda6d5 100644
--- a/backends/lean/Base/Primitives/Scalar.lean
+++ b/backends/lean/Base/Primitives/Scalar.lean
@@ -411,6 +411,10 @@ def Scalar.or {ty : ScalarTy} (x : Scalar ty) (y : Scalar ty) : Scalar ty :=
 def Scalar.cast {src_ty : ScalarTy} (tgt_ty : ScalarTy) (x : Scalar src_ty) : Result (Scalar tgt_ty) :=
   Scalar.tryMk tgt_ty x.val
 
+-- This can't fail, but for now we make all casts faillible (easier for the translation)
+def Scalar.cast_bool (tgt_ty : ScalarTy) (x : Bool) : Result (Scalar tgt_ty) :=
+  Scalar.tryMk tgt_ty (if x then 1 else 0)
+
 -- The scalar types
 -- We declare the definitions as reducible so that Lean can unfold them (useful
 -- for type class resolution for instance).
-- 
cgit v1.2.3

