2 * Copyright © 2016 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #include "ao_scheme.h"
18 ao_scheme_int_write(ao_poly p)
20 int i = ao_scheme_poly_int(p);
25 ao_scheme_poly_integer(ao_poly p)
27 switch (ao_scheme_poly_base_type(p)) {
29 return ao_scheme_poly_int(p);
31 if (ao_scheme_other_type(ao_scheme_poly_other(p)) == AO_SCHEME_BIGINT)
32 return ao_scheme_bigint_int(ao_scheme_poly_bigint(p)->value);
34 return AO_SCHEME_NOT_INTEGER;
38 ao_scheme_integer_poly(int32_t p)
40 struct ao_scheme_bigint *bi;
42 if (AO_SCHEME_MIN_INT <= p && p <= AO_SCHEME_MAX_INT)
43 return ao_scheme_int_poly(p);
44 bi = ao_scheme_alloc(sizeof (struct ao_scheme_bigint));
45 bi->value = ao_scheme_int_bigint(p);
46 return ao_scheme_bigint_poly(bi);
49 static void bigint_mark(void *addr)
54 static int bigint_size(void *addr)
58 return sizeof (struct ao_scheme_bigint);
61 static void bigint_move(void *addr)
66 const struct ao_scheme_type ao_scheme_bigint_type = {
74 ao_scheme_bigint_write(ao_poly p)
76 struct ao_scheme_bigint *bi = ao_scheme_poly_bigint(p);
78 printf("%d", ao_scheme_bigint_int(bi->value));