support infinity and nan literals

This commit is contained in:
Yuichi Nishiwaki 2014-06-27 08:54:32 +09:00
parent 195ccf199d
commit 51b8344527
1 changed files with 17 additions and 3 deletions

View File

@ -206,25 +206,39 @@ negate(pic_value n)
static pic_value
read_minus(pic_state *pic, struct pic_port *port, char c)
{
/* TODO: -inf.0, -nan.0 */
pic_value sym;
if (isdigit(peek(port))) {
return negate(read_number(pic, port, next(port)));
}
else {
return read_symbol(pic, port, c);
sym = read_symbol(pic, port, c);
if (pic_eq_p(sym, pic_sym_value(pic_intern_cstr(pic, "-inf.0")))) {
return pic_float_value(-INFINITY);
}
if (pic_eq_p(sym, pic_sym_value(pic_intern_cstr(pic, "-nan.0")))) {
return pic_float_value(-NAN);
}
return sym;
}
}
static pic_value
read_plus(pic_state *pic, struct pic_port *port, char c)
{
/* TODO: +inf.0, +nan.0 */
pic_value sym;
if (isdigit(peek(port))) {
return read_number(pic, port, c);
}
else {
sym = read_symbol(pic, port, c);
if (pic_eq_p(sym, pic_sym_value(pic_intern_cstr(pic, "+inf.0")))) {
return pic_float_value(INFINITY);
}
if (pic_eq_p(sym, pic_sym_value(pic_intern_cstr(pic, "+nan.0")))) {
return pic_float_value(NAN);
}
return read_symbol(pic, port, c);
}
}