diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-11-19 07:06:22 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-11-20 16:17:19 -0800 |
commit | eb483eb39fa4570d1178a3f71fb65be908fd0d01 (patch) | |
tree | 4668efdc1c3c407e2ff21c0559cb23800a0471ce /txr.1 | |
parent | ec5daf6385b68f08e82c106a925a758cf2b2bf14 (diff) | |
download | txr-eb483eb39fa4570d1178a3f71fb65be908fd0d01.tar.gz txr-eb483eb39fa4570d1178a3f71fb65be908fd0d01.tar.bz2 txr-eb483eb39fa4570d1178a3f71fb65be908fd0d01.zip |
Introducing lazy structs.
* 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.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 77 |
1 files changed, 76 insertions, 1 deletions
@@ -18599,9 +18599,10 @@ are applied to the structure as if it were a function, the method is invoked with those arguments, with the object itself inserted into the leftmost argument position. -.coNP Macro @ new +.coNP Macros @ new and @ lnew .synb .mets (new >> { name | >> ( name << arg *)} >> { slot << init-form }*) +.mets (lnew >> { name | >> ( name << arg *)} >> { slot << init-form }*) .syne .desc The @@ -18646,6 +18647,32 @@ If any of the initializations abandon the evaluation of by a non-local exit such as an exception throw, the object's finalizers, if any, are invoked. +The macro +.code lnew +differs from new in that it specifies the construction of a +lazy struct, as if by the +.code make-lazy-struct +function. +When +.code lnew +is used to construct an instance, a lazy struct is returned +immediately, without evaluating any of the the +.meta arg +and +.meta init-form +expressions. +The expressions are evaluated when any of the object's +instance slots is accessed for the first time. At that time, +these expressions are evaluated (in the same order as under +.codn new ) +and initialization proceeds in the same way. + +If any of the initializations abandon the delayed initializations steps +arranged by +.code lnew +by a non-local exit such as an exception throw, the object's +finalizers, if any, are invoked. + .coNP Macro @ qref .synb .mets (qref < object-form @@ -19123,6 +19150,54 @@ If any of the initializations abandon the evaluation of by a non-local exit such as an exception throw, the object's finalizers, if any, are invoked. +.coNP Function @ make-lazy-struct +.synb +.mets (make-lazy-struct < type << argfun ) +.syne +.desc +The +.code make-lazy-struct +function returns a new object which is an instance of the +structure type +.metn type . + +The +.meta type +argument must either be a +.code struct-type +object, or else a symbol which is the name of a structure. + +The +.meta argfun +argument should be a function which can be called with no parameters +and returns a cons cell. More requirements are specified below. + +The object returned by +.code make-lazy-struct +is a lazily-initialized struct instance, or +.IR "lazy struct" . + +A lazy struct remains uninitialized until just before the first access +to any of its instance slots. Just before an instance slot is +accessed, initialization +takes place as follows. The +.meta argfun +function is invoked with no arguments. Its return value must be a cons +cell. The +.code car +of the cons cell is taken to be a property list, as defined by the +.code prop +function. The +.code cdr +field is taken to be a list of arguments. These values are treated +as if they were, respectively, the +.meta slot-init-plist +and the boa constructor arguments given in a +.code make-struct +invocation. Initialization of the structure proceeds as described +in the description of +.codn make-struct . + .coNP Function @ copy-struct .synb .mets (copy-struct << struct-obj ) |