micropython/micropython — pull request #311 by pfalcon (2014-02-18 19:45:24+00:00)
Title: Towards support full range of small ints in bytecode

So, one issue we have is:

~~~~
>>> 10000000
micropython: ../py/emitbc.c:146: emit_write_byte_code_byte_int: Assertion `0 <= num && num <= 0xffffff' failed.
Aborted
~~~~

Encoding of int's apparently should be consistent with encoding of uint's. Then this patch tries to support encoding arbitrary uint's (and regardless of its bitsize). Let me know if you like and I clean it up (tests pass with it).

Then beyond uint's, varlen encoding for ints has its peculiarities. Note that I don't think that static biasing like you emit_write_byte_code_byte_int() with num += 0x800000 helps here. It turns "short" 0 in a big long value for example (I guess that's why you didn't make it varlen encoded, just static 3-byte). Obvious way to overcome that is to use "sign + magnitude" encoding (like floats), but that requires extra magic to handle MIN_INT, so I'd hope that some smart sign management allow to store two's complement still...