interim icon indicating copy to clipboard operation
interim copied to clipboard

Divide by zero crashes

Open mathias opened this issue 9 years ago • 1 comments

Hello!

I haven't yet gotten this booting on a RaspPi 2 (waiting for it to arrive) but I am having fun running it on my Mac.

I did notice that divide by 0 crashes sledge, and currently only integers are supported.

What kind of numeric support are you planning? Is there a particular place where I could start looking at expanding it?

Thanks in advance!

mathias avatar Oct 01 '15 23:10 mathias

Thanks for your feedback, mathias. I'm planning to include double-precision 64-bit IEEE 754 floating point numbers. This opens many questions of how and when to convert between fp and integers (probably always explicitly).

To implement a new type like TAG_FLOAT, you need to:

  • add a TAG_FLOAT constant in minilisp.h (they are currently power-of-two-ints, but this can be changed except for TAG_MARK which has to be a bit)
  • add alloc_float(double f) function in alloc.h / alloc.c (you can copy stuff from alloc_int)
  • add a state PST_FLOAT in reader.h and switch from PST_NUM or PST_ATOM to PST_FLOAT in reader.c when a '.' is encountered
  • implement PST_FLOAT parser in reader.c (which calls alloc_float with the parsed number)
  • implement PST_FLOAT printing in writer.c
  • probably implement load_float in compiler_new.c analog to load_int (maybe triggering a refactor to make load_int/_cell/_float more compact). alternatively first always use boxed floats to make things simpler. then you would only need to expand load_int to coerce a float cell to an integer.
  • introduce BUILTIN_FADD / _FSUB / _FMUL / FDIV cases in compiler_new.c and jit*.c and register those constants in compiler_new.h enum builtin_t

I think that should be about it! :)

About division by zero: I'll look into this, it is platform specific, and there are 4 more exceptions on floating point hardware.

Cheers Lukas

mntmn avatar Oct 13 '15 16:10 mntmn