Index: library/nx/nx.tcl =================================================================== diff -u -r6458c13882afd52e8719ee0e0e054b42e9aee696 -radc4affd14701109f5d9b655dddf58d6b42cd781 --- library/nx/nx.tcl (.../nx.tcl) (revision 6458c13882afd52e8719ee0e0e054b42e9aee696) +++ library/nx/nx.tcl (.../nx.tcl) (revision adc4affd14701109f5d9b655dddf58d6b42cd781) @@ -340,33 +340,40 @@ path } { # TODO: handle -create (actually, its absence) + #puts "resolve_method_path" set methodName $path if {[string first " " $path]} { set methodName [lindex $path end] foreach w [lrange $path 0 end-1] { - #puts stderr "check $object info methods $w => '[$object info methods -methodtype all $w]'" + #puts stderr "check $object info methods $path @ <$w>" set scope [expr {[nsf::objectproperty $object class] && !${per-object} ? "Class" : "Object"}] - if {[::nsf::cmd::${scope}Info::methods $object -methodtype all $w] eq ""} { + if {[::nsf::dispatch $object ::nsf::cmd::${scope}Info2::methods -methodtype all $w] eq ""} { # # Create dispatch object an accessor method (if wanted) # - set o [Object create ${object}::$w] - if {$verbose} {puts stderr "... create object $o"} if {$scope eq "Class"} { - # we are on a class, and have to create an alias to be + if {![::nsf::objectproperty ${object}::slot object]} { + Object create ${object}::slot + if {$verbose} {puts stderr "... create object ${object}::slot"} + } + set o [Object create ${object}::slot::__$w] + if {$verbose} {puts stderr "... create object $o"} + # We are on a class, and have to create an alias to be # accessible for objects ::nsf::alias $object $w $o if {$verbose} {puts stderr "... create alias $object $w $o"} + } else { + set o [Object create ${object}::$w] + if {$verbose} {puts stderr "... create object $o"} } - #puts stderr "... $object info methods $w => '[$object info methods -methodtype all $w]'" set object $o } else { # # The accessor method exists already, check, if it is # appropriate for extending. # - set type [::nsf::cmd::${scope}Info::method $object type $w] - set definition [::nsf::cmd::${scope}Info::method $object definition $w] + set type [::nsf::dispatch $object ::nsf::cmd::${scope}Info2::method type $w] + set definition [::nsf::dispatch $object ::nsf::cmd::${scope}Info2::method definition $w] if {$scope eq "Class"} { if {$type ne "alias"} {error "can't append to $type"} if {$definition eq ""} {error "definition must not be empty"} @@ -416,6 +423,7 @@ if {[info exists precondition]} {lappend conditions -precondition $precondition} if {[info exists postcondition]} {lappend conditions -postcondition $postcondition} array set "" [::nx::Object resolve_method_path -create -verbose [::nsf::current object] $name] + #puts "class method $(object).$(methodName) [list $arguments] {...}" set r [::nsf::method $(object) $(methodName) $arguments $body {*}$conditions] if {[info exists returns]} {nsf::methodproperty $(object) $r returns $returns} return $r @@ -449,6 +457,7 @@ if {[info exists precondition]} {lappend conditions -precondition $precondition} if {[info exists postcondition]} {lappend conditions -postcondition $postcondition} array set "" [::nx::Object resolve_method_path -create -per-object -verbose [::nsf::current object] $name] + #puts "object method $(object).$(methodName) [list $arguments] {...}" set r [::nsf::method $(object) -per-object $(methodName) $arguments $body {*}$conditions] if {[info exists returns]} {nsf::methodproperty $(object) $r returns $returns} return $r @@ -463,7 +472,7 @@ return [::nsf::dispatch [::nsf::current object] ::nsf::classes::nx::Object::$what {*}$args] } if {$what in [list "info"]} { - return [::nx::objectInfo [lindex $args 0] [::nsf::current object] {*}[lrange $args 1 end]] + return [::nsf::dispatch [::nsf::current object] ::nx::Object::slot::__info [lindex $args 0] {*}[lrange $args 1 end]] } if {$what in [list "filter" "mixin"]} { # @@ -637,20 +646,24 @@ # Class protected object method __unknown {name} {} - # Add alias methods. cmdName for XOTcl method can be added via + # Add alias methods. cmdName for a method can be added via # [... info method handle ] # # -nonleaf and -objscope make only sense for c-defined cmds, # -objscope implies -nonleaf # Object public method alias {-nonleaf:switch -objscope:switch methodName cmd} { - ::nsf::alias [::nsf::current object] -per-object $methodName \ + array set "" [::nx::Object resolve_method_path -per-object -create -verbose [::nsf::current object] $methodName] + #puts "object alias $(object).$(methodName) $cmd" + ::nsf::alias $(object) -per-object $(methodName) \ {*}[expr {${objscope} ? "-objscope" : ""}] \ {*}[expr {${nonleaf} ? "-nonleaf" : ""}] \ $cmd } Class public method alias {-nonleaf:switch -objscope:switch methodName cmd} { - ::nsf::alias [::nsf::current object] $methodName \ + array set "" [::nx::Object resolve_method_path -create -verbose [::nsf::current object] $methodName] + #puts "class alias $(object).$(methodName) $cmd" + ::nsf::alias $(object) $(methodName) \ {*}[expr {${objscope} ? "-objscope" : ""}] \ {*}[expr {${nonleaf} ? "-nonleaf" : ""}] \ $cmd @@ -684,67 +697,120 @@ } } + # allocate system slot parents + Object alloc ::nx::Class::slot + Object alloc ::nx::Object::slot + ######################## # Info definition ######################## - Object create ::nx::objectInfo - Object create ::nx::classInfo + # we have to use "eval", since objectParameters are not defined yet + Object eval { + :alias "info callable" ::nsf::cmd::ObjectInfo2::callable + :alias "info children" ::nsf::cmd::ObjectInfo2::children + :alias "info class" ::nsf::cmd::ObjectInfo2::class + :alias "info filter guard" ::nsf::cmd::ObjectInfo2::filterguard + :alias "info filter methods" ::nsf::cmd::ObjectInfo2::filtermethods + :alias "info forward" ::nsf::cmd::ObjectInfo2::forward + :alias "info hasnamespace" ::nsf::cmd::ObjectInfo2::hasnamespace + :method "info is" {kind value:optional} {::nsf::objectproperty [::nsf::current object] $kind {*}$value} + :alias "info methods" ::nsf::cmd::ObjectInfo2::methods + :alias "info mixin guard" ::nsf::cmd::ObjectInfo2::mixinguard + :alias "info mixin classes" ::nsf::cmd::ObjectInfo2::mixinclasses + :alias "info parent" ::nsf::cmd::ObjectInfo2::parent + :alias "info precedence" ::nsf::cmd::ObjectInfo2::precedence + :alias "info slotobjects" ::nsf::cmd::ObjectInfo2::slotobjects + :alias "info vars" ::nsf::cmd::ObjectInfo2::vars + } + + # Create the object here to prepare for copy of the above + # definitions. Potentially, some names are overwritten by the + # class. Note, that the automatically created name has to be the + # same. + + Object create ::nx::Class::slot::__info + Class alias info ::nx::Class::slot::__info + # - # It would be nice to do here "objectInfo configure {alias ..}", but - # we have no working objectparameter yet due to bootstrapping + # copy all methods except the subobjects to ::nx::Class::slot::__info # - objectInfo eval { - :alias is ::nsf::objectproperty + foreach m [nsf::dispatch ::nx::Object::slot::__info ::nsf::cmd::ObjectInfo2::methods] { + set definition [nsf::dispatch ::nx::Object::slot::__info ::nsf::cmd::ObjectInfo2::method definition $m] + #puts "$m $definition" + #puts "classInfo [lrange $definition 1 end]" + ::nx::Class::slot::__info {*}[lrange $definition 1 end] + } - # info info - :public method info {obj} { - set methods [list] - foreach name [::nsf::cmd::ObjectInfo::methods -methodtype all [::nsf::current object]] { - if {$name eq "unknown"} continue - lappend methods $name - } - return "valid options are: [join [lsort $methods] {, }]" - } - - :method filter {o submethod args} { - switch $submethod { - guard {::nsf::dispatch $o ::nsf::cmd::ObjectInfo2::filterguard {*}$args} - methods {::nsf::dispatch $o ::nsf::cmd::ObjectInfo2::filtermethods {*}$args} - } - } - :method unknown {method obj args} { - error "[::nsf::current object] unknown info option \"$method\"; [$obj info info]" - } + Class eval { + # TODO: are the next two needed? + :alias "info classparent" ::nsf::cmd::ObjectInfo2::parent + :alias "info classchildren" ::nsf::cmd::ObjectInfo2::children + :alias "info filter guard" ::nsf::cmd::ClassInfo2::filterguard + :alias "info filter methods" ::nsf::cmd::ClassInfo2::filtermethods + :alias "info forward" ::nsf::cmd::ClassInfo2::forward + :alias "info heritage" ::nsf::cmd::ClassInfo2::heritage + :alias "info instances" ::nsf::cmd::ClassInfo2::instances + :alias "info methods" ::nsf::cmd::ClassInfo2::methods + :alias "info mixin guard" ::nsf::cmd::ClassInfo2::mixinguard + :alias "info mixin classes" ::nsf::cmd::ClassInfo2::mixinclasses + :alias "info slots" ::nsf::cmd::ClassInfo2::slots + :alias "info subclass" ::nsf::cmd::ClassInfo2::subclass + :alias "info superclass" ::nsf::cmd::ClassInfo2::superclass } - classInfo eval { - :alias is ::nsf::objectproperty - :alias classparent ::nsf::cmd::ObjectInfo::parent - :alias classchildren ::nsf::cmd::ObjectInfo::children - :method filter {o submethod args} { - switch $submethod { - guard {::nsf::dispatch $o ::nsf::cmd::ClassInfo2::filterguard {*}$args} - methods {::nsf::dispatch $o ::nsf::cmd::ClassInfo2::filtermethods {*}$args} - } + # + # Define "info info" and unknown + # + proc infoOptions {obj} { + puts stderr "$obj INFO '[::nsf::dispatch $obj ::nsf::cmd::ObjectInfo2::methods -methodtype all]'" + set methods [list] + foreach name [::nsf::dispatch $obj ::nsf::cmd::ObjectInfo2::methods -methodtype all] { + if {$name eq "unknown"} continue + lappend methods $name } + return "valid options are: [join [lsort $methods] {, }]" } - foreach cmd [info command ::nsf::cmd::ObjectInfo::*] { - set cmdName [namespace tail $cmd] - ::nsf::alias ::nx::objectInfo $cmdName $cmd - ::nsf::alias ::nx::classInfo $cmdName $cmd + Object method "info unknown" {method obj args} { + error "[::nsf::current object] unknown info option \"$method\"; [$obj info info]" } - foreach cmd [info command ::nsf::cmd::ClassInfo::*] { - set cmdName [namespace tail $cmd] - ::nsf::alias ::nx::classInfo $cmdName $cmd - } - unset cmd + Object method "info info" {} {infoOptions ::nx::Object::slot::__info} + Class method "info info" {} {infoOptions ::nx::Class::slot::__info} + + # finally register method "method" (otherwise, we cannot use "method" above) + Object alias "info method" ::nsf::cmd::ObjectInfo2::method + Class alias "info method" ::nsf::cmd::ClassInfo2::method + # register method "info" on Object and Class - Object forward info -onerror ::nsf::infoError ::nx::objectInfo %1 {%@2 %self} - Class forward info -onerror ::nsf::infoError ::nx::classInfo %1 {%@2 %self} + #Object forward info -onerror ::nsf::infoError ::nx::objectInfo %1 {%@2 %self} + #Class forward info -onerror ::nsf::infoError ::nx::classInfo %1 {%@2 %self} + #Object alias info ::nx::objectInfo + #Class alias info ::nx::classInfo + # TOOD REMOVE BLOCK + # puts "After Info" + # puts object-methods=[Object info methods] + # puts class-methods=[Class info methods] + # puts "" + # puts Object::info-methods=[lsort [nsf::dispatch ::nx::Object::slot::__info ::nsf::cmd::ObjectInfo2::methods]] + # puts Class::info-methods_=[lsort [nsf::dispatch ::nx::Class::slot::__info ::nsf::cmd::ObjectInfo2::methods]] + # puts "" + # puts Object::info-callable=[nsf::dispatch ::nx::Object ::nsf::cmd::ObjectInfo2::callable method info] + # puts Class::info-callable_=[nsf::dispatch ::nx::Class ::nsf::cmd::ObjectInfo2::callable method info] + # puts "" + # puts Object::info-def=[nsf::dispatch ::nx::Object ::nsf::cmd::ClassInfo2::method definition info] + # puts Class::info-def_=[nsf::dispatch ::nx::Class ::nsf::cmd::ClassInfo2::method definition info] + # puts "" + # puts object-superclass=[Object info superclass] + # puts class-superclass=[Class info superclass] + + # # Object create o1 + # # puts obj-info-info=[o1 info info] + # # puts class-info-info=[Object info info] + # puts "" + # # Definition of "abstract method foo ...." # @@ -784,8 +850,8 @@ MetaSlot public method slotName {name baseObject} { # Create slot parent object if needed set slotParent ${baseObject}::slot - if {![::nsf::objectproperty ${slotParent} object]} { - ::nx::Object create ${slotParent} + if {![::nsf::objectproperty $slotParent object]} { + ::nx::Object create $slotParent } return ${slotParent}::$name } @@ -827,13 +893,13 @@ } if {${per-object}} { lappend opts -per-object true - set info ObjectInfo + set info ObjectInfo2 } else { - set info ClassInfo + set info ClassInfo2 } :create [:slotName $name $target] {*}$opts $initblock - return [::nsf::cmd::${info}::method $target handle $name] + return [::nsf::dispatch $target ::nsf::cmd::${info}::method handle $name] } } @@ -884,14 +950,14 @@ # # Perform a second round to set default values for already defined - # objects. + # slot objects. # foreach att $definitions { if {[llength $att]>1} {foreach {att default} $att break} if {[info exists default]} { # checking subclasses is not required during bootstrap - foreach i [::nsf::cmd::ClassInfo::instances $class] { + foreach i [::nsf::dispatch $class ::nsf::cmd::ClassInfo2::instances] { if {![::nsf::existsvar $i $att]} { if {[string match {*\[*\]*} $default]} { set value [::nsf::dispatch $i -objscope ::eval subst $default] @@ -1136,7 +1202,9 @@ proc ::nsf::parametersFromSlots {obj} { set parameterdefinitions [list] - foreach slot [::nx::objectInfo slotobjects $obj] { + foreach slot [::nsf::dispatch $obj ::nsf::cmd::ObjectInfo2::slotobjects] { + # TODO: the following line is just for the somehwat dummy "info slot" + if {![::nsf::objectproperty $slot type ::nx::Slot]} continue # Skip some slots for xotcl; # TODO: maybe different parameterFromSlots for xotcl? if {[::nsf::objectproperty ::xotcl::Object class] @@ -1249,8 +1317,6 @@ # system slots ############################################ proc ::nsf::register_system_slots {os} { - ${os}::Object alloc ${os}::Class::slot - ${os}::Object alloc ${os}::Object::slot # @param ::nx::Class#superclass # @@ -1372,7 +1438,7 @@ ::nsf::register_system_slots ::nx proc ::nsf::register_system_slots {} {} - + ############################################ # Attribute slots ############################################ @@ -1491,14 +1557,14 @@ set perObject "" set infokind Class } - if {[::nsf::cmd::${infokind}Info::method ${:domain} handle ${:name}] ne ""} { + if {[::nsf::dispatch ${:domain} ::nsf::cmd::${infokind}Info2::method handle ${:name}] ne ""} { #puts stderr "OPTIMIZER RESETTING ${:domain} slot ${:name}" ::nsf::forward ${:domain} {*}$perObject ${:name} \ ${:manager} \ [list %1 [${:manager} defaultmethods]] %self \ ${:methodname} } - #puts stderr "OPTIMIZER incremental [info exists :incremental] def '[set :defaultmethods]'" + #puts "*** stderr "OPTIMIZER incremental [info exists :incremental] def '[set :defaultmethods]'" if {[info exists :incremental] && ${:incremental}} return if {[set :defaultmethods] ne {get assign}} return @@ -1555,7 +1621,9 @@ if {![::nsf::objectproperty $slot object]} {Object create $slot} ::nsf::setvar $slot __parameter $arglist } - ::nsf::method classInfo parameter {class} { + + Class method "info parameter" {} { + set class [::nsf::current object] set slot ${class}::slot if {![::nsf::objectproperty $slot object]} {Object create $slot} if {[::nsf::existsvar $slot __parameter]} { @@ -1737,13 +1805,13 @@ namespace eval $dest {} } :copyNSVarsAndCmds $origin $dest - foreach i [::nsf::cmd::ObjectInfo::forward $origin] { - ::nsf::forward $dest -per-object $i {*}[::nsf::cmd::ObjectInfo::forward $origin -definition $i] + foreach i [::nsf::dispatch $origin ::nsf::cmd::ObjectInfo2::forward] { + ::nsf::forward $dest -per-object $i {*}[::nsf::dipatch $origin ::nsf::cmd::ObjectInfo2::forward -definition $i] } if {[::nsf::objectproperty $origin class]} { - foreach i [::nsf::cmd::ClassInfo::forward $origin] { - ::nsf::forward $dest $i {*}[::nsf::cmd::ClassInfo::forward $origin -definition $i] + foreach i [nsf::dispatch $origin ::nsf::cmd::ClassInfo2::forward] { + ::nsf::forward $dest $i {*}[::nsf::dipatch $origin ::nsf::cmd::ClassInfo2::forward -definition $i] } } set traces [list]