summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGianni Ceccarelli <gianni.ceccarelli@broadbean.com>2023-07-27 16:05:41 +0100
committerGianni Ceccarelli <gianni.ceccarelli@broadbean.com>2023-07-27 16:11:10 +0100
commit8e235105c5d98c4daa431c12f2136f89eaeb128d (patch)
tree744db4c3201035db243d5cf957ef6c24d643bc50
parentmore flexible namespaced stores (diff)
downloadbash-object-system-8e235105c5d98c4daa431c12f2136f89eaeb128d.tar.gz
bash-object-system-8e235105c5d98c4daa431c12f2136f89eaeb128d.tar.bz2
bash-object-system-8e235105c5d98c4daa431c12f2136f89eaeb128d.zip
vaguely bootstrap things?
-rw-r--r--bos-meta-attribute.sh9
-rw-r--r--bos-meta-bootstrap.sh148
-rw-r--r--bos-meta-class.sh39
-rw-r--r--t/testlib.sh2
4 files changed, 183 insertions, 15 deletions
diff --git a/bos-meta-attribute.sh b/bos-meta-attribute.sh
index 78c573e..b5155ad 100644
--- a/bos-meta-attribute.sh
+++ b/bos-meta-attribute.sh
@@ -6,12 +6,13 @@ 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"
- "bos-namespaces/${attribute_type}-store-for-into" "$1" attribute "$attribute_name" "$associated_class" "$bos_meta_attribute_class" "$bos_meta_attribute_objid"
+ "bos-namespaces/store-${attribute_type}-for-into" "$1" attribute "$attribute_name" "$associated_class" "$bos_meta_attribute_class" "$bos_meta_attribute_objid"
}
function bos/meta/attribute/set-value() {
- local bos_meta_attribute_store; $self store-for-into bos_meta_attribute_store "$1"
+ local bos_meta_attribute_store_name; $self store-for-into bos_meta_attribute_store_name "$1"
shift
+ local -n bos_meta_attribute_store="$bos_meta_attribute_store_name"
case "$attribute_type" in
scalar) bos_meta_attribute_store="$1" ;;
@@ -25,7 +26,8 @@ function bos/meta/attribute/set-value() {
function bos/meta/attribute/get-value-into() {
local -n bos_meta_attribute_result="$1"; shift;
- local bos_meta_attribute_store; $self store-for-into bos_meta_attribute_store "$1"
+ local bos_meta_attribute_store_name; $self store-for-into bos_meta_attribute_store_name "$1"
+ local -n bos_meta_attribute_store="$bos_meta_attribute_store_name"
case "$attribute_type" in
scalar) bos_meta_attribute_result="$bos_meta_attribute_store" ;;
@@ -35,4 +37,3 @@ function bos/meta/attribute/get-value-into() {
return 0
}
-
diff --git a/bos-meta-bootstrap.sh b/bos-meta-bootstrap.sh
new file mode 100644
index 0000000..f301812
--- /dev/null
+++ b/bos-meta-bootstrap.sh
@@ -0,0 +1,148 @@
+#!bash
+
+## metaclass instance for bos/meta/class itself
+
+declare bos_meta_class_meta_class_instance
+bos/meta/class/create-object-into bos_meta_class_meta_class_instance bos/meta/class
+bos-meta/set-metaclass-instance-for bos/meta/class "$bos_meta_class_meta_class_instance"
+
+$bos_meta_class_meta_class_instance make-mro-for bos/meta/class
+
+# metaclass instance for bos/meta/attribute
+
+declare bos_meta_attribute_meta_class_instance
+bos/meta/class/create-object-into bos_meta_attribute_meta_class_instance bos/meta/class
+bos-meta/set-metaclass-instance-for bos/meta/attribute "$bos_meta_attribute_meta_class_instance"
+
+$bos_meta_attribute_meta_class_instance make-mro-for bos/meta/attribute
+
+# here we create meta-attributes for the three attributes of
+# bos/meta/attribute: attribute_name attribute_type associated_class
+# and register them with the $bos_meta_attribute_meta_class_instance
+
+## we'll re-use this name
+declare bos_meta_attribute_instance
+
+## this is the `attribute_name` meta-attribute
+bos/meta/class/create-object-into bos_meta_attribute_instance bos/meta/attribute
+
+attribute_type='scalar'
+associated_class='bos/meta/attribute'
+
+attribute_name='attribute_name'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" attribute_name
+
+attribute_name='attribute_type'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" scalar
+
+attribute_name='associated_class'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" bos/meta/attribute
+
+$bos_meta_attribute_meta_class_instance set-attribute-by-name 'attribute_name' "$bos_meta_attribute_instance"
+
+## this is the `attribute_type` meta-attribute
+bos/meta/class/create-object-into bos_meta_attribute_instance bos/meta/attribute
+
+attribute_type='scalar'
+associated_class='bos/meta/attribute'
+
+attribute_name='attribute_name'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" attribute_type
+
+attribute_name='attribute_type'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" scalar
+
+attribute_name='associated_class'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" bos/meta/attribute
+
+$bos_meta_attribute_meta_class_instance set-attribute-by-name 'attribute_type' "$bos_meta_attribute_instance"
+
+## this is the `associated_class` meta-attribute
+bos/meta/class/create-object-into bos_meta_attribute_instance bos/meta/attribute
+
+attribute_type='scalar'
+associated_class='bos/meta/attribute'
+
+attribute_name='attribute_name'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" associated_class
+
+attribute_name='attribute_type'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" scalar
+
+attribute_name='associated_class'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" bos/meta/attribute
+
+$bos_meta_attribute_meta_class_instance set-attribute-by-name 'associated_class' "$bos_meta_attribute_instance"
+
+# now we set the attributes for bos/meta/class!
+
+## this is the `class-attributes` meta-attribute
+bos/meta/class/create-object-into bos_meta_attribute_instance bos/meta/attribute
+
+attribute_type='scalar'
+associated_class='bos/meta/class'
+
+attribute_name='attribute_name'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" 'class-attributes'
+
+attribute_name='attribute_type'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" assoc
+
+attribute_name='associated_class'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" bos/meta/class
+
+$bos_meta_class_meta_class_instance set-attribute-by-name 'class-attributes' "$bos_meta_attribute_instance"
+
+## this is the `class-name` meta-attribute
+bos/meta/class/create-object-into bos_meta_attribute_instance bos/meta/attribute
+
+attribute_type='scalar'
+associated_class='bos/meta/class'
+
+attribute_name='attribute_name'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" 'class-name'
+
+attribute_name='attribute_type'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" scalar
+
+attribute_name='associated_class'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" bos/meta/class
+
+$bos_meta_class_meta_class_instance set-attribute-by-name 'class-name' "$bos_meta_attribute_instance"
+
+## this is the `isa` meta-attribute
+bos/meta/class/create-object-into bos_meta_attribute_instance bos/meta/attribute
+
+attribute_type='scalar'
+associated_class='bos/meta/class'
+
+attribute_name='attribute_name'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" 'isa'
+
+attribute_name='attribute_type'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" arary
+
+attribute_name='associated_class'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" bos/meta/class
+
+$bos_meta_class_meta_class_instance set-attribute-by-name 'isa' "$bos_meta_attribute_instance"
+
+## this is the `mro` meta-attribute
+bos/meta/class/create-object-into bos_meta_attribute_instance bos/meta/attribute
+
+attribute_type='scalar'
+associated_class='bos/meta/class'
+
+attribute_name='attribute_name'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" 'mro'
+
+attribute_name='attribute_type'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" arary
+
+attribute_name='associated_class'
+$bos_meta_attribute_instance set-value "$bos_meta_attribute_instance" bos/meta/class
+
+$bos_meta_class_meta_class_instance set-attribute-by-name 'mro' "$bos_meta_attribute_instance"
+
+unset bos_meta_class_meta_class_instance bos_meta_attribute_instance attribute_name attribute_type associated_class
+
diff --git a/bos-meta-class.sh b/bos-meta-class.sh
index 4884d40..ec3c03e 100644
--- a/bos-meta-class.sh
+++ b/bos-meta-class.sh
@@ -103,17 +103,42 @@ 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 -A bos_meta_class_attrs
+ local -n bos_meta_class_get_attribute_result="$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 associated_class='bos/meta/class'
- bos/meta/attribute/store-for-into bos_meta_class_attrs "$self"
+ bos/meta/attribute/store-for-into bos_meta_class_attrs_name "$self"
- return "${bos_meta_class_attrs[$1]}"
+ local -n bos_meta_class_attrs="$bos_meta_class_attrs_name"
+
+ bos_meta_class_get_attribute_result="${bos_meta_class_attrs[$1]}"
+
+ return 0
+}
+
+function bos/meta/class/set-attribute-by-name() {
+ 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 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_attrs["$1"]="$2"
+
+ return 0
}
@@ -201,11 +226,3 @@ function bos/meta/class/create-object-into() {
function bos/meta/class() {
bos-dispatch/invoke bos/meta/class 0 "$@"
}
-
-declare bos_meta_class_meta_class_instance
-bos/meta/class/create-object-into bos_meta_class_meta_class_instance bos/meta/class
-bos-meta/set-metaclass-instance-for bos/meta/class "$bos_meta_class_meta_class_instance"
-
-$bos_meta_class_meta_class_instance make-mro-for bos/meta/class
-
-unset bos_meta_class_meta_class_instance
diff --git a/t/testlib.sh b/t/testlib.sh
index d506257..556afd1 100644
--- a/t/testlib.sh
+++ b/t/testlib.sh
@@ -9,6 +9,8 @@ PS4='[${#FUNCNAME[*]}] ${BASH_SOURCE[0]}:${LINENO} (${FUNCNAME[0]}) +'
. bos-base.sh
. bos-meta.sh
. bos-meta-class.sh
+. bos-meta-attribute.sh
+. bos-meta-bootstrap.sh
. bos-sugar.sh
. minitap.sh