forked from M-Labs/nac3
1
0
Fork 0

Add handling for np.bool_ and np.str_

This commit is contained in:
David Mak 2024-06-18 14:14:12 +08:00
parent e85f4f9bd2
commit 1bc95a7ba6
2 changed files with 10 additions and 6 deletions

View File

@ -102,7 +102,9 @@ pub struct PrimitivePythonId {
float: u64, float: u64,
float64: u64, float64: u64,
bool: u64, bool: u64,
np_bool_: u64,
string: u64, string: u64,
np_str_: u64,
list: u64, list: u64,
ndarray: u64, ndarray: u64,
tuple: u64, tuple: u64,
@ -922,7 +924,9 @@ impl Nac3 {
uint32: get_attr_id(numpy_mod, "uint32"), uint32: get_attr_id(numpy_mod, "uint32"),
uint64: get_attr_id(numpy_mod, "uint64"), uint64: get_attr_id(numpy_mod, "uint64"),
bool: get_attr_id(builtins_mod, "bool"), bool: get_attr_id(builtins_mod, "bool"),
np_bool_: get_attr_id(numpy_mod, "bool_"),
string: get_attr_id(builtins_mod, "str"), string: get_attr_id(builtins_mod, "str"),
np_str_: get_attr_id(numpy_mod, "str_"),
float: get_attr_id(builtins_mod, "float"), float: get_attr_id(builtins_mod, "float"),
float64: get_attr_id(numpy_mod, "float64"), float64: get_attr_id(numpy_mod, "float64"),
list: get_attr_id(builtins_mod, "list"), list: get_attr_id(builtins_mod, "list"),

View File

@ -311,9 +311,9 @@ impl InnerResolver {
Ok(Ok((primitives.uint32, true))) Ok(Ok((primitives.uint32, true)))
} else if ty_id == self.primitive_ids.uint64 { } else if ty_id == self.primitive_ids.uint64 {
Ok(Ok((primitives.uint64, true))) Ok(Ok((primitives.uint64, true)))
} else if ty_id == self.primitive_ids.bool { } else if ty_id == self.primitive_ids.bool || ty_id == self.primitive_ids.np_bool_ {
Ok(Ok((primitives.bool, true))) Ok(Ok((primitives.bool, true)))
} else if ty_id == self.primitive_ids.string { } else if ty_id == self.primitive_ids.string || ty_id == self.primitive_ids.np_str_ {
Ok(Ok((primitives.str, true))) Ok(Ok((primitives.str, true)))
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 { } else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {
Ok(Ok((primitives.float, true))) Ok(Ok((primitives.float, true)))
@ -873,11 +873,11 @@ impl InnerResolver {
let val: u64 = obj.extract().unwrap(); let val: u64 = obj.extract().unwrap();
self.id_to_primitive.write().insert(id, PrimitiveValue::U64(val)); self.id_to_primitive.write().insert(id, PrimitiveValue::U64(val));
Ok(Some(ctx.ctx.i64_type().const_int(val, false).into())) Ok(Some(ctx.ctx.i64_type().const_int(val, false).into()))
} else if ty_id == self.primitive_ids.bool { } else if ty_id == self.primitive_ids.bool || ty_id == self.primitive_ids.np_bool_ {
let val: bool = obj.extract().unwrap(); let val: bool = obj.extract().unwrap();
self.id_to_primitive.write().insert(id, PrimitiveValue::Bool(val)); self.id_to_primitive.write().insert(id, PrimitiveValue::Bool(val));
Ok(Some(ctx.ctx.i8_type().const_int(u64::from(val), false).into())) Ok(Some(ctx.ctx.i8_type().const_int(u64::from(val), false).into()))
} else if ty_id == self.primitive_ids.string { } else if ty_id == self.primitive_ids.string || ty_id == self.primitive_ids.np_str_ {
let val: String = obj.extract().unwrap(); let val: String = obj.extract().unwrap();
self.id_to_primitive.write().insert(id, PrimitiveValue::Str(val.clone())); self.id_to_primitive.write().insert(id, PrimitiveValue::Str(val.clone()));
Ok(Some(ctx.ctx.const_string(val.as_bytes(), true).into())) Ok(Some(ctx.ctx.const_string(val.as_bytes(), true).into()))
@ -1124,10 +1124,10 @@ impl InnerResolver {
} else if ty_id == self.primitive_ids.uint64 { } else if ty_id == self.primitive_ids.uint64 {
let val: u64 = obj.extract()?; let val: u64 = obj.extract()?;
Ok(SymbolValue::U64(val)) Ok(SymbolValue::U64(val))
} else if ty_id == self.primitive_ids.bool { } else if ty_id == self.primitive_ids.bool || ty_id == self.primitive_ids.np_bool_ {
let val: bool = obj.extract()?; let val: bool = obj.extract()?;
Ok(SymbolValue::Bool(val)) Ok(SymbolValue::Bool(val))
} else if ty_id == self.primitive_ids.string { } else if ty_id == self.primitive_ids.string || ty_id == self.primitive_ids.np_str_ {
let val: String = obj.extract()?; let val: String = obj.extract()?;
Ok(SymbolValue::Str(val)) Ok(SymbolValue::Str(val))
} else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 { } else if ty_id == self.primitive_ids.float || ty_id == self.primitive_ids.float64 {