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. --- regex.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'regex.c') diff --git a/regex.c b/regex.c index 9d07f411..2fc08c64 100644 --- a/regex.c +++ b/regex.c @@ -1511,13 +1511,12 @@ val regexp(val obj) if (consp(obj)) return if2(eq(car(obj), compiled_regex_s), t); - return (is_ptr(obj) && obj->co.type == COBJ && obj->co.cls == regex_s) - ? t : nil; + return typeof(obj) == regex_s ? t : nil; } static nfa_t *regex_nfa(val reg) { - assert (reg->co.type == COBJ && reg->co.cls == regex_s); + assert (typeof(reg) == regex_s); return (nfa_t *) reg->co.handle; } -- cgit v1.2.3