from nac3_types import * TBool = TObj('bool', {}, []) TInt = TObj('int', {}, []) TFloat = TObj('float', {}, []) TBool.fields['__eq__'] = TFunc([FuncArg('other', TBool, False)], TBool, []) TBool.fields['__ne__'] = TFunc([FuncArg('other', TBool, False)], TBool, []) def impl_cmp(ty): ty.fields['__lt__'] = TFunc([FuncArg('other', ty, False)], TBool, []) ty.fields['__le__'] = TFunc([FuncArg('other', ty, False)], TBool, []) ty.fields['__eq__'] = TFunc([FuncArg('other', ty, False)], TBool, []) ty.fields['__ne__'] = TFunc([FuncArg('other', ty, False)], TBool, []) ty.fields['__gt__'] = TFunc([FuncArg('other', ty, False)], TBool, []) ty.fields['__ge__'] = TFunc([FuncArg('other', ty, False)], TBool, []) def impl_arithmetic(ty): ty.fields['__add__'] = TFunc([FuncArg('other', ty, False)], ty, []) ty.fields['__sub__'] = TFunc([FuncArg('other', ty, False)], ty, []) ty.fields['__mul__'] = TFunc([FuncArg('other', ty, False)], ty, []) impl_cmp(TInt) impl_cmp(TFloat) impl_arithmetic(TInt) impl_arithmetic(TFloat) TNum = TVar([TInt, TFloat]) TInt.fields['__truediv__'] = TFunc( [FuncArg('other', TNum, False)], TFloat, [TNum]) TInt.fields['__floordiv__'] = TFunc( [FuncArg('other', TNum, False)], TInt, [TNum]) TFloat.fields['__truediv__'] = TFunc( [FuncArg('other', TNum, False)], TFloat, [TNum]) TFloat.fields['__floordiv__'] = TFunc( [FuncArg('other', TNum, False)], TFloat, [TNum])