summaryrefslogtreecommitdiffstats
path: root/lib.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-17 20:30:15 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-17 20:30:15 -0700
commitd268addccbf0cfdb19f84103f85874daf410e1a6 (patch)
tree4db5ade3b4a64ccf06d6a9b344e8a0625096fb07 /lib.h
parent302c1d3aeb9e05c3d2888529589217292f7e1c02 (diff)
downloadtxr-d268addccbf0cfdb19f84103f85874daf410e1a6.tar.gz
txr-d268addccbf0cfdb19f84103f85874daf410e1a6.tar.bz2
txr-d268addccbf0cfdb19f84103f85874daf410e1a6.zip
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.
Diffstat (limited to 'lib.h')
-rw-r--r--lib.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib.h b/lib.h
index dae6c755..e33667a4 100644
--- a/lib.h
+++ b/lib.h
@@ -38,7 +38,7 @@ typedef int_ptr_t cnum;
#define NUM_MIN (INT_PTR_MIN/4)
typedef enum type {
- NUM = TAG_NUM, CHR = TAG_CHR, LIT = TAG_LIT, CONS,
+ NIL, NUM = TAG_NUM, CHR = TAG_CHR, LIT = TAG_LIT, CONS,
STR, SYM, PKG, FUN, VEC, LCONS, LSTR, COBJ, ENV,
BGNUM
} type_t;
@@ -216,7 +216,10 @@ INLINE int is_lit(val obj) { return tag(obj) == TAG_LIT; }
INLINE type_t type(val obj)
{
- return tag(obj) ? (type_t) tag(obj) : obj->t.type;
+ return obj ? tag(obj)
+ ? (type_t) tag(obj)
+ : obj->t.type
+ : NIL;
}
typedef struct wli wchli_t;