summaryrefslogtreecommitdiffstats
path: root/lib.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-11-19 20:36:21 -0800
committerKaz Kylheku <kaz@kylheku.com>2015-11-20 16:17:20 -0800
commit3c09800abda31a3f5da8157b0ef2863850f6b662 (patch)
treec60d7424fab9b35ff6c4cb7ce344a9fb7cf57c72 /lib.h
parent4caf98c502bf3cc80e20dba74eb941f50b58216e (diff)
downloadtxr-3c09800abda31a3f5da8157b0ef2863850f6b662.tar.gz
txr-3c09800abda31a3f5da8157b0ef2863850f6b662.tar.bz2
txr-3c09800abda31a3f5da8157b0ef2863850f6b662.zip
New equality substitution.
If the equal method is defined for structs, its return value is used in their place for hashing and comparison. * eval.h (eq_s, eql_s, equal_s): Declared. * hash.c (equal_hash): If a COBJ defines an equalsub function, we call it. If it returns non-nil, we take the object in its place and recurse. * lib.c (equal): Refactored to support equality substitution. (less): Support equality substitution. * lib.h (cobj_ops): New function pointer member, equalsub. Only struct instances define this, currently. (cobj_ops_init): Add null entry to initializer for equalsub. (cobj_ops_init_ex): New initialiation macro for situations when the equalsub member must be provided. * struct.c (struct struct_type): new member eqmslot. (make_struct_type): Initialize emslot to zero. (static_slot_set, static_slot_ensure): If eqmslot is -1, indicating positive knowledge that there is no equal method static slot, we must invalidate that with a zero: it is no longer known whether there is or isn't such a slot. (get_equal_method, struct_inst_equalsub): New static functions. (struct_inst_ops): Initialize the equalsub member using new cobj_ops_init_ex macro. * txr.1: Document equality substitution.
Diffstat (limited to 'lib.h')
-rw-r--r--lib.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib.h b/lib.h
index 3b10ce6d..7b33c784 100644
--- a/lib.h
+++ b/lib.h
@@ -219,10 +219,15 @@ struct cobj_ops {
void (*destroy)(val self);
void (*mark)(val self);
cnum (*hash)(val self);
+ val (*equalsub)(val self);
};
#define cobj_ops_init(equal, print, destroy, mark, hash) \
- { equal, print, destroy, mark, hash }
+ { equal, print, destroy, mark, hash, 0 }
+
+#define cobj_ops_init_ex(equal, print, destroy, mark, hash, \
+ equalsub) \
+ { equal, print, destroy, mark, hash, equalsub }
/* Default operations for above structure.
* Default equal is eq