Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divide by zero crashes #9

Open
mathias opened this issue Oct 1, 2015 · 1 comment
Open

Divide by zero crashes #9

mathias opened this issue Oct 1, 2015 · 1 comment

Comments

@mathias
Copy link

mathias commented Oct 1, 2015

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!

@mntmn
Copy link
Owner

mntmn commented Oct 13, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants