summaryrefslogtreecommitdiff
path: root/bos-meta-class.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bos-meta-class.sh')
-rw-r--r--bos-meta-class.sh64
1 files changed, 44 insertions, 20 deletions
diff --git a/bos-meta-class.sh b/bos-meta-class.sh
index ec3c03e..9e25b90 100644
--- a/bos-meta-class.sh
+++ b/bos-meta-class.sh
@@ -103,21 +103,23 @@ function bos/meta/class/find-method-into() {
# that the class that this metaclass describe, actuall has that
# attribute
function bos/meta/class/get-attribute-by-name-into() {
- local -n bos_meta_class_get_attribute_result="$1"
+ >&2 echo "get-attribute-by-name-into($*)"
+ local -n bos_meta_class_get_attribute_result="$1"; shift
+ local bos_meta_class_get_attribute_name="$1"
local bos_meta_class_attrs_name
-
+
# very manual method call, because I'm not sure I can make this
# work otherwise
local attribute_type='assoc'
- local attribute_name='class-attributes'
+ local attribute_name='class_attributes'
local associated_class='bos/meta/class'
bos/meta/attribute/store-for-into bos_meta_class_attrs_name "$self"
local -n bos_meta_class_attrs="$bos_meta_class_attrs_name"
- bos_meta_class_get_attribute_result="${bos_meta_class_attrs[$1]}"
+ bos_meta_class_get_attribute_result="${bos_meta_class_attrs[$bos_meta_class_get_attribute_name]}"
return 0
}
@@ -129,7 +131,7 @@ function bos/meta/class/set-attribute-by-name() {
# work otherwise
local attribute_type='assoc'
- local attribute_name='class-attributes'
+ local attribute_name='class_attributes'
local associated_class='bos/meta/class'
bos/meta/attribute/store-for-into bos_meta_class_attrs_name "$self"
@@ -144,10 +146,10 @@ function bos/meta/class/set-attribute-by-name() {
function bos/meta/class/find-attribute-into() {
local -n bos_meta_class_find_attribute_result="$1"
- local class="$2"
- local attribute_name="$4"
+ local bos_meta_class_find_attribute_class="$2"
+ local bos_meta_class_find_attribute_attribute_name="$3"
- local mro_store; $self mro-for-into mro_store "$class"
+ local mro_store; $self mro-for-into mro_store "$bos_meta_class_find_attribute_class"
local -n mro="$mro_store"
# minimal MRO: the class itself
@@ -161,7 +163,7 @@ function bos/meta/class/find-attribute-into() {
for bos_class_from_mro in "${mro[@]}"; do
bos-meta/metaclass-instance-for-class-into bos_meta_class_for_class "$bos_class_from_mro"
- $bos_meta_class_for_class get-attribute-by-name-into bos_meta_class_find_attribute_result "$attribute_name"
+ $bos_meta_class_for_class get-attribute-by-name-into bos_meta_class_find_attribute_result "$bos_meta_class_find_attribute_attribute_name"
if [[ -n "$bos_meta_class_find_attribute_result" ]]; then
return 0
@@ -175,19 +177,19 @@ function bos/meta/class/find-attribute-into() {
# the method dispatcher
function bos/meta/class/invoke() {
- local class="$1";shift
- local object_id="$1";shift
- local method="$1";shift
+ local bos_invoke_class="$1";shift
+ local bos_invoke_object_id="$1";shift
+ local bos_invoke_method="$1";shift
- local start_from_class=''
+ local bos_invoke_start_from_class=''
- if [[ "$method" == 'next/method' ]]; then
+ if [[ "$bos_invoke_method" == 'next/method' ]]; then
# get the method and the calling class, so
# bos_find_class_for_method will return the *next* class to
# use
- local caller; bos-dispatch/caller-into caller
- method="${caller##*/}"
- start_from_class="${caller%/*}"
+ local bos_invoke_caller; bos-dispatch/caller-into bos_invoke_caller
+ bos_invoke_method="${bos_invoke_caller##*/}"
+ bos_invoke_start_from_class="${bos_invoke_caller%/*}"
fi
# get the first class that defines the method
@@ -196,12 +198,34 @@ function bos/meta/class/invoke() {
# local; this is a probably-bad-but-works workaround: use a
# different variable name in different recursive calls
local ffsname="to_invoke_${#FUNCNAME[*]}"
- $self find-method-into "$ffsname" "$class" "$start_from_class" "$method"
+ $self find-method-into "$ffsname" "$bos_invoke_class" "$bos_invoke_start_from_class" "$bos_invoke_method"
+
+ local bos_invoke_attrs_attr
+ $self find-attribute-into bos_invoke_attrs_attr "$bos_invoke_class" 'class_attributes'
+
+ if [[ -n "$bos_invoke_attrs_attr" ]]; then
+ local -A bos_invoke_attrs
+ $bos_invoke_attrs_attr get-value-into bos_invoke_attrs "$self"
- # TODO: make the fields accessible!
+ local bos_invoke_attr_name bos_invoke_attr_obj bos_invoke_attr_type
+ for bos_invoke_attr_name in "${!bos_invoke_attrs[@]}"; do
+ bos_invoke_attr_obj="${bos_invoke_attrs[$bos_invoke_attr_name]}"
+
+ >&2 echo "getting attribute type from $bos_invoke_attr_name=($bos_invoke_attr_obj)"
+ $bos_invoke_attr_obj get-attribute-type-into bos_invoke_attr_type
+
+ case "$bos_invoke_attr_type" in
+ scalar) local "$bos_invoke_attr_name" ;;
+ array) local -a "$bos_invoke_attr_name" ;;
+ assoc) local -A "$bos_invoke_attr_name" ;;
+ esac
+
+ $bos_invoke_attr_obj get-value-into "$bos_invoke_attr_name"
+ done
+ fi
local self
- bos-object-id/pack-self-into self "$class" "$object_id"
+ bos-object-id/pack-self-into self "$bos_invoke_class" "$bos_invoke_object_id"
# call it
eval "\"\$$ffsname\" \"\$@\""