diff options
-rw-r--r-- | bos-namespaces.sh | 16 | ||||
-rw-r--r-- | bos-sugar.sh | 29 | ||||
-rw-r--r-- | meta-stuff.rst.txt | 4 |
3 files changed, 28 insertions, 21 deletions
diff --git a/bos-namespaces.sh b/bos-namespaces.sh index 02f3df2..d36b87e 100644 --- a/bos-namespaces.sh +++ b/bos-namespaces.sh @@ -112,3 +112,19 @@ function bos-namespaces/qualify-funcs() { return 0 } + +function bos-namespaces/namespace-open() { + bos-namespaces/push "$1" + bos-namespaces/save-funcs + + return 0 +} + +function bos-namespaces/namespace-close() { + local -a methods_list; bos-namespaces/list-new-funcs-into methods_list + bos-namespaces/qualify-funcs "${methods_list[@]}" + + bos-namespaces/pop + + return 0 +} diff --git a/bos-sugar.sh b/bos-sugar.sh index 1322b36..f211f97 100644 --- a/bos-sugar.sh +++ b/bos-sugar.sh @@ -44,13 +44,6 @@ function bos-sugar/class-open() { return 1 fi - local class="$1" - bos-namespaces/push "$class" - - local fq_class; bos-namespaces/current-namespace-into fq_class - - bos-sugar/set-metaclass-for "$fq_class" - function extends() { local fq_class; bos-namespaces/current-namespace-into fq_class local metaclass_ref; bos-namespaces/store-scalar-for-into metaclass_ref meta "$fq_class" @@ -58,9 +51,11 @@ function bos-sugar/class-open() { $metaclass_object set-superclasses-for "$fq_class" "$@" } - eval "function $fq_class { bos-dispatch/invoke \"$fq_class\" 0 \"\$@\"; }" + local class="$1" + bos-namespaces/namespace-open "$1" - bos-namespaces/save-funcs + local fq_class; bos-namespaces/current-namespace-into fq_class + bos-sugar/set-metaclass-for "$fq_class" # this will get renamed into the class function new-into() { @@ -70,7 +65,7 @@ function bos-sugar/class-open() { local -n metaclass_object="$metaclass_ref" local new_object - $metaclass_object create-object-into new_object "$class" + $metaclass_object create-object-into new_object "$class" "$@" new_into_result="$new_object" } @@ -85,12 +80,12 @@ function bos-sugar/class-close() { local metaclass_ref; bos-namespaces/store-scalar-for-into metaclass_ref meta "$fq_class" local -n metaclass_object="$metaclass_ref" - local -a methods_list; bos-namespaces/list-new-funcs-into methods_list - bos-namespaces/qualify-funcs "${methods_list[@]}" + bos-namespaces/namespace-close $metaclass_object make-mro-for "$fq_class" - bos-namespaces/pop + # TODO this should probably be done by the metaclass? + eval "function $fq_class { bos-dispatch/invoke \"$fq_class\" 0 \"\$@\"; }" return 0 } @@ -103,17 +98,13 @@ function bos-sugar/namespace-open() { return 1 fi - bos-namespaces/push "$1" - bos-namespaces/save-funcs + bos-namespaces/namespace-open "$1" return 0 } function bos-sugar/namespace-close() { - local -a methods_list; bos-namespaces/list-new-funcs-into methods_list - bos-namespaces/qualify-funcs "${methods_list[@]}" - - bos-namespaces/pop + bos-namespaces/namespace-close return 0 } diff --git a/meta-stuff.rst.txt b/meta-stuff.rst.txt index 2a990e8..c53fb7d 100644 --- a/meta-stuff.rst.txt +++ b/meta-stuff.rst.txt @@ -4,12 +4,12 @@ done bits variable name as 1st argument (otherwise optional arguments become a mess) -next bits… - * expose namespace open/close, and ``namespace $name; do …; done`` - use them inside ``class_open`` / ``class_close`` +next bits… + * formalise that ``bos-dispatch/invoke $class 0 $method $args`` is a class method invocation |