diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ao_lisp_os.h | 48 | ||||
| -rw-r--r-- | src/test/ao_lisp_test.c | 68 | 
2 files changed, 74 insertions, 42 deletions
| diff --git a/src/test/ao_lisp_os.h b/src/test/ao_lisp_os.h new file mode 100644 index 00000000..19bd4f64 --- /dev/null +++ b/src/test/ao_lisp_os.h @@ -0,0 +1,48 @@ +/* + * Copyright © 2016 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#ifndef _AO_LISP_OS_H_ +#define _AO_LISP_OS_H_ + +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +extern int ao_lisp_getc(void); + +static inline void +ao_lisp_abort(void) +{ +	abort(); +} + +static inline void +ao_lisp_os_led(int led) +{ +	printf("leds set to 0x%x\n", led); +} + +static inline void +ao_lisp_os_delay(int delay) +{ +	struct timespec ts = { +		.tv_sec = delay / 1000, +		.tv_nsec = (delay % 1000) * 1000000, +	}; +	nanosleep(&ts, NULL); +} +#endif diff --git a/src/test/ao_lisp_test.c b/src/test/ao_lisp_test.c index 8bc677da..69739100 100644 --- a/src/test/ao_lisp_test.c +++ b/src/test/ao_lisp_test.c @@ -15,55 +15,39 @@  #include "ao_lisp.h"  #include <stdio.h> -#if 0 -static struct ao_lisp_cons	*list; -static char			*string; -#endif +static FILE *ao_lisp_file; +static int newline = 1;  int -main (int argc, char **argv) +ao_lisp_getc(void)  { -#if 0 -	int			i, j; +	int c; -	struct ao_lisp_atom	*atom; -	ao_lisp_root_add(&ao_lisp_cons_type, (void **) &list); -	ao_lisp_root_add(&ao_lisp_string_type, (void **) &string); +	if (ao_lisp_file) +		return getc(ao_lisp_file); -	/* allocator test */ -	for (j = 0; j < 10; j++) { -		list = 0; -		string = ao_lisp_string_new(0); -		for (i = 0; i < 2; i++) { -			string = ao_lisp_string_cat(string, "a"); -			list = ao_lisp_cons_cons(ao_lisp_string_poly(string), list); -			list = ao_lisp_cons_cons(ao_lisp_int_poly(i), list); -			atom = ao_lisp_atom_intern("ant"); -			list = ao_lisp_cons_cons(ao_lisp_atom_poly(atom), list); -		} -		ao_lisp_poly_print(ao_lisp_cons_poly(list)); -		printf("\n"); +	if (newline) { +		printf("> "); +		newline = 0;  	} +	c = getchar(); +	if (c == '\n') +		newline = 1; +	return c; +} -	for (atom = ao_lisp_poly_atom(ao_builtin_atoms); atom; atom = ao_lisp_poly_atom(atom->next)) { -		printf("%s = ", atom->name); -		ao_lisp_poly_print(ao_lisp_atom_get(ao_lisp_atom_poly(atom))); -		printf("\n"); +int +main (int argc, char **argv) +{ +	while (*++argv) { +		ao_lisp_file = fopen(*argv, "r"); +		if (!ao_lisp_file) { +			perror(*argv); +			exit(1); +		} +		ao_lisp_read_eval_print(); +		fclose(ao_lisp_file); +		ao_lisp_file = NULL;  	} -#endif -#if 0 -	list = ao_lisp_cons_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("+")), -				 ao_lisp_cons_cons(ao_lisp_cons_poly(ao_lisp_cons_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("+")), -										       ao_lisp_cons_cons(ao_lisp_int_poly(3), -													 ao_lisp_cons_cons(ao_lisp_int_poly(4), NULL)))), -						   ao_lisp_cons_cons(ao_lisp_int_poly(2), NULL))); -	printf("list: "); -	ao_lisp_poly_print(ao_lisp_cons_poly(list)); -	printf ("\n"); -	ao_lisp_poly_print(ao_lisp_eval(ao_lisp_cons_poly(list))); -	printf ("\n"); -#endif -#if 1  	ao_lisp_read_eval_print(); -#endif  } | 
