#include "ao_scheme.h"
void
-ao_scheme_int_write(ao_poly p)
+ao_scheme_int_write(FILE *out, ao_poly p, bool write)
{
int i = ao_scheme_poly_int(p);
- printf("%d", i);
+ (void) write;
+ fprintf(out, "%d", i);
+}
+
+ao_poly
+ao_scheme_do_integerp(struct ao_scheme_cons *cons)
+{
+#ifdef AO_SCHEME_FEATURE_BIGINT
+ ao_poly val;
+
+ if (!ao_scheme_parse_args(_ao_scheme_atom_pair3f, cons,
+ AO_SCHEME_POLY, &val,
+ AO_SCHEME_ARG_END))
+ return AO_SCHEME_NIL;
+ switch (ao_scheme_poly_type(val)) {
+ case AO_SCHEME_INT:
+ case AO_SCHEME_BIGINT:
+ return _ao_scheme_bool_true;
+ default:
+ return _ao_scheme_bool_false;
+ }
+#else
+ return ao_scheme_do_typep(_ao_scheme_atom_integer3f, AO_SCHEME_INT, cons);
+#endif
+}
+
+ao_poly
+ao_scheme_do_numberp(struct ao_scheme_cons *cons)
+{
+#if defined(AO_SCHEME_FEATURE_BIGINT) || defined(AO_SCHEME_FEATURE_FLOAT)
+ ao_poly val;
+
+ if (!ao_scheme_parse_args(_ao_scheme_atom_pair3f, cons,
+ AO_SCHEME_POLY, &val,
+ AO_SCHEME_ARG_END))
+ return AO_SCHEME_NIL;
+ switch (ao_scheme_poly_type(val)) {
+ case AO_SCHEME_INT:
+#ifdef AO_SCHEME_FEATURE_BIGINT
+ case AO_SCHEME_BIGINT:
+#endif
+#ifdef AO_SCHEME_FEATURE_FLOAT
+ case AO_SCHEME_FLOAT:
+#endif
+ return _ao_scheme_bool_true;
+ default:
+ return _ao_scheme_bool_false;
+ }
+#else
+ return ao_scheme_do_integerp(cons);
+#endif
}
#ifdef AO_SCHEME_FEATURE_BIGINT
switch (ao_scheme_poly_base_type(p)) {
case AO_SCHEME_INT:
return ao_scheme_poly_int(p);
- case AO_SCHEME_OTHER:
- if (ao_scheme_other_type(ao_scheme_poly_other(p)) == AO_SCHEME_BIGINT)
- return ao_scheme_bigint_int(ao_scheme_poly_bigint(p)->value);
+ case AO_SCHEME_BIGINT:
+ return ao_scheme_poly_bigint(p)->value;
}
- return AO_SCHEME_NOT_INTEGER;
+ return 0;
}
ao_poly
if (AO_SCHEME_MIN_INT <= p && p <= AO_SCHEME_MAX_INT)
return ao_scheme_int_poly(p);
bi = ao_scheme_alloc(sizeof (struct ao_scheme_bigint));
- bi->value = ao_scheme_int_bigint(p);
+ bi->value = p;
return ao_scheme_bigint_poly(bi);
}
};
void
-ao_scheme_bigint_write(ao_poly p)
+ao_scheme_bigint_write(FILE *out, ao_poly p, bool write)
{
struct ao_scheme_bigint *bi = ao_scheme_poly_bigint(p);
- printf("%d", ao_scheme_bigint_int(bi->value));
+ (void) write;
+ fprintf(out, "%d", bi->value);
}
#endif /* AO_SCHEME_FEATURE_BIGINT */