QUERY · ISSUE
Viper bug: integers > 0x3fffffff appear as python objects
bug
The bug presumably is a result of the same logic as the now closed #8956 (perhaps the fix is also as simple).
Integers outside the mpy small int range ( > 0x3fffffff) are handled as python objects in viper.
This rather should happen with integers > 0xffffffff.
Code to illustrate the issue:
# @micropython.viper
# def largeint(a) -> int:
# b = a & 0xfffffffe
# return b # -> ViperTypeError: return expected 'int' but got 'object'
# print(largeint(3))
@micropython.viper
def largeint2(a):
b = a & 0xfffffffe # works, but b is now a python object rather than a viper integer
return b
print(largeint2(3))
gv = b'\x03\x00\x00\x00'
@micropython.viper
def and32(p:ptr32):
p[0] = p[0] & 0xfffffffe # -> ViperTypeError: can't do binary op between 'int' and 'object'
# but works with 0x3ffffffe and with int(0xfffffffe)
print('Before: ', int.from_bytes(gv, 'little')) # -> 3
and32(gv)
print('After: ', int.from_bytes(gv, 'little')) # should be 2, but does not work
CANDIDATE · ISSUE
viper: ViperTypeError: can't do binary op between 'uint' and 'uint'
The following produces the above error at compile time (only with uints - compiles and runs with int)
@micropython.viper
def foo(arg1: uint, arg2: uint) -> uint:
return arg1 + arg2
MicroPython v1.6-35-ge372e83 on 2016-02-11; PYBv1.0 with STM32F405RG