summaryrefslogtreecommitdiff
path: root/bos-mop-inheritance.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bos-mop-inheritance.sh')
-rw-r--r--bos-mop-inheritance.sh51
1 files changed, 51 insertions, 0 deletions
diff --git a/bos-mop-inheritance.sh b/bos-mop-inheritance.sh
new file mode 100644
index 0000000..551dd18
--- /dev/null
+++ b/bos-mop-inheritance.sh
@@ -0,0 +1,51 @@
+#!bash
+
+# this encoding must match bos-namespaces/encode-into
+bos_5fbos_2fmop_2finheritance_5fmeta="bos-dispatch/invoke bos/mop/base 0"
+declare -a bos_5fbos_2fmop_2finheritance_5fmro=( "bos/mop/inheritance" "bos/mop/base" )
+
+function bos/mop/inheritance/isa-for-into() {
+ bos-namespaces/store-array-for-into isa "$1" "$2"
+}
+
+function bos/mop/inheritance/set-superclasses-for() {
+ local isa_name; $self isa-for-into "$1" isa_name
+ local -n isa="$isa_name"
+ shift
+
+ isa=( "$@" )
+
+ return 0
+}
+
+function bos/mop/inheritance/get-superclasses-for-into() {
+ local isa_name; $self isa-for-into "$1" isa_name
+ local -n isa="$isa_name"
+ local -n dest="$2"
+
+ dest=( "${isa[@]}" )
+
+ return 0
+}
+
+# given a class and an array, sets the array to the list of clasess to
+# look into when resolving a method call for the given class, in order
+function bos/mop/inheritance/make-mro-for() {
+ local class="$1"
+ local mro_name; $self mro-for-into "$class" mro_name
+ local -n mro="$mro_name"
+
+ # TODO: use C3 and support multiple inheritance
+
+ mro=( "$class" )
+ local -a nextclasses
+ $self get-superclasses-for-into "$class" nextclasses
+
+ while [[ "${#nextclasses}" -gt 0 ]]; do
+ mro+=( "${nextclasses[0]}" )
+ class="${nextclasses[0]}"
+ $self get-superclasses-for-into "$class" nextclasses
+ done
+
+ return 0
+}