@@ -28,10 +28,10 @@ void error(char *fmt, int line_num, ...) {
2828}
2929
3030// Constants
31- static Obj * True = & (Obj ){ TTRUE };
32- static Obj * Nil = & (Obj ){ TNIL };
33- static Obj * Dot = & (Obj ){ TDOT };
34- static Obj * Cparen = & (Obj ){ TCPAREN };
31+ static Obj * True = & (Obj ){ . type = TTRUE , . size = sizeof ( Obj ) };
32+ static Obj * Nil = & (Obj ){ . type = TNIL , . size = sizeof ( Obj ) };
33+ static Obj * Dot = & (Obj ){ . type = TDOT , . size = sizeof ( Obj ) };
34+ static Obj * Cparen = & (Obj ){ . type = TCPAREN , . size = sizeof ( Obj ) };
3535
3636//======================================================================
3737// Constructors
@@ -263,15 +263,8 @@ static Obj *read_string(void *root) {
263263static Obj * read_expr (void * root ) {
264264 for (;;) {
265265 char c = read_char ();
266- if (c == '\n' ) {
267- if (peek () == '\r' );
266+ if (c == ' ' || c == '\n' || c == '\r' || c == '\t' )
268267 continue ;
269- }
270-
271- if (c == ' ' || c == '\r' || c == '\t' )
272- continue ;
273- if (c == EOF )
274- return NULL ;
275268 if (c == ';' ) {
276269 skip_line ();
277270 continue ;
@@ -292,6 +285,9 @@ static Obj *read_expr(void *root) {
292285 return make_int (root , - read_number (0 ));
293286 if (isalpha (c ) || strchr (symbol_chars , c ))
294287 return read_symbol (root , c );
288+ if (c == EOF )
289+ return NULL ;
290+
295291 error ("Don't know how to handle %c" , filepos .line_num , c );
296292 }
297293}
@@ -808,9 +804,9 @@ static Obj *prim_macroexpand(void *root, Obj **env, Obj **list) {
808804
809805// (print ...)
810806static Obj * prim_print (void * root , Obj * * env , Obj * * list ) {
811- for ( Obj * args = * list ; args != Nil ; args = args -> cdr ) {
812- print ( eval ( root , env , & ( args -> car ))) ;
813- }
807+ DEFINE1 ( root , tmp );
808+ * tmp = ( * list ) -> car ;
809+ print ( eval ( root , env , tmp ));
814810 return Nil ;
815811}
816812
@@ -1023,6 +1019,8 @@ static void define_primitives(void *root, Obj **env) {
10231019 add_primitive (root , env , "while" , prim_while );
10241020 add_primitive (root , env , "gensym" , prim_gensym );
10251021 add_primitive (root , env , "not" , prim_not );
1022+ add_primitive (root , env , "and" , prim_and );
1023+ add_primitive (root , env , "or" , prim_or );
10261024 add_primitive (root , env , "+" , prim_plus );
10271025 add_primitive (root , env , "-" , prim_minus );
10281026 add_primitive (root , env , "*" , prim_mult );
@@ -1060,20 +1058,16 @@ static void define_primitives(void *root, Obj **env) {
10601058
10611059extern void * memory ;
10621060
1063- void reset_minilisp (Obj * * env ) {
1061+ void init_minilisp (Obj * * env ) {
10641062 // Memory allocation
1065- extern void * memory ;
10661063 extern void * alloc_semispace ();
1067- extern void free_semispace (void * );
1068- gc_root = NULL ;
1069- free_semispace (memory );
10701064 memory = alloc_semispace ();
10711065
10721066 // Constants and primitives
10731067 Symbols = Nil ;
1074- * env = make_env (gc_root , & Nil , & Nil );
1075- define_constants (gc_root , env );
1076- define_primitives (gc_root , env );
1068+ * env = make_env (NULL , & Nil , & Nil );
1069+ define_constants (NULL , env );
1070+ define_primitives (NULL , env );
10771071}
10781072
10791073int eval_input (void * root , Obj * * env , Obj * * expr ) {
0 commit comments