diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-29 19:46:42 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-29 19:46:42 -0700 |
commit | 111650e235ab2e529fa1529b1c9a23688a11cd1f (patch) | |
tree | b9b6aa775fdb38bef83458d5822c9ba27d31a152 /sysif.c | |
parent | c84defd9b6484dff60e513ad79e361c44aadcc0e (diff) | |
download | txr-111650e235ab2e529fa1529b1c9a23688a11cd1f.tar.gz txr-111650e235ab2e529fa1529b1c9a23688a11cd1f.tar.bz2 txr-111650e235ab2e529fa1529b1c9a23688a11cd1f.zip |
Implementation of static slots for structures.
* share/txr/stdlib/struct.tl (sys:bad-slot-syntax): New helper function.
(defstruct): Macro revamped with new slot specifier syntax for
writing static slots as well as methods.
* struct.c (STATIC_SLOT_BASE): New preprocessor symbol.
(struct struct_type): New members, nstslots, stinitfun, stslot.
(make_struct_type_compat): New static function.
(struct_init): Register make-struct-type to make_struct_type_compat
if compatibility is 117 or lower.
Register new intrinsics static-slot, static-slot-set, call-super-method,
call-super-fun, slot-p and static-slot-p.
(call_stinitfun_chain): New static function.
(make_struct_type): Two new arguments for specifying static slots and
an initialization function for them. Logic added for setting
up static slots and handling inheritance.
(struct_type_destroy): New static function.
(struct_type_mark): Mark the new stinitfun member of struct type.
Also iterate over the static slots in the new stslot array and
mark them.
(lookup_slot): Altered to return a loc instead of a raw pointer,
and also to accept the instance object as a member.
Now resolves static slots: it can return a loc which references
a static slot in the structure type, or an instance slot in
the structure.
(lookup_static_slot): New static function.
(slot, slotset): Implementation adjusted due to new lookup_slot interface.
(static_slot, static_slot_set, slot_p, static_slot_p): New functions.
(call_super_method, call_super_fun): New static functions.
(struct_inst_print): This function can no longer assume that the slots
list lines up with the array of slots, since it contains a mixture of
static and instance slots. Earnest slot lookup has to be performed.
(struct_type_ops): Point the destroy function to struct_type_destroy
instead of cobj_destroy_free_op. A structure type now has an array
of static slots to free.
* struct.h (make_struct_type): Declaration updated.
(static_slot, static_slot_set, slot_p, static_slot_p): Declared.
* lib.c (time_init): Update call to make_struct_type with new
arguments.
* sysif.c (sysif_init): Likewise.
* tests/012/struct.tl: Update defstruct macro expansion test.
* txr.1: Documented static slots and new functions.
Diffstat (limited to 'sysif.c')
-rw-r--r-- | sysif.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -1078,18 +1078,18 @@ void sysif_init(void) mem_s = intern(lit("mem"), user_package); #endif - make_struct_type(stat_s, nil, + make_struct_type(stat_s, nil, nil, list(dev_s, ino_s, mode_s, nlink_s, uid_s, gid_s, rdev_s, size_s, blksize_s, blocks_s, atime_s, - mtime_s, ctime_s, nao), nil, nil); + mtime_s, ctime_s, nao), nil, nil, nil); #if HAVE_PWUID - make_struct_type(passwd_s, nil, + make_struct_type(passwd_s, nil, nil, list(name_s, passwd_s, uid_s, gid_s, - gecos_s, dir_s, shell_s, nao), nil, nil); + gecos_s, dir_s, shell_s, nao), nil, nil, nil); #endif #if HAVE_GRGID - make_struct_type(group_s, nil, - list(name_s, passwd_s, gid_s, mem_s, nao), nil, nil); + make_struct_type(group_s, nil, nil, + list(name_s, passwd_s, gid_s, mem_s, nao), nil, nil, nil); #endif reg_fun(intern(lit("errno"), user_package), func_n1o(errno_wrap, 0)); |