Index: TODO =================================================================== diff -u -r57cbc3cee2f970fd9a166109529a8685cc07658e -r1b0a690f760447d8fc63aeded3e62c723e592c64 --- TODO (.../TODO) (revision 57cbc3cee2f970fd9a166109529a8685cc07658e) +++ TODO (.../TODO) (revision 1b0a690f760447d8fc63aeded3e62c723e592c64) @@ -3031,9 +3031,19 @@ - reamed ObjectParameterSlot attribute from nosetter => accessor (positive formulation) +- nsf.c: make sure to always initialize variables +- first draft of separation of attribute -> variable + accessor + TODO: + - maybe use (position == -1) instead of (objectparameter == false) to save common vars + - optimization of plain variable in per-object case + - cleanup variable/attribute + - testing variable/attribute + - maybe change default + createBootstrapAttributeSlots ::nx::Attribute {accessor true} -> false + - Revise callstack introspection/intercession, i.e., [current activelevel] vs. [current callinglevel] vs. uplevel()/upvar(): Index: library/nx/nx.tcl =================================================================== diff -u -r57cbc3cee2f970fd9a166109529a8685cc07658e -r1b0a690f760447d8fc63aeded3e62c723e592c64 --- library/nx/nx.tcl (.../nx.tcl) (revision 57cbc3cee2f970fd9a166109529a8685cc07658e) +++ library/nx/nx.tcl (.../nx.tcl) (revision 1b0a690f760447d8fc63aeded3e62c723e592c64) @@ -741,10 +741,11 @@ -per-object:switch {-class ""} {-initblock ""} + {-defaultopts ""} value default:optional } { - set opts [list] + set opts $defaultopts set colonPos [string first : $value] if {$colonPos == -1} { set name $value @@ -851,6 +852,7 @@ # set for every bootstrap attribute slot the position 0 # ::nsf::var::set $slotObj position 0 + ::nsf::var::set $slotObj objectparameter 1 } #puts stderr "Bootstrapslot for $class calls invalidateobjectparameter" @@ -921,6 +923,7 @@ {forwardername} {defaultmethods {get assign}} {accessor false} + {objectparameter true} {noarg} {disposition alias} {required false} @@ -1087,7 +1090,11 @@ # ensure partial ordering and avoid sorting. # foreach slot [nsf::dispatch [self] ::nsf::methods::class::info::slots -closure -type ::nx::Slot] { - lappend defs([$slot position]) [$slot getParameterSpec] + if {[::nsf::var::exists $slot objectparameter] && [::nsf::var::set $slot objectparameter]} { + lappend defs([$slot position]) [$slot getParameterSpec] + } else { + #puts stderr "== no objectparameter for $slot !" + } } # # Fold the per-position lists into a common list @@ -1411,17 +1418,22 @@ return 1 } - ::nx::Attribute protected method makeAccessor {} { + ::nx::Attribute public method makeAccessor {} { if {!${:accessor}} { #puts stderr "Do not register forwarder ${:domain} ${:name}" - return + return 0 } if {[:needsForwarder]} { - :makeForwarder + set handle [:makeForwarder] :makeIncrementalOperations } else { - :makeSetter + set handle [:makeSetter] } + ::nsf::method::property ${:domain} \ + {*}[expr {${:per-object} ? "-per-object" : ""}] \ + $handle call-protected \ + [::nsf::dispatch ${:domain} __default_attribute_call_protection] + return 1 } ::nx::Attribute public method reconfigure {} { @@ -1582,15 +1594,73 @@ return $r } + nx::Object method variable { + {-class ""} + {-initblock ""} + {-objectparameter false} + {-accessor false} + spec + default:optional + } { + set r [::nx::MetaSlot createFromParameterSpec [::nsf::self] \ + -per-object \ + -class $class \ + -initblock $initblock \ + -defaultopts [list -accessor $accessor -objectparameter $objectparameter] \ + $spec \ + {*}[expr {[info exists default] ? [list $default] : ""}]] + return $r + } + + Object method attribute {spec {-class ""} {initblock ""}} { + set r [[self] ::nsf::classes::nx::Object::variable \ + -class $class \ + -initblock $initblock \ + -accessor true \ + -objectparameter true \ + {*}$spec] + return $r + } + + nx::Class method variable { + {-class ""} + {-initblock ""} + {-objectparameter false} + {-accessor false} + spec + default:optional + } { + set r [::nx::MetaSlot createFromParameterSpec [::nsf::self] \ + -class $class \ + -initblock $initblock \ + -defaultopts [list -accessor $accessor -objectparameter $objectparameter] \ + $spec \ + {*}[expr {[info exists default] ? [list $default] : ""}]] + return $r + } + + Class method attribute {spec {-class ""} {initblock ""}} { + set r [[self] ::nsf::classes::nx::Class::variable \ + -class $class \ + -initblock $initblock \ + -accessor true \ + -objectparameter true \ + {*}$spec] + return $r + } + + ###################################################################### # Define method "attributes" for convenience to define multiple # attributes based on a list of parameter specifications. ###################################################################### Class public method attributes arglist { - set slotContainer [::nx::slotObj [::nsf::self]] + set slotContainer [::nx::slotObj [::nsf::self]] + puts stderr slotContainer=$slotContainer foreach arg $arglist { - ::nx::MetaSlot createFromParameterSpec [::nsf::self] {*}$arg + #::nx::MetaSlot createFromParameterSpec [::nsf::self] {*}$arg + [self] ::nsf::classes::nx::Class::attribute $arg } ::nsf::var::set $slotContainer __parameter $arglist } @@ -1693,7 +1763,7 @@ :method makeTargetList {t} { lappend :targetList $t - #puts stderr "COPY makeTargetList $t target= ${:targetList}" + #puts stderr "COPY makeTargetList $t targetList '${:targetList}'" # if it is an object without namespace, it is a leaf if {[::nsf::object::exists $t]} { if {[::nsf::dispatch $t ::nsf::methods::object::info::hasnamespace]} { @@ -1720,6 +1790,7 @@ } :method copyNSVarsAndCmds {orig dest} { + puts stderr "::nsf::nscopyvars $orig $dest" ::nsf::nscopyvars $orig $dest ::nsf::nscopycmds $orig $dest } @@ -1886,7 +1957,6 @@ ###################################################################### # some utilities ###################################################################### - # # Provide mechanisms to configure nx # Index: library/xotcl/library/xotcl2.tcl =================================================================== diff -u -r396bf130d2a1dc934b01522a105bc93fa003f237 -r1b0a690f760447d8fc63aeded3e62c723e592c64 --- library/xotcl/library/xotcl2.tcl (.../xotcl2.tcl) (revision 396bf130d2a1dc934b01522a105bc93fa003f237) +++ library/xotcl/library/xotcl2.tcl (.../xotcl2.tcl) (revision 1b0a690f760447d8fc63aeded3e62c723e592c64) @@ -248,6 +248,7 @@ ::nsf::method::property Class dealloc redefine-protected true ::nsf::method::property Class create redefine-protected true + # # define parametercmd and instparametercmd in terms of ::nsf::setter # define filterguard and instfilterguard in terms of filterguard @@ -340,7 +341,8 @@ set r [::nsf::method::forward [self] $method {*}$arglist] return $r } - + + Class instproc unknown {args} { #puts stderr "use '[self] create $args', not '[self] $args'" uplevel [list [self] create {*}$args] @@ -374,6 +376,13 @@ return $parameterdefinitions } + ###################################################################### + # Define default attribute protection before calling :attribute + ###################################################################### + ::nsf::method::create ::xotcl::Object __default_attribute_call_protection args {return false} + ::nsf::method::property ::xotcl::Object __default_attribute_call_protection call-protected true + + # # Use parameter definition from nx # (same with classInfo parameter, see below) Index: tests/disposition.test =================================================================== diff -u -rdedef29f68094a6083cbc91cb0803c3b1f0c0e68 -r1b0a690f760447d8fc63aeded3e62c723e592c64 --- tests/disposition.test (.../disposition.test) (revision dedef29f68094a6083cbc91cb0803c3b1f0c0e68) +++ tests/disposition.test (.../disposition.test) (revision 1b0a690f760447d8fc63aeded3e62c723e592c64) @@ -1389,7 +1389,7 @@ nx::Test parameter count 1000 -nx::Test case xotcl-residualargs { +nx::Test case xotcl-residualargs2 { ::xotcl::Class create XC -parameter {a b c} ::XC instproc init args {set :x $args; incr :y} Index: tests/info-method.test =================================================================== diff -u -rcef0608bea97458e5dcd87615c9b8ca3fe7b464c -r1b0a690f760447d8fc63aeded3e62c723e592c64 --- tests/info-method.test (.../info-method.test) (revision cef0608bea97458e5dcd87615c9b8ca3fe7b464c) +++ tests/info-method.test (.../info-method.test) (revision 1b0a690f760447d8fc63aeded3e62c723e592c64) @@ -124,8 +124,8 @@ ? {::nx::Object info lookup methods -source application} "" ? {::nx::Class info lookup methods -source application} "" - set object_methods "alias attribute configure contains copy delete destroy eval filter forward info method mixin move protected public require volatile" - set class_methods "alias attribute attributes class configure contains copy create delete destroy eval filter forward info method mixin move new protected public require volatile" + set object_methods "alias attribute configure contains copy delete destroy eval filter forward info method mixin move protected public require variable volatile" + set class_methods "alias attribute attributes class configure contains copy create delete destroy eval filter forward info method mixin move new protected public require variable volatile" ? {lsort [::nx::Object info lookup methods -source baseclasses]} $class_methods ? {lsort [::nx::Class info lookup methods -source baseclasses]} $class_methods