summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2023-07-28 12:09:50 +0100
committerdakkar <dakkar@thenautilus.net>2023-07-28 12:09:50 +0100
commit1587b16d91c69932470dc74284b2f615bda74032 (patch)
tree2dfc172853695fa7c6d63ae7bef4edd91affe243
parentless broken (diff)
downloadbash-object-system-1587b16d91c69932470dc74284b2f615bda74032.tar.gz
bash-object-system-1587b16d91c69932470dc74284b2f615bda74032.tar.bz2
bash-object-system-1587b16d91c69932470dc74284b2f615bda74032.zip
probably fix exposing attributes
now they're aliases… still completely untested, because: * we're not exposing attributes on direct dispatch (`bos-dispatch/invoke`) * we don't have a decent way to add attributes to classes (`bos-sugar/*`)
-rw-r--r--bos-meta-attribute.sh14
-rw-r--r--bos-meta-class.sh62
2 files changed, 27 insertions, 49 deletions
diff --git a/bos-meta-attribute.sh b/bos-meta-attribute.sh
index 9d7a4dd..1153d3a 100644
--- a/bos-meta-attribute.sh
+++ b/bos-meta-attribute.sh
@@ -6,6 +6,20 @@ function bos/meta/attribute/store-for-into() {
local bos_meta_attribute_class bos_meta_attribute_objid
bos-object/unpack-self-into bos_meta_attribute_class bos_meta_attribute_objid "$2"
+ # meta-look! we can't depend on bos-dispatch/invoke or
+ # bos/meta/class/invoke to set these up
+
+ # the `if` is there because bos-meta-bootstrap.sh sets these manually
+ if [[ -z "$attribute_name" ]]; then
+ local bos_meta_attribute_get_name; $self get-attribute-name-into bos_meta_attribute_get_name
+ local bos_meta_attribute_get_type; $self get-attribute-type-into bos_meta_attribute_get_type
+ local bos_meta_attribute_get_class; $self get-associated-class-into bos_meta_attribute_get_class
+
+ local attribute_name="$bos_meta_attribute_get_name"
+ local attribute_type="$bos_meta_attribute_get_type"
+ local associated_class="$bos_meta_attribute_get_class"
+ fi
+
"bos-namespaces/store-${attribute_type}-for-into" "$1" attribute "$attribute_name" "$associated_class" "$bos_meta_attribute_class" "$bos_meta_attribute_objid"
}
diff --git a/bos-meta-class.sh b/bos-meta-class.sh
index bd83c29..586eee5 100644
--- a/bos-meta-class.sh
+++ b/bos-meta-class.sh
@@ -143,40 +143,6 @@ function bos/meta/class/set-attribute-by-name() {
return 0
}
-
-function bos/meta/class/find-attribute-into() {
- local -n bos_meta_class_find_attribute_result="$1"
- 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 "$bos_meta_class_find_attribute_class"
- local -n mro="$mro_store"
-
- # minimal MRO: the class itself
- if [[ "${#mro[@]}" -eq 0 ]]; then
- mro=( "$bos_meta_class_find_attribute_class" )
- fi
-
- local bos_meta_class_for_class
- local bos_class_from_mro
-
- for bos_class_from_mro in "${mro[@]}"; do
- bos-meta/metaclass-instance-for-class-into bos_meta_class_for_class "$bos_class_from_mro"
-
- >&2 echo "from mro(${mro[*]})=$bos_class_from_mro meta=$bos_meta_class_for_class"
-
- $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
- fi
- done
-
- # TODO: better error / failure
- >&2 echo "attribute $bos_meta_class_find_attribute_attribute_name not found via class $bos_meta_class_find_attribute_class"
- return 1
-}
-
# the method dispatcher
function bos/meta/class/invoke() {
local bos_invoke_class="$1";shift
@@ -202,34 +168,32 @@ function bos/meta/class/invoke() {
local ffsname="to_invoke_${#FUNCNAME[*]}"
$self find-method-into "$ffsname" "$bos_invoke_class" "$bos_invoke_start_from_class" "$bos_invoke_method"
+ local bos_invoke_target_obj
+ bos-object-id/pack-self-into bos_invoke_target_obj "$bos_invoke_class" "$bos_invoke_object_id"
+
local bos_invoke_target_class="${!ffsname%/*}"
+ local bos_invoke_target_metaclass_instance
+ bos-meta/metaclass-instance-for-class-into bos_invoke_target_metaclass_instance "$bos_invoke_target_class"
+
local bos_invoke_attrs_attr
- $self find-attribute-into bos_invoke_attrs_attr "$bos_invoke_target_class" 'class_attributes'
+ $bos_invoke_target_metaclass_instance get-attribute-by-name-into bos_invoke_attrs_attr 'class_attributes'
>&2 echo "for (${bos_invoke_class}->${bos_invoke_target_class}) class_attributes = $bos_invoke_attrs_attr"
if [[ -n "$bos_invoke_attrs_attr" ]]; then
local -A bos_invoke_attrs
- $bos_invoke_attrs_attr get-value-into bos_invoke_attrs "$self"
- local bos_invoke_attr_name bos_invoke_attr_obj bos_invoke_attr_type
+ $bos_invoke_attrs_attr get-value-into bos_invoke_attrs "$bos_invoke_target_metaclass_instance"
+
+ local bos_invoke_attr_name bos_invoke_attr_store
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" "$self"
+ $bos_invoke_attr_obj store-for-into bos_invoke_attr_store "$bos_invoke_target_obj"
+ local -n "$bos_invoke_attr_name"="$bos_invoke_attr_store"
done
fi
- local self
- bos-object-id/pack-self-into self "$bos_invoke_class" "$bos_invoke_object_id"
+ local self="$bos_invoke_target_obj"
# call it
eval "\"\$$ffsname\" \"\$@\""