summaryrefslogtreecommitdiffstats
path: root/struct.h
Commit message (Collapse)AuthorAgeFilesLines
* Methods for turning objects into sequences.Kaz Kylheku2016-06-011-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | Struct objects can now define methods car, cdr and nullify. With these, they can participate in operations on sequences. * eval.h (car_s, cdr_s): Declared. * lib.c (nullify_s): New symbol variable. (car, cdr): Implement for struct objects via, respectively, their car and cdr methods. (tolist): Handle objects by mapping through identity. (nullify): Implement for objects optionally: if an object is a struct with a nullify method, use it, otherwise go through default case of just returning the object. (empty): Implement for objects that have nullify method. (obj_init): Initialize nullify_s. * struct.c (maybe_slot): New function. * struct.h (maybe_slot): Declared. * txr.1: Documented car, cdr and nullify method convention.
* Copyright year bump.Kaz Kylheku2015-12-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * LICENSE, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/cadr.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Add 2016 copyright. * linenoise/LICENSE, linenoise/linenoise.c, linenoise/linenoise.h: Bump one principal author's copyright from 2014 to 2015. The code is based on a snapshot of 2015 upstream work.
* Useful feature: object post-initialization.Kaz Kylheku2015-12-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Structs can now have code which executes after an object is initialized, which is useful for doing work like registering objects in global lists and whatever, when those actions need access to the initialized slots of the object. * share/txr/stdlib/struct.tl (defstruct): Handle :posinit syntax, by generating lambda as eighth argument of sys:make-struct call. * struct.c (struct struct_type): New member, postinitfun. (struct_init): Adjust registrations of make_struct_type to account for new parameter. The user visible make-struct-type is registered as having one optional argument, for backward compat. (make_struct_type): New argument, postinitfun. Store this in the structure. For backward compatibility, the argument is defaulted. (struct_type_mark): Mark the new postinitfun member. (call_postinitfun_chain): New static function. (make_struct, lazy_struct_init): Call call_postinitfun_chain after slots are initialized, and after the boa function is called. * struct.h (make_struct_type): Declaration updated. * lib.c (time_init): Pass eighth argument to make_struct type. * sysif.c (sysif_init): Likewise. * unwind.c (uw_late_init): Likewise. * tests/012/struct.tl: Update defstruct expansion test case. * txr.1: Document new argument of make-struct-type, and clarify ordering of initfun with regard to other actions. Likewise, document :postinit, and clarify ordering of :init actions with regard to other actions.
* defun can define methods.Kaz Kylheku2015-11-301-1/+1
| | | | | | | | | | | | * eval.c (op_defun): Handle (meth type name) syntax in place of name via sys:defmeth function, which is dynamically resolved and autoloaded as necessary. (builtin_reject_test): When defun is being checked, recognize a (method ...) form and allow it. * struct.h (meth_s): Declaration added. * txr.1: Documented new defun capability.
* func-get-name calculates a name for methods.Kaz Kylheku2015-11-301-0/+1
| | | | | | | | | | | | | | * eval.c (func_get_name): Use try to use new method_name function, if unable to get name from the lexical or global environment for functions. * struct.c (meth_s): New symbol variable. (struct_init): Initialize meth_s variable. (method_name): New function. * struct.h (method_name): Declared. * txr.1: Re-documented func-get-name.
* Introducing lazy structs.Kaz Kylheku2015-11-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (lnew): New macro. * struct.c (struct_type): Turn id into a bitfield one bit smaller than cnum. New Boolean bitfield lazy. (struct_init): Register make-lazy-struct intrinsic. (make_struct): Initialize lazy bitfield to zero. (lazy_struct_init, check_init_lazy_struct): New static functions. (make_lazy_struct): New function. (copy_struct, clear_struct, replace_struct, reset_struct, lookup_slot, struct_inst_equal, struct_inst_hash): Call check_init_lazy_struct on all structures involved. (lookup_slot): Call check_init_lazy_struct. (struct_inst_mark): If the struct is lazy, it has one instance slot which must be marked, holding the argfun function passed into make_lazy_struct. * struct.h (make_lazy_struct): Declared. * txr.1: Documented lnew and make-lazy-struct.
* New uslot function and usl macro.Kaz Kylheku2015-11-201-0/+1
| | | | | | | | | | | | | | * struct.c (struct_init): Register uslot intrinsic function. (uslot_fun): New static function. (uslot): New function. * struct.h (uslot): Declared. * share/txr/stdlib/struct.tl (usl): New macro. * lisplib.c (struct_set_entries): Add usl macro. * txr.1: Documented uslot and usl.
* Adding defmeth macro and static-slot-ensure.Kaz Kylheku2015-10-161-0/+1
| | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (defmeth): New macro. * struct.c (struct struct_type): New member, dvtypes. (struct_init): Register static-slot-ensure intrinsic. (make_struct_type): Initialize dvtypes of newly instantiated struct_type struct. If a super is specified, add new type to the super's dvtypes. (struct_type_mark): Mark st->dvtypes. (static_slot_ensure): New function. * struct.h (static_slot_ensure): Declared. * txr.1: Documented defmeth and static-slot-ensure.
* New function: reset-struct.Kaz Kylheku2015-10-061-0/+1
| | | | | | | | | * struct.c (reset_struct): New function. (struct_init): Register reset_struct intrinsic. * struct.h (reset_struct): Declared. * txr.1: documented reset-struct.
* New function: replace-struct.Kaz Kylheku2015-10-061-0/+1
| | | | | | | | | * struct.c (replace_struct): New function. (struct_init): Register replace_struct intrinsic. * struct.h (replace_struct): Declared. * txr.1: documented replace-struct.
* New function: clear-struct.Kaz Kylheku2015-10-061-0/+1
| | | | | | | | | * struct.c (clear_struct): New function. (struct_init): Register clear-struct intrinsic. * struct.h (struct_init): Declared. * txr.1: documented clear-struct.
* slot-p renamed to slotp, conforming with Lisp conventions.Kaz Kylheku2015-10-031-1/+1
| | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (sys:prune-nil-inits): Use of slot-p renamed. * struct.c (struct_init): Register slotp, and make registration of slot-p conditional on compatibility option. (slot_p): Function renamed to slotp. * struct.h (slot_p): Declaration renamed. * txr.1: References to slot-p fixed to slotp. Compat notes added.
* New umeth and umethod macro and function.Kaz Kylheku2015-10-031-0/+1
| | | | | | | | | | * share/txr/stdlib/struct.tl (umeth): New macro. * struct.c (struct_init): Registered umethod intrinsic. (umethod_fun): New static function. (umethod): New function. * txr.1: Documented.
* New super-method function.Kaz Kylheku2015-10-011-1/+2
| | | | | | | | | * struct.c (struct_init): Register super-method. (super_method): New function. * struct.h (super_method): Declared. * txr.1: Documented.
* Implementation of static slots for structures.Kaz Kylheku2015-09-291-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* Introducing structs.Kaz Kylheku2015-09-021-0/+39
* 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.