diff options
| author | Keith Packard <keithp@keithp.com> | 2018-01-06 17:29:10 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2018-01-06 17:31:43 -0800 | 
| commit | 16061947d4376b41e596d87f97ec53ec29d17644 (patch) | |
| tree | f7ad08f8810b0ea78cf282048eacb46d441a2ee1 /src/scheme/ao_scheme_int.c | |
| parent | 39df849f0717d92a7d5bdf8aa5904bd4db1b467f (diff) | |
altos/scheme: Add ports. Split scheme code up.
And lots of other changes, including freeing unreferenced atoms.
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.c | 63 | 
1 files changed, 54 insertions, 9 deletions
| diff --git a/src/scheme/ao_scheme_int.c b/src/scheme/ao_scheme_int.c index 01b571c0..2c9e45a0 100644 --- a/src/scheme/ao_scheme_int.c +++ b/src/scheme/ao_scheme_int.c @@ -15,28 +15,73 @@  #include "ao_scheme.h"  void -ao_scheme_int_write(ao_poly p, bool write) +ao_scheme_int_write(FILE *out, ao_poly p, bool write)  {  	int i = ao_scheme_poly_int(p);  	(void) write; -	printf("%d", i); +	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  int32_t -ao_scheme_poly_integer(ao_poly p, bool *fail) +ao_scheme_poly_integer(ao_poly p)  { -	if (fail) -		*fail = false;  	switch (ao_scheme_poly_base_type(p)) {  	case AO_SCHEME_INT:  		return ao_scheme_poly_int(p);  	case AO_SCHEME_BIGINT:  		return ao_scheme_poly_bigint(p)->value;  	} -	if (fail) -		*fail = true;  	return 0;  } @@ -77,11 +122,11 @@ const struct ao_scheme_type ao_scheme_bigint_type = {  };  void -ao_scheme_bigint_write(ao_poly p, bool write) +ao_scheme_bigint_write(FILE *out, ao_poly p, bool write)  {  	struct ao_scheme_bigint	*bi = ao_scheme_poly_bigint(p);  	(void) write; -	printf("%d", bi->value); +	fprintf(out, "%d", bi->value);  }  #endif /* AO_SCHEME_FEATURE_BIGINT */ | 
