summaryrefslogtreecommitdiff
path: root/src/scheme/ao_scheme_int.c
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-12-14 23:04:39 -0800
committerKeith Packard <keithp@keithp.com>2017-12-14 23:04:39 -0800
commit32f6877288ea6b7eb1cae9a42fbe8e2c5dbb2f08 (patch)
tree4e23989a62ae144b8cbf1d2fd135ca8a6bd743dc /src/scheme/ao_scheme_int.c
parent2e11cae044cd2c053049effd76df9c5adecb84d7 (diff)
altos/scheme: swap BIGINT and STRING types
This lets BIGINT be a primitive type, allowing it to use all 32 bits for storage. This does make strings another byte longer, and also slightly harder to deal with. It's a trade off. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/scheme/ao_scheme_int.c')
-rw-r--r--src/scheme/ao_scheme_int.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/scheme/ao_scheme_int.c b/src/scheme/ao_scheme_int.c
index 43d6b8e1..4fcf4931 100644
--- a/src/scheme/ao_scheme_int.c
+++ b/src/scheme/ao_scheme_int.c
@@ -24,16 +24,19 @@ ao_scheme_int_write(ao_poly p)
#ifdef AO_SCHEME_FEATURE_BIGINT
int32_t
-ao_scheme_poly_integer(ao_poly p)
+ao_scheme_poly_integer(ao_poly p, bool *fail)
{
+ if (fail)
+ *fail = false;
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;
+ if (fail)
+ *fail = true;
+ return 0;
}
ao_poly
@@ -44,7 +47,7 @@ ao_scheme_integer_poly(int32_t p)
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);
}
@@ -77,6 +80,6 @@ ao_scheme_bigint_write(ao_poly p)
{
struct ao_scheme_bigint *bi = ao_scheme_poly_bigint(p);
- printf("%d", ao_scheme_bigint_int(bi->value));
+ printf("%d", bi->value);
}
#endif /* AO_SCHEME_FEATURE_BIGINT */