From d268addccbf0cfdb19f84103f85874daf410e1a6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 17 Mar 2012 20:30:15 -0700 Subject: Changing type function to not blow up on nil, which makes a lot of code simpler. A pseudo type code is introduced called NIL with value 0. * lib.h (enum type): New enumeration value, NIL. (type): Function accepts object nil and maps it to code NIL. * eval.c (dwim_loc, op_dwim): test for nil obj and goto hack is gone, just handle NIL in the switch. * gc.c (make_obj, mark): Handle new NIL type code in switch. * hash.c (equal_hash): Handle NIL in the switch instead of nil test. * lib.c (code2type): Map new NIL type code to null. (typeof, typecheck): Code simplified. (class_check, car): Move nil test into switch. (eql, equal, consp, bignump, stringp, lazy_stringp, symbolp, functionp, vectorp, cobjp): Simplified. (length, sub, ref, refset, replace, obj_print, obj_pprint): Handle NIL in switch instead of nil test. goto hack removed from refset. * match.c (do_match_line, do_output_line): switch condition simplified. * regex.c (regexp): Simplified. (regex_nfa): Assert condition simplified. --- eval.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index 6cb8721e..fcce0b2f 100644 --- a/eval.c +++ b/eval.c @@ -751,9 +751,6 @@ static val *dwim_loc(val form, val env, val op, val newform, val *retval) val obj = eval_lisp1(second(form), env, form); val args = eval_args_lisp1(rest(rest(form)), env, form); - if (!obj) - goto list; - switch (type(obj)) { case LIT: case STR: @@ -839,9 +836,9 @@ static val *dwim_loc(val form, val env, val op, val newform, val *retval) return vecref_l(obj, index); } } + case NIL: case CONS: case LCONS: - list: if (rest(args)) eval_error(form, lit("[~s ...]: list indexing needs one arg"), obj, nao); @@ -1102,10 +1099,9 @@ static val op_dwim(val form, val env) val obj = eval_lisp1(second(form), env, form); val args = eval_args_lisp1(rest(rest(form)), env, form); - if (!obj) - return nil; - switch (type(obj)) { + case NIL: + return nil; case LIT: case STR: case LSTR: -- cgit v1.2.3