diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-02-26 22:42:09 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-02-26 22:42:09 -0800 |
commit | 4f14d3a2ded6137c5dd6449f4ec2d566947c4157 (patch) | |
tree | 549a19452aa66c2b60b1529333b82007ed3127ca /lib.c | |
parent | 875c0c2d16fbcaa61bfc46da58533ab0890bf513 (diff) | |
download | txr-4f14d3a2ded6137c5dd6449f4ec2d566947c4157.tar.gz txr-4f14d3a2ded6137c5dd6449f4ec2d566947c4157.tar.bz2 txr-4f14d3a2ded6137c5dd6449f4ec2d566947c4157.zip |
Place C standard I/O based streams into subtype.
* lib.c (subtypep): Handle subtype check here between
stream and stdio-stream as a special case, since streams
aren't structures related by inheritance, but built-ins.
(class_check): If the type of obj doesn't match the class
exactly, use a subtypep check. We need this because stream
functions use this check, and stdio streams are not of the
stream type now.
* stream.c (stdio_stream_s): New global symbol variable.
(make_stdio_stream_common): Use stdio_stream_s symbol for the
type of stdio streams.
(stream_init): Intern the stdio-stream symbol, and store in
stdio_stream_s variable.
(streamp): Replace exact check with typep.
* stream.h (stdio_stream_s): Declared.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -222,6 +222,8 @@ val subtypep(val sub, val sup) sub == list_s); } else if (sup == string_s) { return tnil(sub == str_s || sub == lit_s || sub == lstr_s); + } else if (sup == stream_s) { + return tnil(sub == stdio_stream_s); } else { val sub_struct = find_struct_type(sub); val sup_struct = find_struct_type(sup); @@ -269,7 +271,7 @@ val type_check3(val obj, int t1, int t2, int t3) val class_check(val cobj, val class_sym) { type_assert (is_ptr(cobj) && cobj->t.type == COBJ && - cobj->co.cls == class_sym, + (cobj->co.cls == class_sym || subtypep(cobj->co.cls, class_sym)), (lit("~s is not of type ~s"), cobj, class_sym, nao)); return t; } |