From 007843c1ef30ded1de3e0b1927870fb99ca7380b Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 5 Jan 2021 13:21:39 +0800 Subject: [PATCH] added aug assign for primitives --- nac3core/src/primitives.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/nac3core/src/primitives.rs b/nac3core/src/primitives.rs index e7777491..ced24da3 100644 --- a/nac3core/src/primitives.rs +++ b/nac3core/src/primitives.rs @@ -17,8 +17,11 @@ fn impl_math(def: &mut TypeDef, ty: &Type) { result: result.clone(), }; def.methods.insert("__add__", fun.clone()); + def.methods.insert("__iadd__", fun.clone()); def.methods.insert("__sub__", fun.clone()); + def.methods.insert("__isub__", fun.clone()); def.methods.insert("__mul__", fun.clone()); + def.methods.insert("__imul__", fun.clone()); def.methods.insert( "__neg__", FnDef { @@ -33,9 +36,21 @@ fn impl_math(def: &mut TypeDef, ty: &Type) { result: Some(PrimitiveType(FLOAT_TYPE).into()), }, ); + if ty.as_ref() == &PrimitiveType(FLOAT_TYPE) { + def.methods.insert( + "__itruediv__", + FnDef { + args: vec![ty.clone()], + result: Some(PrimitiveType(FLOAT_TYPE).into()), + }, + ); + } def.methods.insert("__floordiv__", fun.clone()); + def.methods.insert("__ifloordiv__", fun.clone()); def.methods.insert("__mod__", fun.clone()); - def.methods.insert("__pow__", fun); + def.methods.insert("__imod__", fun.clone()); + def.methods.insert("__pow__", fun.clone()); + def.methods.insert("__ipow__", fun); } fn impl_bits(def: &mut TypeDef, ty: &Type) {