[Snek] [keith-packard/snek] 9392ca: range_start initial value was casting through soffset

Keith Packard noreply at github.com
Fri Feb 15 19:04:21 PST 2019


  Branch: refs/heads/master
  Home:   https://github.com/keith-packard/snek
  Commit: 9392ca20fd084c8dbdeca935bd6bbf4f5171624f
      https://github.com/keith-packard/snek/commit/9392ca20fd084c8dbdeca935bd6bbf4f5171624f
  Author: Keith Packard <keithp at keithp.com>
  Date:   2019-02-14 (Thu, 14 Feb 2019)

  Changed paths:
    M snek-code.c

  Log Message:
  -----------
  range_start initial value was casting through soffset

Initial value needs to be a float not truncated to an integer. oops.

Signed-off-by: Keith Packard <keithp at keithp.com>


  Commit: 7c42d8cf2e22dfdb0253067ab38bfd85250ca932
      https://github.com/keith-packard/snek/commit/7c42d8cf2e22dfdb0253067ab38bfd85250ca932
  Author: Keith Packard <keithp at keithp.com>
  Date:   2019-02-14 (Thu, 14 Feb 2019)

  Changed paths:
    M test/Makefile
    A test/range.py

  Log Message:
  -----------
  test: range operation tests

Signed-off-by: Keith Packard <keithp at keithp.com>


  Commit: dd9a44bfddfbc4eb10f11386fd3f5f1c81550979
      https://github.com/keith-packard/snek/commit/dd9a44bfddfbc4eb10f11386fd3f5f1c81550979
  Author: Keith Packard <keithp at keithp.com>
  Date:   2019-02-15 (Fri, 15 Feb 2019)

  Changed paths:
    M snek-frame.c
    M snek-func.c
    M snek-memory.c
    M snek-name.c
    M snek-poly.c
    M snek-print.c
    M snek.h

  Log Message:
  -----------
  Don't generate -inf (0xff800000) as value of list at offset 0.

With snek_list == 0, snek_offset_to_poly(0, snek_list) looks like:

	(snek_poly_t) { .u = SNEK_EXPONENT_MASK | offset | type };

This results in a .u value of 0xff800000 (SNEK_EXPONENT_MASK), which
is the IEEE encoding for -inf.

Fixing this was 'interesting. The first change is to re-order
snek_type_t so that snek_builtin is encoding 0. Because snek_builtins
start at 1 instead of 0, there is no valid snek_builtin with all of
the IEEE mantissa bits set to zero. snek_builtin is the only
non-reference type, and the range is expected to be quite limited.

However, the code still confuses an offset of 0 with a NULL
'pointer'. To fix this, I've switched the offset representation of
NULL from 0 to ~3 -- that is, a maximum offset value with both type
bits cleared. That ends up looking like a builtin, which makes dealing
with this value in the memory code easy -- it follows the same path as
builtins, which are not references.

To keep this small enough for Arduino, I've moved some NULL checks in
memory management out of the individual types and down into the common
memory manager code.

Reported-by: fanoush
Signed-off-by: Keith Packard <keithp at keithp.com>


Compare: https://github.com/keith-packard/snek/compare/4e63d56a7b20...dd9a44bfddfb


More information about the Snek mailing list