From 3fb22c91827c7f4d6ed5b4c047fa726c7ccee7f4 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 12 Apr 2022 10:33:28 +0800 Subject: [PATCH] nac3artiq: treat host numpy.float64 as float. Closes #90 --- nac3artiq/src/lib.rs | 2 ++ nac3artiq/src/symbol_resolver.rs | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index bf5aad1d..d6ed943f 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -65,6 +65,7 @@ pub struct PrimitivePythonId { uint32: u64, uint64: u64, float: u64, + float64: u64, bool: u64, list: u64, tuple: u64, @@ -397,6 +398,7 @@ impl Nac3 { uint64: get_attr_id(numpy_mod, "uint64"), bool: get_attr_id(builtins_mod, "bool"), float: get_attr_id(builtins_mod, "float"), + float64: get_attr_id(numpy_mod, "float64"), list: get_attr_id(builtins_mod, "list"), tuple: get_attr_id(builtins_mod, "tuple"), exception: get_attr_id(builtins_mod, "Exception"), diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 609de2c3..a581ef84 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -302,6 +302,8 @@ impl InnerResolver { Ok(Ok((primitives.bool, true))) } else if ty_id == self.primitive_ids.float { Ok(Ok((primitives.float, true))) + } else if ty_id == self.primitive_ids.float64 { + Ok(Ok((primitives.float, true))) } else if ty_id == self.primitive_ids.exception { Ok(Ok((primitives.exception, true))) } else if ty_id == self.primitive_ids.list { @@ -755,7 +757,7 @@ impl InnerResolver { format!("{} is not in the range of bool", obj)))?; self.id_to_primitive.write().insert(id, PrimitiveValue::Bool(val)); Ok(Some(ctx.ctx.bool_type().const_int(val as u64, false).into())) - } else if ty_id == self.primitive_ids.float { + } else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 { let val: f64 = obj.extract().map_err(|_| super::CompileError::new_err( format!("{} is not in the range of float64", obj)))?; self.id_to_primitive.write().insert(id, PrimitiveValue::F64(val)); @@ -985,7 +987,7 @@ impl InnerResolver { } else if ty_id == self.primitive_ids.bool { let val: bool = obj.extract()?; Ok(SymbolValue::Bool(val)) - } else if ty_id == self.primitive_ids.float { + } else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 { let val: f64 = obj.extract()?; Ok(SymbolValue::Double(val)) } else if ty_id == self.primitive_ids.tuple {