Index: generic/gentclAPI.decls =================================================================== diff -u -rf316e4ef5e27eedc5ed7cb1a4d90ff0d86b53ca8 -r663efcd5c70b2338bdfadf30e4ce125347362ec0 --- generic/gentclAPI.decls (.../gentclAPI.decls) (revision f316e4ef5e27eedc5ed7cb1a4d90ff0d86b53ca8) +++ generic/gentclAPI.decls (.../gentclAPI.decls) (revision 663efcd5c70b2338bdfadf30e4ce125347362ec0) @@ -49,7 +49,8 @@ {-argName "args" -type allargs} } xotclCmd instvar XOTclInstvarCmd { - {-argName "args" -type allargs} + {-argName "-object" -nrargs 1 -type object} + {-argName "args" -type args} } xotclCmd is XOTclIsCmd { {-argName "object" -required 1 -type tclobj} Index: generic/predefined.h =================================================================== diff -u -r6fa467e12f7a039c928b3096175a73414b5f26ff -r663efcd5c70b2338bdfadf30e4ce125347362ec0 --- generic/predefined.h (.../predefined.h) (revision 6fa467e12f7a039c928b3096175a73414b5f26ff) +++ generic/predefined.h (.../predefined.h) (revision 663efcd5c70b2338bdfadf30e4ce125347362ec0) @@ -1,6 +1,6 @@ static char cmd[] = -"#\n" -"set bootstrap 1\n" +"namespace eval ::xotcl {\n" +"set bootstrap 1}\n" "namespace eval xotcl2 {\n" "namespace path ::xotcl\n" "::xotcl::createobjectsystem ::xotcl2::Object ::xotcl2::Class\n" @@ -19,11 +19,8 @@ "if {![self isnext]} {\n" "error \"[self]: unable to dispatch method '$m'\"}}\n" "Object method init args {}\n" +"Object method defaultmethod {} {::xotcl::self}\n" "Object method objectparameter {} {;}\n" -"Class create ::xotcl2::ParameterType\n" -"foreach cmd [info command ::xotcl::cmd::ParameterType::*] {\n" -"::xotcl::alias ::xotcl2::ParameterType [namespace tail $cmd] $cmd}\n" -"::xotcl2::ParameterType create ::xotcl2::parameterType\n" "Object create ::xotcl2::objectInfo\n" "Object create ::xotcl2::classInfo\n" "foreach cmd [info command ::xotcl::cmd::ObjectInfo::*] {\n" @@ -61,6 +58,21 @@ "return \"valid options are: [join [lsort $methods] {, }]\"}\n" "classInfo method unknown {method args} {\n" "error \"[::xotcl::self] unknown info option \\\"$method\\\"; [.info info]\"}\n" +"Object method abstract {methtype -per-object:switch methname arglist} {\n" +"if {$methtype ne \"method\"} {\n" +"error \"invalid method type '$methtype', must be 'method'\"}\n" +"set body \"\n" +"if {!\\[::xotcl::self isnextcall\\]} {\n" +"error \\\"Abstract method $methname $arglist called\\\"} else {::xotcl::next}\n" +"\"\n" +"if {${per-object}} {\n" +".method -per-object $methname $arglist $body} else {\n" +".method $methname $arglist $body}}\n" +"proc ::xotcl::unsetExitHandler {} {\n" +"proc ::xotcl::__exitHandler {} {}}\n" +"proc ::xotcl::setExitHandler {newbody} {proc ::xotcl::__exitHandler {} $newbody}\n" +"proc ::xotcl::getExitHandler {} {::info body ::xotcl::__exitHandler}\n" +"::xotcl::unsetExitHandler\n" "namespace export Object Class}\n" "::xotcl2::Class create ::xotcl::MetaSlot\n" "::xotcl::relation ::xotcl::MetaSlot superclass ::xotcl2::Class\n" @@ -99,6 +111,10 @@ "lappend parameterdefinitions -parameter:method,optional}\n" "lappend parameterdefinitions -noinit:method,optional,noarg -volatile:method,optional,noarg arg:initcmd,optional\n" "return $parameterdefinitions}\n" +"::xotcl2::Class create ::xotcl2::ParameterType\n" +"foreach cmd [info command ::xotcl::cmd::ParameterType::*] {\n" +"::xotcl::alias ::xotcl2::ParameterType [namespace tail $cmd] $cmd}\n" +"::xotcl2::ParameterType create ::xotcl2::parameterType\n" "proc createBootstrapAttributeSlots {class definitions} {\n" "if {![::xotcl::is ${class}::slot object]} {\n" "::xotcl2::Object create ${class}::slot}\n" @@ -285,7 +301,7 @@ "inobject}\n" "::xotcl::ScopedNew method init {} {\n" ".method new {-childof args} {\n" -"[::xotcl::self class] instvar {inobject object} withclass\n" +"::xotcl::instvar -object [::xotcl::self class] {inobject object} withclass\n" "if {![::xotcl::is $object object]} {\n" "$withclass create $object}\n" "eval ::xotcl::next -childof $object $args}}\n" @@ -343,7 +359,7 @@ "::eval $po configure [lrange $arg 1 end]\n" "if {[$po exists extra] || [$po exists setter] ||\n" "[$po exists getter] || [$po exists access]} {\n" -"$po instvar extra setter getter access defaultParam\n" +"::xotcl::instvar -object $po extra setter getter access defaultParam\n" "if {![info exists extra]} {set extra \"\"}\n" "if {![info exists defaultParam]} {set defaultParam \"\"}\n" "if {![info exists setter]} {set setter set}\n" @@ -386,14 +402,14 @@ "set cl [[$origin info class] create $dest -noinit]\n" "set obj $cl\n" "$cl superclass [$origin info superclass]\n" -"$cl instinvar [$origin info instinvar]\n" +"$cl instinvar [$origin info instinvar]\n" "$cl instfilter [$origin info instfilter -guards]\n" -"$cl instmixin [$origin info instmixin]\n" +"$cl instmixin [$origin info instmixin]\n" ".copyNSVarsAndCmds ::xotcl::classes$origin ::xotcl::classes$dest} else {\n" "set obj [[$origin info class] create $dest -noinit]}\n" -"$obj invar [$origin info invar]\n" -"$obj check [$origin info check]\n" -"$obj mixin [$origin info mixin]\n" +"$obj invar [$origin info invar]\n" +"$obj check [$origin info check]\n" +"$obj mixin [$origin info mixin]\n" "$obj filter [$origin info filter -guards]\n" "if {[$origin info hasnamespace]} {\n" "$obj requireNamespace}} else {\n" @@ -425,6 +441,8 @@ "set .dest $dest\n" ".makeTargetList $obj\n" ".copyTargets}\n" +"::xotcl2::Object create ::xotcl::@ {\n" +".method unknown args {}}\n" "namespace eval ::xotcl {\n" "::xotcl::createobjectsystem ::xotcl::Object ::xotcl::Class\n" "foreach cmd [info command ::xotcl::cmd::Object::*] {\n" @@ -444,16 +462,16 @@ "if {![self isnext]} {\n" "error \"[self]: unable to dispatch method '$m'\"}}\n" "Object method init args {}\n" -"Object method objectparameter {} {;}\n" +"Object method self {} {::xotcl::self}\n" +"::xotcl::Object method objectparameter {} {\n" +"set parameterdefinitions [::xotcl::parametersFromSlots [self]]\n" +"lappend parameterdefinitions args\n" +"return $parameterdefinitions}\n" "Class create ::xotcl::ParameterType\n" "foreach cmd [info command ::xotcl::cmd::ParameterType::*] {\n" "::xotcl::alias ::xotcl::ParameterType [namespace tail $cmd] $cmd}\n" "::xotcl::alias ::xotcl::ParameterType type=switch ::xotcl::cmd::ParameterType::type=boolean\n" "::xotcl::ParameterType create ::xotcl::parameterType\n" -"::xotcl::Object method objectparameter {} {\n" -"set parameterdefinitions [::xotcl::parametersFromSlots [self]]\n" -"lappend parameterdefinitions args\n" -"return $parameterdefinitions}\n" "createBootstrapAttributeSlots ::xotcl::Class {\n" "{__default_superclass ::xotcl::Object}\n" "{__default_metaclass ::xotcl::Class}}\n" @@ -472,11 +490,6 @@ "::xotcl::alias ::xotcl::classInfo classchildren ::xotcl::cmd::ObjectInfo::children\n" "Object instforward info -onerror ::xotcl::infoError ::xotcl::objectInfo %1 {%@2 %self}\n" "Class instforward info -onerror ::xotcl::infoError ::xotcl::classInfo %1 {%@2 %self}\n" -"proc ::xotcl::infoError msg {\n" -"regsub -all \" \" $msg \"\" msg\n" -"regsub -all \" \" $msg \"\" msg\n" -"regsub {\\\"} $msg \"\\\"info \" msg\n" -"error $msg \"\"}\n" "objectInfo method info {obj} {\n" "set methods [list]\n" "foreach m [::info commands ::xotcl::objectInfo::*] {\n" @@ -537,21 +550,7 @@ "Object method ismetaclass {{class:substdefault \"[self]\"}} {::xotcl::is $class metaclass}\n" "Object method ismixin {class} {::xotcl::is [self] mixin $class}\n" "Object method istype {class} {::xotcl::is [self] type $class}\n" -"::xotcl::Object method contains {\n" -"{-withnew:boolean true}\n" -"-object\n" -"{-class ::xotcl2::Object}\n" -"cmds} {\n" -"if {![info exists object]} {set object [::xotcl::self]}\n" -"if {![::xotcl::is $object object]} {$class create $object}\n" -"$object requireNamespace\n" -"if {$withnew} {\n" -"set m [::xotcl::ScopedNew new \\\n" -"-inobject $object -withclass $class -volatile]\n" -"::xotcl2::Class instmixin add $m end\n" -"namespace eval $object $cmds\n" -"::xotcl2::Class instmixin delete $m} else {\n" -"namespace eval $object $cmds}}\n" +"::xotcl::alias ::xotcl::Object contains ::xotcl::classes::xotcl2::Object::contains\n" "::xotcl::Class instforward slots %self contains \\\n" "-object {%::xotcl::dispatch [::xotcl::self] -objscope ::subst [::xotcl::self]::slot}\n" "Object method proc {name arglist body precondition:optional postcondition:optional} {\n" @@ -569,39 +568,27 @@ "if {[info exists precondition]} {lappend cmd -precondition $precondition}\n" "if {[info exists postcondition]} {lappend cmd -postcondition $postcondition}\n" "eval $cmd}\n" -"Object create ::xotcl::@\n" -"@ method unknown args {}\n" -"proc myproc {args} {linsert $args 0 [::xotcl::self]}\n" -"proc myvar {var} {.requireNamespace; return [::xotcl::self]::$var}\n" -"namespace export Object Class @ myproc myvar Attribute}\n" -"::xotcl::Object method self {} {::xotcl::self}\n" -"::xotcl2::Object method defaultmethod {} {\n" -"return [::xotcl::self]}\n" -"::xotcl::Object method hasclass cl {\n" -"if {[::xotcl::is [self] mixin $cl]} {return 1}\n" -"::xotcl::is [self] type $cl}\n" -"::xotcl::Class method allinstances {} {\n" -"return [.info instances -closure]}\n" -"::xotcl::alias ::xotcl::Class parameter ::xotcl::classes::xotcl2::Class::parameter\n" -"::xotcl::alias ::xotcl::Object defaultmethod ::xotcl::classes::xotcl2::Object::defaultmethod\n" -"::xotcl::Object method -per-object unsetExitHandler {} {\n" -"::xotcl::Object method -per-object __exitHandler {} {\n" -";}}\n" -"::xotcl::Object unsetExitHandler\n" -"::xotcl::Object method -per-object setExitHandler {newbody} {\n" -"::xotcl::Object method -per-object __exitHandler {} $newbody}\n" -"::xotcl::Object method -per-object getExitHandler {} {\n" -"::xotcl::Object info body __exitHandler}\n" -"proc ::xotcl::__exitHandler {} {\n" -"::xotcl::Object __exitHandler}\n" -"::xotcl::Object method abstract {methtype methname arglist} {\n" +"Object method abstract {methtype methname arglist} {\n" "if {$methtype ne \"proc\" && $methtype ne \"instproc\" && $methtype ne \"method\"} {\n" "error \"invalid method type '$methtype', \\\n" "must be either 'proc', 'instproc' or 'method'.\"}\n" ".$methtype $methname $arglist \"\n" "if {!\\[::xotcl::self isnextcall\\]} {\n" "error \\\"Abstract method $methname $arglist called\\\"} else {::xotcl::next}\n" "\"}\n" +"Object method hasclass cl {\n" +"if {[::xotcl::is [self] mixin $cl]} {return 1}\n" +"::xotcl::is [self] type $cl}\n" +"Class method allinstances {} {\n" +"return [.info instances -closure]}\n" +"Object method -per-object unsetExitHandler {} {::xotcl::unsetExitHandler $newbody}\n" +"Object method -per-object setExitHandler {newbody} {::xotcl::setExitHandler $newbody}\n" +"Object method -per-object getExitHandler {} {:xotcl::getExitHandler}\n" +"::xotcl::alias ::xotcl::Class parameter ::xotcl::classes::xotcl2::Class::parameter\n" +"::xotcl::alias ::xotcl::Object defaultmethod ::xotcl::classes::xotcl2::Object::defaultmethod\n" +"proc myproc {args} {linsert $args 0 [::xotcl::self]}\n" +"proc myvar {var} {.requireNamespace; return [::xotcl::self]::$var}\n" +"namespace export Object Class @ myproc myvar Attribute}\n" "::xotcl::Object method copy newName {\n" "if {[string compare [string trimleft $newName :] [string trimleft [::xotcl::self] :]]} {\n" "[::xotcl::CopyHandler new -volatile] copy [::xotcl::self] $newName}}\n" @@ -767,7 +754,8 @@ "set .loaded($pkg) $v ;# loaded stuff needed for Tcl 8.0}}\n" "set .component $prevComponent\n" "return $v}\n" -"proc ::xotcl::tmpdir {} {\n" +"namespace eval ::xotcl {\n" +"proc tmpdir {} {\n" "foreach e [list TMPDIR TEMP TMP] {\n" "if {[info exists ::env($e)] \\\n" "&& [file isdirectory $::env($e)] \\\n" @@ -778,6 +766,6 @@ "if {[file isdirectory $d] && [file writable $d]} {\n" "return $d}}}\n" "return /tmp}\n" -"unset bootstrap\n" +"unset bootstrap}\n" ""; Index: generic/predefined.xotcl =================================================================== diff -u -r6fa467e12f7a039c928b3096175a73414b5f26ff -r663efcd5c70b2338bdfadf30e4ce125347362ec0 --- generic/predefined.xotcl (.../predefined.xotcl) (revision 6fa467e12f7a039c928b3096175a73414b5f26ff) +++ generic/predefined.xotcl (.../predefined.xotcl) (revision 663efcd5c70b2338bdfadf30e4ce125347362ec0) @@ -1,12 +1,15 @@ -# -# By setting the variable bootstrap, we can check later, whether we -# are in bootstrapping mode -# -set bootstrap 1 +namespace eval ::xotcl { + # + # By setting the variable bootstrap, we can check later, whether we + # are in bootstrapping mode + # + set bootstrap 1 +} # # First create the ::xotcl2 object system. # + namespace eval xotcl2 { namespace path ::xotcl ::xotcl::createobjectsystem ::xotcl2::Object ::xotcl2::Class @@ -45,20 +48,13 @@ # "init" must exist on Object. per default it is empty. Object method init args {} + # this method is called on calls to object without a specified method + Object method defaultmethod {} {::xotcl::self} + # provide a placeholder for the bootup process. The real definition # is based on slots, which are not available at this point. Object method objectparameter {} {;} - # - # create class and object for nonpositional argument processing - Class create ::xotcl2::ParameterType - foreach cmd [info command ::xotcl::cmd::ParameterType::*] { - ::xotcl::alias ::xotcl2::ParameterType [namespace tail $cmd] $cmd - } - - # create an object for dispatching - ::xotcl2::ParameterType create ::xotcl2::parameterType - ######################## # Info definition ######################## @@ -115,9 +111,38 @@ error "[::xotcl::self] unknown info option \"$method\"; [.info info]" } + + Object method abstract {methtype -per-object:switch methname arglist} { + if {$methtype ne "method"} { + error "invalid method type '$methtype', must be 'method'" + } + set body " + if {!\[::xotcl::self isnextcall\]} { + error \"Abstract method $methname $arglist called\" + } else {::xotcl::next} + " + if {${per-object}} { + .method -per-object $methname $arglist $body + } else { + .method $methname $arglist $body + } + } + + # exit handlers + proc ::xotcl::unsetExitHandler {} { + proc ::xotcl::__exitHandler {} { + # clients should append exit handlers to this proc body + } + } + proc ::xotcl::setExitHandler {newbody} {proc ::xotcl::__exitHandler {} $newbody} + proc ::xotcl::getExitHandler {} {::info body ::xotcl::__exitHandler} + # initialize exit handler + ::xotcl::unsetExitHandler + namespace export Object Class } + ################## # Slot definitions ################## @@ -194,7 +219,17 @@ return $parameterdefinitions } +# +# create class and object for nonpositional argument processing +::xotcl2::Class create ::xotcl2::ParameterType +foreach cmd [info command ::xotcl::cmd::ParameterType::*] { + ::xotcl::alias ::xotcl2::ParameterType [namespace tail $cmd] $cmd +} +# create an object for dispatching +::xotcl2::ParameterType create ::xotcl2::parameterType + + # use low level interface for defining slot values. Normally, this is # done via slot objects, which are defined later. @@ -522,7 +557,7 @@ ::xotcl::ScopedNew method init {} { .method new {-childof args} { - [::xotcl::self class] instvar {inobject object} withclass + ::xotcl::instvar -object [::xotcl::self class] {inobject object} withclass if {![::xotcl::is $object object]} { $withclass create $object } @@ -611,7 +646,7 @@ if {[$po exists extra] || [$po exists setter] || [$po exists getter] || [$po exists access]} { - $po instvar extra setter getter access defaultParam + ::xotcl::instvar -object $po extra setter getter access defaultParam if {![info exists extra]} {set extra ""} if {![info exists defaultParam]} {set defaultParam ""} if {![info exists setter]} {set setter set} @@ -694,18 +729,18 @@ # class object set obj $cl $cl superclass [$origin info superclass] - $cl instinvar [$origin info instinvar] + $cl instinvar [$origin info instinvar] $cl instfilter [$origin info instfilter -guards] - $cl instmixin [$origin info instmixin] + $cl instmixin [$origin info instmixin] .copyNSVarsAndCmds ::xotcl::classes$origin ::xotcl::classes$dest } else { # create obj set obj [[$origin info class] create $dest -noinit] } # copy object -> may be a class obj - $obj invar [$origin info invar] - $obj check [$origin info check] - $obj mixin [$origin info mixin] + $obj invar [$origin info invar] + $obj check [$origin info check] + $obj mixin [$origin info mixin] $obj filter [$origin info filter -guards] if {[$origin info hasnamespace]} { $obj requireNamespace @@ -759,9 +794,23 @@ .copyTargets } +####################################################### +# some utilities +####################################################### +# documentation stub object -> just ignore per default. +# if xoDoc is loaded, documentation will be activated +::xotcl2::Object create ::xotcl::@ { + .method unknown args {} +} -####################################################################### + + + + +####################################################### +# Classical ::xotcl 1.* +####################################################### namespace eval ::xotcl { # # Perform the basic setup of XOTcl 1.x. First, let us allocate the @@ -807,11 +856,19 @@ # "init" must exist on Object. per default it is empty. Object method init args {} - # provide a placeholder for the bootup process. The real definition - # is based on slots, which are not available at this point. - Object method objectparameter {} {;} + Object method self {} {::xotcl::self} # + # object-parameter definition, backwards compatible + # + ::xotcl::Object method objectparameter {} { + set parameterdefinitions [::xotcl::parametersFromSlots [self]] + lappend parameterdefinitions args + #puts stderr "*** parameter definition for [self]: $parameterdefinitions" + return $parameterdefinitions + } + + # # create class and object for nonpositional argument processing Class create ::xotcl::ParameterType foreach cmd [info command ::xotcl::cmd::ParameterType::*] { @@ -823,16 +880,6 @@ ::xotcl::ParameterType create ::xotcl::parameterType # - # object-parameter definition, backwards compatible - # - ::xotcl::Object method objectparameter {} { - set parameterdefinitions [::xotcl::parametersFromSlots [self]] - lappend parameterdefinitions args - #puts stderr "*** parameter definition for [self]: $parameterdefinitions" - return $parameterdefinitions - } - - # # TODO: # - are createBootstrapAttributeSlots for ::xotcl::Class still needed? # - Defaults for objectparameter seem more natural. @@ -869,17 +916,10 @@ ::xotcl::alias ::xotcl::classInfo classparent ::xotcl::cmd::ObjectInfo::parent ::xotcl::alias ::xotcl::classInfo classchildren ::xotcl::cmd::ObjectInfo::children + # note, we are using ::xotcl::infoError defined earlier Object instforward info -onerror ::xotcl::infoError ::xotcl::objectInfo %1 {%@2 %self} Class instforward info -onerror ::xotcl::infoError ::xotcl::classInfo %1 {%@2 %self} - # TODO: the following method is defined redundantly - proc ::xotcl::infoError msg { - #puts stderr "INFO ERROR: <$msg>\n$::errorInfo" - regsub -all " " $msg "" msg - regsub -all " " $msg "" msg - regsub {\"} $msg "\"info " msg - error $msg "" - } objectInfo method info {obj} { set methods [list] foreach m [::info commands ::xotcl::objectInfo::*] { @@ -1008,31 +1048,12 @@ Object method ismixin {class} {::xotcl::is [self] mixin $class} Object method istype {class} {::xotcl::is [self] type $class} - - # todo: it should be possible to use an alias for the xotcl2 implementation - ::xotcl::Object method contains { - {-withnew:boolean true} - -object - {-class ::xotcl2::Object} - cmds - } { - if {![info exists object]} {set object [::xotcl::self]} - if {![::xotcl::is $object object]} {$class create $object} - $object requireNamespace - if {$withnew} { - set m [::xotcl::ScopedNew new \ - -inobject $object -withclass $class -volatile] - ::xotcl2::Class instmixin add $m end - namespace eval $object $cmds - ::xotcl2::Class instmixin delete $m - } else { - namespace eval $object $cmds - } - } + ::xotcl::alias ::xotcl::Object contains ::xotcl::classes::xotcl2::Object::contains ::xotcl::Class instforward slots %self contains \ -object {%::xotcl::dispatch [::xotcl::self] -objscope ::subst [::xotcl::self]::slot} - # + # define proc and instproc in terms of method + # Object method proc {name arglist body precondition:optional postcondition:optional} { set cmd [list my method $name $arglist $body] if {[info exists precondition]} {lappend cmd -precondition $precondition} @@ -1051,12 +1072,37 @@ if {[info exists postcondition]} {lappend cmd -postcondition $postcondition} eval $cmd } + Object method 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'." + } + .$methtype $methname $arglist " + if {!\[::xotcl::self isnextcall\]} { + error \"Abstract method $methname $arglist called\" + } else {::xotcl::next} + " + } - # documentation stub object -> just ignore per default. - # if xoDoc is loaded, documentation will be activated - Object create ::xotcl::@ - @ method unknown args {} + # support for XOTcl 1.* specific convenience routines + Object method hasclass cl { + if {[::xotcl::is [self] mixin $cl]} {return 1} + ::xotcl::is [self] type $cl + } + Class method allinstances {} { + # TODO: mark it deprecated + return [.info instances -closure] + } + # keep old object interface for xotcl 1.* + Object method -per-object unsetExitHandler {} {::xotcl::unsetExitHandler $newbody} + Object method -per-object setExitHandler {newbody} {::xotcl::setExitHandler $newbody} + Object method -per-object getExitHandler {} {:xotcl::getExitHandler} + + # resue some definitions from ::xotcl2 + ::xotcl::alias ::xotcl::Class parameter ::xotcl::classes::xotcl2::Class::parameter + ::xotcl::alias ::xotcl::Object defaultmethod ::xotcl::classes::xotcl2::Object::defaultmethod + proc myproc {args} {linsert $args 0 [::xotcl::self]} proc myvar {var} {.requireNamespace; return [::xotcl::self]::$var} @@ -1065,70 +1111,14 @@ ####################################################################### - # # utilities # -::xotcl::Object method self {} {::xotcl::self} -::xotcl2::Object method defaultmethod {} { - return [::xotcl::self] -} -# support for XOTcl specific convenience routines -::xotcl::Object method hasclass cl { - if {[::xotcl::is [self] mixin $cl]} {return 1} - ::xotcl::is [self] type $cl -} -::xotcl::Class method allinstances {} { - # TODO: mark it deprecated - return [.info instances -closure] -} - -# reuse definitions from xotcl in xotcl2 -# TODO: can this be done with interp aliases? -::xotcl::alias ::xotcl::Class parameter ::xotcl::classes::xotcl2::Class::parameter -#::xotcl::alias ::xotcl::Object contains ::xotcl::classes::xotcl2::Object::contains -::xotcl::alias ::xotcl::Object defaultmethod ::xotcl::classes::xotcl2::Object::defaultmethod - -#interp alias {} ::xotcl::classes::xotcl::Class::parameter {} ::xotcl::classes::xotcl2::Class::parameter -#interp alias {} ::xotcl::classes::xotcl::Object::defaultmethod {} ::xotcl::classes::xotcl2::Object::defaultmethod - # # TODO remainder should move from ::xotcl::Object -> xotcl2::* # -# Exit Handler -::xotcl::Object method -per-object unsetExitHandler {} { - ::xotcl::Object method -per-object __exitHandler {} { - # clients should append exit handlers to this proc body - ; - } -} -# pre-defined as empty method -::xotcl::Object unsetExitHandler -::xotcl::Object method -per-object setExitHandler {newbody} { - ::xotcl::Object method -per-object __exitHandler {} $newbody -} -::xotcl::Object method -per-object getExitHandler {} { - ::xotcl::Object info body __exitHandler -} -# provide a global handler to avoid a proc on the global object. -proc ::xotcl::__exitHandler {} { - ::xotcl::Object __exitHandler -} -::xotcl::Object method 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'." - } - .$methtype $methname $arglist " - if {!\[::xotcl::self isnextcall\]} { - error \"Abstract method $methname $arglist called\" - } else {::xotcl::next} - " -} - - ::xotcl::Object method copy newName { if {[string compare [string trimleft $newName :] [string trimleft [::xotcl::self] :]]} { [::xotcl::CopyHandler new -volatile] copy [::xotcl::self] $newName @@ -1378,23 +1368,25 @@ return $v } -# return temp directory -proc ::xotcl::tmpdir {} { - foreach e [list TMPDIR TEMP TMP] { - if {[info exists ::env($e)] \ - && [file isdirectory $::env($e)] \ - && [file writable $::env($e)]} { - return $::env($e) +namespace eval ::xotcl { + # return platform aware temp directory + proc tmpdir {} { + foreach e [list TMPDIR TEMP TMP] { + if {[info exists ::env($e)] \ + && [file isdirectory $::env($e)] \ + && [file writable $::env($e)]} { + return $::env($e) + } } - } - if {$::tcl_platform(platform) eq "windows"} { - foreach d [list "C:\\TEMP" "C:\\TMP" "\\TEMP" "\\TMP"] { - if {[file isdirectory $d] && [file writable $d]} { - return $d + if {$::tcl_platform(platform) eq "windows"} { + foreach d [list "C:\\TEMP" "C:\\TMP" "\\TEMP" "\\TMP"] { + if {[file isdirectory $d] && [file writable $d]} { + return $d + } } } + return /tmp } - return /tmp -} -unset bootstrap + unset bootstrap +} Index: generic/tclAPI.h =================================================================== diff -u -rf316e4ef5e27eedc5ed7cb1a4d90ff0d86b53ca8 -r663efcd5c70b2338bdfadf30e4ce125347362ec0 --- generic/tclAPI.h (.../tclAPI.h) (revision f316e4ef5e27eedc5ed7cb1a4d90ff0d86b53ca8) +++ generic/tclAPI.h (.../tclAPI.h) (revision 663efcd5c70b2338bdfadf30e4ce125347362ec0) @@ -256,7 +256,7 @@ static int XOTclDotCmd(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); static int XOTclFinalizeObjCmd(Tcl_Interp *interp); static int XOTclGetSelfObjCmd(Tcl_Interp *interp, int selfoption); -static int XOTclInstvarCmd(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); +static int XOTclInstvarCmd(Tcl_Interp *interp, XOTclObject *withObject, int nobjc, Tcl_Obj *CONST nobjv[]); static int XOTclInterpObjCmd(Tcl_Interp *interp, char *name, int objc, Tcl_Obj *CONST objv[]); static int XOTclIsCmd(Tcl_Interp *interp, Tcl_Obj *object, int objectkind, Tcl_Obj *value); static int XOTclMethodPropertyCmd(Tcl_Interp *interp, XOTclObject *object, char *methodName, int withPer_object, int methodproperty, Tcl_Obj *value); @@ -2112,11 +2112,20 @@ static int XOTclInstvarCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { + parseContext pc; - + if (ArgumentParse(interp, objc, objv, NULL, objv[0], + method_definitions[XOTclInstvarCmdIdx].paramDefs, + method_definitions[XOTclInstvarCmdIdx].nrParameters, + &pc) != TCL_OK) { + return TCL_ERROR; + } else { + XOTclObject *withObject = (XOTclObject *)pc.clientData[0]; - return XOTclInstvarCmd(interp, objc, objv); + parseContextRelease(&pc); + return XOTclInstvarCmd(interp, withObject, objc-pc.lastobjc, objv+pc.lastobjc); + } } static int @@ -2666,7 +2675,8 @@ {"::xotcl::self", XOTclGetSelfObjCmdStub, 1, { {"proc|class|activelevel|args|activemixin|calledproc|calledmethod|calledclass|callingproc|callingclass|callinglevel|callingobject|filterreg|isnextcall|next", 0, 0, convertToSelfoption}} }, -{"::xotcl::instvar", XOTclInstvarCmdStub, 1, { +{"::xotcl::instvar", XOTclInstvarCmdStub, 2, { + {"-object", 0, 1, convertToObject}, {"args", 0, 0, convertToNothing}} }, {"::xotcl::interp", XOTclInterpObjCmdStub, 2, { Index: generic/xotcl.c =================================================================== diff -u -r3bc1c47ab8d6e5b70c724522656be5f0a9932c78 -r663efcd5c70b2338bdfadf30e4ce125347362ec0 --- generic/xotcl.c (.../xotcl.c) (revision 3bc1c47ab8d6e5b70c724522656be5f0a9932c78) +++ generic/xotcl.c (.../xotcl.c) (revision 663efcd5c70b2338bdfadf30e4ce125347362ec0) @@ -9980,11 +9980,11 @@ static int GetInstvarsIntoCurrentScope(Tcl_Interp *interp, XOTclObject *obj, int objc, Tcl_Obj *CONST objv[]); static int -XOTclInstvarCmd(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - XOTclObject *obj = GetSelfObj(interp); - if (!obj) +XOTclInstvarCmd(Tcl_Interp *interp, XOTclObject *object, int objc, Tcl_Obj *CONST objv[]) { + if (object == NULL) object = GetSelfObj(interp); + if (!object) return XOTclVarErrMsg(interp, "instvar: no current object", (char *) NULL); - return GetInstvarsIntoCurrentScope(interp, obj, objc, objv); + return GetInstvarsIntoCurrentScope(interp, object, objc, objv); } /* create a slave interp that calls XOTcl Init */ Index: tests/speedtest.xotcl =================================================================== diff -u -rc11ab22190bdfe6231b454e9969b6ffafb547f9c -r663efcd5c70b2338bdfadf30e4ce125347362ec0 --- tests/speedtest.xotcl (.../speedtest.xotcl) (revision c11ab22190bdfe6231b454e9969b6ffafb547f9c) +++ tests/speedtest.xotcl (.../speedtest.xotcl) (revision 663efcd5c70b2338bdfadf30e4ce125347362ec0) @@ -15,7 +15,7 @@ set ocount 1014 set ocount [expr {$ccount + 206}] set ocount [expr {$ccount + 15}] -set ocount [expr {$ccount + 7}] +set ocount [expr {$ccount + 6}] set startObjects [Object info instances] set x [llength [Object info instances]]