From 4abe22bcf27745145882cbf9c38e3d4bc21ba162 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 23 Dec 2020 16:53:01 +0800 Subject: [PATCH] operator overload --- toy-impl/README.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/toy-impl/README.md b/toy-impl/README.md index 5e289a2..a197f01 100644 --- a/toy-impl/README.md +++ b/toy-impl/README.md @@ -21,6 +21,11 @@ for simplicity reasons: * method override check modulo variable renaming. * more complicated type guard +## Running Example +```bash +python main.py example/a.py +``` + ## Files All files named `test_xxx` are used for inspecting the result of algorithms, and can be ignored for now. @@ -198,5 +203,31 @@ This would fail. From the first argument, we have `A -> A`, and from the second argument we need `A -> B`. In general, we may have `A != B`, so there is no substitution that meets the requirement and the type check failed. -## Operator Override +## Operator Overloading +Most operations are actually implemented via operator overloading. +We currently support: +* Normal: + * `__init__` +* Comparison: + * `__lt__` + * `__le__` + * `__gt__` + * `__ge__` + * `__eq__` + * `__ne__` +* Arithmetic: + * `__add__` + * `__sub__` + * `__mul__` + * `__matmul__` + * `__truediv__` + * `__floordiv__` + * `__mod__` + * `__pow__` + * `__lshift__` + * `__rshift__` + * `__and__` + * `__or__` + * `__xor__` + * `__neg__`