Index: library/lib/xotcl1.xotcl =================================================================== diff -u -r04747ba752ca2b7a4f30586348e39ab04f190da9 -rbf9bae94d157de9bbd4c398f6a3a9a4d93626025 --- library/lib/xotcl1.xotcl (.../xotcl1.xotcl) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) +++ library/lib/xotcl1.xotcl (.../xotcl1.xotcl) (revision bf9bae94d157de9bbd4c398f6a3a9a4d93626025) @@ -13,7 +13,9 @@ # provide the standard command set for ::xotcl::Object foreach cmd [info command ::xotcl::cmd::Object::*] { - ::xotcl::alias Object [namespace tail $cmd] $cmd + set cmdName [namespace tail $cmd] + if {$cmdName in [list "setter" "object-method"]} continue + ::xotcl::alias Object $cmdName $cmd } # provide some Tcl-commands as methods for ::xotcl::Object @@ -23,7 +25,9 @@ # provide the standard command set for ::xotcl::Class foreach cmd [info command ::xotcl::cmd::Class::*] { - ::xotcl::alias Class [namespace tail $cmd] $cmd + set cmdName [namespace tail $cmd] + if {$cmdName in [list "setter" "class-method"]} continue + ::xotcl::alias Class $cmdName $cmd } # protect some methods against redefinition @@ -32,26 +36,59 @@ ::xotcl::methodproperty Class dealloc static true ::xotcl::methodproperty Class create static true - Class method -public unknown {args} { + # define instproc and proc + ::xotcl::dispatch Class ::xotcl::cmd::Class::class-method instproc { + name arguments body precondition:optional postcondition:optional + } { + set conditions [list] + if {[info exists precondition]} {lappend conditions -precondition $precondition} + if {[info exists postcondition]} {lappend conditions -postcondition $postcondition} + ::xotcl::dispatch [self] ::xotcl::cmd::Class::class-method $name $arguments $body {*}$conditions + #puts stderr "[self] [self proc] $name defined" + } + + ::xotcl::dispatch Object ::xotcl::cmd::Class::class-method proc { + name arguments body precondition:optional postcondition:optional + } { + set conditions [list] + if {[info exists precondition]} {lappend conditions -precondition $precondition} + if {[info exists postcondition]} {lappend conditions -postcondition $postcondition} + ::xotcl::dispatch [self] ::xotcl::cmd::Object::object-method $name $arguments $body {*}$conditions + #puts stderr "[self] [self proc] $name defined" + } + + # define - like in xotcl - a minimal implementation of "method" + Object instproc method {name arguments body} { + .proc $name $arguments $body + } + Class instproc method {-per-object:switch name arguments body} { + if {${per-object}} { + .proc $name $arguments $body + } else { + .instproc $name $arguments $body + } + } + + Class instproc unknown {args} { #puts stderr "use '[self] create $args', not '[self] $args'" eval my create $args } - Object method -public unknown {m args} { + Object instproc unknown {m args} { if {![self isnext]} { error "[self]: unable to dispatch method '$m'" } } # "init" must exist on Object. per default it is empty. - Object method -public init args {} + Object instproc init args {} - Object method -public self {} {::xotcl::self} + Object instproc self {} {::xotcl::self} # # object-parameter definition, backwards compatible # - ::xotcl::Object method objectparameter {} { + ::xotcl::Object instproc objectparameter {} { set parameterdefinitions [::xotcl::parametersFromSlots [self]] lappend parameterdefinitions args #puts stderr "*** parameter definition for [self]: $parameterdefinitions" @@ -121,7 +158,7 @@ Object forward info -onerror ::xotcl::infoError ::xotcl::objectInfo %1 {%@2 %self} Class forward info -onerror ::xotcl::infoError ::xotcl::classInfo %1 {%@2 %self} - objectInfo method -public info {obj} { + objectInfo proc info {obj} { set methods [list] foreach m [::info commands ::xotcl::objectInfo::*] { set name [namespace tail $m] @@ -130,11 +167,11 @@ } return "valid options are: [join [lsort $methods] {, }]" } - objectInfo method unknown {method args} { + objectInfo proc unknown {method args} { error "[::xotcl::self] unknown info option \"$method\"; [.info info]" } - classInfo method -public info {cl} { + classInfo proc info {cl} { set methods [list] foreach m [::info commands ::xotcl::classInfo::*] { set name [namespace tail $m] @@ -143,7 +180,8 @@ } return "valid options are: [join [lsort $methods] {, }]" } - classInfo method unknown {method args} { + + classInfo proc unknown {method args} { error "[::xotcl::self] unknown info option \"$method\"; [.info info]" } @@ -237,55 +275,55 @@ error "procedure \"$method\" doesn't have an argument \"$varName\"" } classInfo eval { - .method -public instargs {o method} {::xotcl::info_args Class $o $method} - .method -public args {o method} {::xotcl::info_args Object $o $method} - .method -public instnonposargs {o method} {::xotcl::info_nonposargs Class $o $method} - .method -public nonposargs {o method} {::xotcl::info_nonposargs Object $o $method} - .method -public instdefault {o method arg var} {::xotcl::info_default Class $o $method $arg $var} - .method -public default {o method arg var} {::xotcl::info_default Object $o $method $arg $var} + .proc instargs {o method} {::xotcl::info_args Class $o $method} + .proc args {o method} {::xotcl::info_args Object $o $method} + .proc instnonposargs {o method} {::xotcl::info_nonposargs Class $o $method} + .proc nonposargs {o method} {::xotcl::info_nonposargs Object $o $method} + .proc instdefault {o method arg var} {::xotcl::info_default Class $o $method $arg $var} + .proc default {o method arg var} {::xotcl::info_default Object $o $method $arg $var} # info options emulated by "info method" - .method -public instbody {o methodName} { + .proc instbody {o methodName} { lindex [::xotcl::cmd::ClassInfo::method $o definition $methodName] end } - .method -public instpre {o methodName} {::xotcl::cmd::ClassInfo::method $o precondition $methodName} - .method -public instpost {o methodName} {::xotcl::cmd::ClassInfo::method $o postcondition $methodName} + .proc instpre {o methodName} {::xotcl::cmd::ClassInfo::method $o precondition $methodName} + .proc instpost {o methodName} {::xotcl::cmd::ClassInfo::method $o postcondition $methodName} # info options emulated by "info methods" - .method -public instcommands {o {pattern:optional ""}} { + .proc instcommands {o {pattern:optional ""}} { ::xotcl::cmd::ClassInfo::methods $o {*}$pattern } - .method -public instprocs {o {pattern:optional ""}} { + .proc instprocs {o {pattern:optional ""}} { ::xotcl::cmd::ClassInfo::methods $o -methodtype scripted {*}$pattern } - .method -public parametercmd {o {pattern:optional ""}} { + .proc parametercmd {o {pattern:optional ""}} { ::xotcl::cmd::ClassInfo::methods $o -per-object -methodtype setter {*}$pattern } - .method -public instparametercmd {o {pattern:optional ""}} { + .proc instparametercmd {o {pattern:optional ""}} { ::xotcl::cmd::ClassInfo::methods $o -methodtype setter {*}$pattern } } objectInfo eval { - .method -public args {o method} {::xotcl::info_args Object $o $method} - .method -public nonposargs {o method} {::xotcl::info_nonposargs Object $o $method} - .method -public default {o method arg var} {::xotcl::info_default Object $o $method $arg $var} + .proc args {o method} {::xotcl::info_args Object $o $method} + .proc nonposargs {o method} {::xotcl::info_nonposargs Object $o $method} + .proc default {o method arg var} {::xotcl::info_default Object $o $method $arg $var} # info options emulated by "info method" - .method -public body {o methodName} { + .proc body {o methodName} { lindex [::xotcl::cmd::ObjectInfo::method $o definition $methodName] end } - .method -public pre {o methodName} {::xotcl::cmd::ObjectInfo::method $o pre $methodName} - .method -public post {o methodName} {::xotcl::cmd::ObjectInfo::method $o post $methodName} + .proc pre {o methodName} {::xotcl::cmd::ObjectInfo::method $o pre $methodName} + .proc post {o methodName} {::xotcl::cmd::ObjectInfo::method $o post $methodName} # info options emulated by "info methods" - .method -public commands {o {pattern:optional ""}} { + .proc commands {o {pattern:optional ""}} { ::xotcl::cmd::ObjectInfo::methods $o {*}$pattern } - .method -public procs {o {pattern:optional ""}} { + .proc procs {o {pattern:optional ""}} { ::xotcl::cmd::ObjectInfo::methods $o -methodtype scripted {*}$pattern } - .method -public methods { + .proc methods { o -nocmds:switch -noprocs:switch -incontext:switch pattern:optional } { set methodtype all @@ -332,42 +370,23 @@ # emulation of isobject, isclass ... - Object method -public isobject {{object:substdefault "[self]"}} {::xotcl::is $object object} - Object method -public isclass {{class:substdefault "[self]"}} {::xotcl::is $class class} - Object method -public ismetaclass {{class:substdefault "[self]"}} {::xotcl::is $class metaclass} - Object method -public ismixin {class} {::xotcl::is [self] mixin $class} - Object method -public istype {class} {::xotcl::is [self] type $class} + Object instproc isobject {{object:substdefault "[self]"}} {::xotcl::is $object object} + Object instproc isclass {{class:substdefault "[self]"}} {::xotcl::is $class class} + Object instproc ismetaclass {{class:substdefault "[self]"}} {::xotcl::is $class metaclass} + Object instproc ismixin {class} {::xotcl::is [self] mixin $class} + Object instproc istype {class} {::xotcl::is [self] type $class} - ::xotcl::alias ::xotcl::Object contains ::xotcl::classes::xotcl2::Object::contains + ::xotcl::alias Object parametercmd ::xotcl::cmd::Object::setter + ::xotcl::alias Object contains ::xotcl::classes::xotcl2::Object::contains + ::xotcl::Class forward slots %self contains \ -object {%::xotcl::dispatch [::xotcl::self] -objscope ::subst [::xotcl::self]::slot} # - # define proc and instproc in terms of method # define forward and instforward in terms of forward # define parametercmd and instparametercmd in terms of setter # define parametercmd and instparametercmd in terms of setter # define mixinguard and instmixinguard in terms of mixinguard # - Object method -public proc {name arglist body precondition:optional postcondition:optional} { - set cmd [list my method -public $name $arglist $body] - if {[info exists precondition]} {lappend cmd -precondition $precondition} - if {[info exists postcondition]} {lappend cmd -postcondition $postcondition} - eval $cmd - } - ::xotcl::alias Object parametercmd ::xotcl::cmd::Object::setter - - Class method -public proc {name arglist body precondition:optional postcondition:optional} { - set cmd [list my method -public -per-object $name $arglist $body] - if {[info exists precondition]} {lappend cmd -precondition $precondition} - if {[info exists postcondition]} {lappend cmd -postcondition $postcondition} - eval $cmd - } - Class method -public instproc {name arglist body precondition:optional postcondition:optional} { - set cmd [list my method -public $name $arglist $body] - if {[info exists precondition]} {lappend cmd -precondition $precondition} - if {[info exists postcondition]} {lappend cmd -postcondition $postcondition} - eval $cmd - } ::xotcl::alias Class instparametercmd ::xotcl::cmd::Class::setter ::xotcl::alias Class parametercmd ::xotcl::cmd::Object::setter ::xotcl::alias Class filterguard ::xotcl::cmd::Object::filterguard @@ -382,7 +401,7 @@ ::xotcl::alias Class instforward ::xotcl::cmd::Class::forward ::xotcl::alias Class forward ::xotcl::cmd::Object::forward - Object method -public abstract {methtype methname arglist} { + Object instproc abstract {methtype methname arglist} { if {$methtype ne "proc" && $methtype ne "instproc" && $methtype ne "method"} { error "invalid method type '$methtype', \ must be either 'proc', 'instproc' or 'method'." @@ -395,11 +414,11 @@ } # support for XOTcl 1.* specific convenience routines - Object method -public hasclass cl { + Object instproc hasclass cl { if {[::xotcl::is [self] mixin $cl]} {return 1} ::xotcl::is [self] type $cl } - Object method -public procsearch {name} { + Object instproc procsearch {name} { set definition [::xotcl::cmd::ObjectInfo::callable [self] -which $name] if {$definition ne ""} { foreach {obj kind arg} $definition break @@ -416,15 +435,15 @@ return [list $obj $kind $name] } } - Class method -public allinstances {} { + Class instproc allinstances {} { # TODO: mark it deprecated return [.info instances -closure] } # keep old object interface for xotcl 1.* - Object method -public -per-object unsetExitHandler {} {::xotcl::unsetExitHandler $newbody} - Object method -public -per-object setExitHandler {newbody} {::xotcl::setExitHandler $newbody} - Object method -public -per-object getExitHandler {} {:xotcl::getExitHandler} + Object proc unsetExitHandler {} {::xotcl::unsetExitHandler $newbody} + Object proc setExitHandler {newbody} {::xotcl::setExitHandler $newbody} + Object proc getExitHandler {} {:xotcl::getExitHandler} # resue some definitions from ::xotcl2 ::xotcl::alias ::xotcl::Object copy ::xotcl::classes::xotcl2::Object::copy @@ -438,7 +457,7 @@ proc myvar {var} {.requireNamespace; return [::xotcl::self]::$var} Object create ::xotcl::config - config method -public load {obj file} { + config proc load {obj file} { source $file foreach i [array names ::auto_index [list $obj *proc *]] { set type [lindex $i 1] @@ -449,7 +468,7 @@ } } - config method -public mkindex {meta dir args} { + config proc mkindex {meta dir args} { set sp {[ ]+} set st {^[ ]*} set wd {([^ ;]+)} @@ -516,7 +535,7 @@ # # if cutTheArg not 0, it cut from upvar argsList # - Object method -public extractConfigureArg {al name {cutTheArg 0}} { + Object instproc extractConfigureArg {al name {cutTheArg 0}} { set value "" upvar $al argList set largs [llength $argList] @@ -538,10 +557,10 @@ } Object create ::xotcl::rcs - rcs method -public date string { + rcs proc date string { lreplace [lreplace $string 0 0] end end } - rcs method -public version string { + rcs proc version string { lindex $string 2 } @@ -550,7 +569,7 @@ # # puts this for the time being into xotcl 1.* # - ::xotcl::Class method -public uses list { + ::xotcl::Class instproc uses list { foreach package $list { ::xotcl::package import -into [::xotcl::self] $package puts stderr "*** using ${package}::* in [::xotcl::self]"