summaryrefslogtreecommitdiffstats
path: root/struct.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Implementation of static slots for structures.Kaz Kylheku2015-09-291-35/+273
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Fix failure of struct.c to compile as C++.Kaz Kylheku2015-09-041-16/+9
| | | | | | | * struct.c (struct_type_ops, struct_inst_ops): Use static_forward and static_macros to handle the forward declarations. Also, cobj_ops_init macro now used for both instead of raw initializer.
* Slot cache fix: zero is a valid slot index.Kaz Kylheku2015-09-021-2/+2
| | | | | | | struct.c (cacheline_lookup): return -1 when the id is not found in the cacheline, rather than zero. (lookup_slot): Test return value of cacheline_lookup according to the above change.
* Fix incorrect finalization of struct-type.Kaz Kylheku2015-09-021-14/+20
| | | | | | | | | | | | | | | | | | | | | | The issue is that we can't call remhash in the cobj destroy handler, because we are in the middle of gc. The fix is to register a proper finalization hook. This is the first use of finalize from within TXR. * gc.c (gc_finalize): static becomes extern. * gc.h (gc_finalize): Declared. * struct.c (struct_type_finalize_f): New static variable. (struct_init): GC-protect new static variable, and initialize it to point to new struct_type_finalize function. (struct_type_finalize): New function: performs the remhash calls previously done in struct_type_free. (make_struct_type): Register a finalizer hook for every new structure type, which will call struct_type_finalize. (struct_type_free): Static function removed. (struct_type_ops): Use generic cobj_destroy_free_op since all that is left to do is to free the handle.
* equal comparison and hashing for structs.Kaz Kylheku2015-09-011-2/+36
| | | | | * struct.c (struct_inst_equal, struct_inst_hash): New functions. (struct_inst_ops): Wire new functions into operations table.
* struct: 4-way set associative slot caches.Kaz Kylheku2015-08-301-10/+54
| | | | | | | | | | | * lib.h (SLOT_CACHE_SIZE): Adjust value from 32 to 8. (slot_cache_entry_t): New struct typedef. (slot_cache_line_t): Typedef updated: a cache line consists of cache line entry structs rather than cnums. * struct.c (cacheline_lookup, cacheline_insert): New static functions. (lookup_slot): Use cacheline_lookup and cacheline_insert.
* Introducing structs.Kaz Kylheku2015-09-021-0/+450
* args.c (args_cat_zap): New function. * args.h: (args_cat_zap): Declared. * eval.c (struct_lit_s): New symbol variable. (eval_init): Initialize struct_lit_s. * eval.h (struct_lit_s): Declared. * gc.c (finalize): If a symbol has a struct slot hash attached to it, we must free it when the symbol is reclaimed. * lib.c (make_sym): Initialize symbol's slot_cache pointer to null. (copy): Copy structure objects. (init): Call struct_init to initialize struct module. * lib.h (SLOT_CACHE_SIZE): New preprocessor symbol (slot_cache_line_t, slot_cache_t): New typedefs. (struct sym): New member, slot_cache. * lisplib.c (struct_set_entries, struct_instantiate): New static functions. (liplib_init): Register new functions in dl_table. parser.y (HASH_S): New terminal symbol. (struct): New grammar rule. (n_expr): Derive struct. (yybadtoken): Map HASH_S to #S string. parser.l (grammar): Recognize #S and return HASH_S token. share/txr/stdlib/place.tl (slot): New defplace. share/txr/stdlib/struct.tl: New file. struct.c: New file. struct.h: New file. * Makefile (OBJS): Adding struct.o.