Index: generic/predefined.h =================================================================== diff -u -re45455a7ad52d4d849a0408243d175b4b4a52bb3 -r670151ba40e8da27625ed679f2d3ff58d1763239 --- generic/predefined.h (.../predefined.h) (revision e45455a7ad52d4d849a0408243d175b4b4a52bb3) +++ generic/predefined.h (.../predefined.h) (revision 670151ba40e8da27625ed679f2d3ff58d1763239) @@ -145,20 +145,45 @@ "namespace eval ::xotcl {\n" "::xotcl2::Class create ::xotcl::MetaSlot\n" "::xotcl::relation ::xotcl::MetaSlot superclass ::xotcl2::Class\n" +"::xotcl::MetaSlot public method slotName {name baseObject} {\n" +"set slotParent ${baseObject}::slot\n" +"if {![::xotcl::is ${slotParent} object]} {\n" +"::xotcl2::Object create ${slotParent}}\n" +"return ${slotParent}::$name}\n" +"::xotcl::MetaSlot method createFromParameterSyntax {target {-initblock \"\"} value default:optional} {\n" +"set opts [list]\n" +"set colonPos [string first : $value]\n" +"if {$colonPos == -1} {\n" +"set name $value} else {\n" +"set properties [string range $value [expr {$colonPos+1}] end]\n" +"set name [string range $value 0 [expr {$colonPos -1}]]\n" +"foreach property [split $properties ,] {\n" +"if {$property eq \"required\"} {\n" +"lappend opts -required 1} elseif {$property eq \"multivalued\"} {\n" +"lappend opts -multivalued 1} elseif {[string match type=* $property]} {\n" +"set type [string range $property 5 end]\n" +"if {![string match ::* $type]} {set type ::$type}} elseif {[string match arg=* $property]} {\n" +"set argument [string range $property 4 end]\n" +"lappend opts -arg $argument} else {\n" +"set type $property}}}\n" +"if {[info exists type]} {\n" +"lappend opts -type $type}\n" +"if {[info exists default]} {\n" +"lappend opts -default $default}\n" +":create [:slotName $name $target] {*}$opts $initblock}\n" "::xotcl::MetaSlot create ::xotcl::Slot\n" "::xotcl::MetaSlot create ::xotcl::ObjectParameterSlot\n" "::xotcl::relation ::xotcl::ObjectParameterSlot superclass ::xotcl::Slot\n" "::xotcl::MetaSlot create ::xotcl::MethodParameterSlot\n" "::xotcl::relation ::xotcl::MethodParameterSlot superclass ::xotcl::Slot\n" "::xotcl::MethodParameterSlot create ::xotcl::methodParameterSlot\n" "proc createBootstrapAttributeSlots {class definitions} {\n" -"if {![::xotcl::is ${class}::slot object]} {\n" -"::xotcl2::Object create ${class}::slot}\n" "foreach att $definitions {\n" "if {[llength $att]>1} {foreach {att default} $att break}\n" -"::xotcl::ObjectParameterSlot create ${class}::slot::$att\n" +"set slotObj [::xotcl::ObjectParameterSlot slotName $att $class]\n" +"::xotcl::ObjectParameterSlot create $slotObj\n" "if {[info exists default]} {\n" -"::xotcl::setinstvar ${class}::slot::$att default $default\n" +"::xotcl::setinstvar $slotObj default $default\n" "unset default}\n" "::xotcl::setter $class $att}\n" "foreach att $definitions {\n" @@ -344,27 +369,6 @@ "valuecmd\n" "valuechangedcmd\n" "arg}\n" -"::xotcl::Attribute object method createFromParameterSyntax {target value default:optional} {\n" -"set opts [list]\n" -"set colonPos [string first : $value]\n" -"if {$colonPos == -1} {\n" -"set name $value} else {\n" -"set properties [string range $value [expr {$colonPos+1}] end]\n" -"set name [string range $value 0 [expr {$colonPos -1}]]\n" -"foreach property [split $properties ,] {\n" -"if {$property eq \"required\"} {\n" -"lappend opts -required 1} elseif {$property eq \"multivalued\"} {\n" -"lappend opts -multivalued 1} elseif {[string match type=* $property]} {\n" -"set type [string range $property 5 end]\n" -"if {![string match ::* $type]} {set type ::$type}} elseif {[string match arg=* $property]} {\n" -"set argument [string range $property 4 end]\n" -"lappend opts -arg $argument} else {\n" -"set type $property}}}\n" -"if {[info exists type]} {\n" -"lappend opts -type $type}\n" -"if {[info exists default]} {\n" -"lappend opts -default $default}\n" -"::xotcl::Attribute create ${target}::slot::$name {*}$opts}\n" "::xotcl::Attribute method __default_from_cmd {obj cmd var sub op} {\n" "$obj trace remove variable $var $op [list [::xotcl::self] [::xotcl::self proc] $obj $cmd]\n" "::xotcl::setinstvar $obj $var [$obj eval $cmd]}\n" @@ -450,8 +454,6 @@ "::xotcl::setter ${:domain} {*}$perObject $setterParam}}\n" "::xotcl::Attribute mixin add ::xotcl::Attribute::Optimizer\n" "::xotcl2::Class public method parameter arglist {\n" -"if {![::xotcl::is [::xotcl::self]::slot object]} {\n" -"::xotcl2::Object create [::xotcl::self]::slot}\n" "foreach arg $arglist {\n" "::xotcl::Attribute createFromParameterSyntax [self] {*}$arg}\n" "::xotcl::setinstvar [::xotcl::self]::slot __parameter $arglist}\n" @@ -556,7 +558,7 @@ "if {[::xotcl::is $origin class]} {\n" "set dest [:getDest $origin]\n" "foreach oldslot [$origin info slots] {\n" -"set newslot ${dest}::slot::[namespace tail $oldslot]\n" +"set newslot [::xotcl::Slot slotName [namespace tail $oldslot] $dest]\n" "if {[$oldslot domain] eq $origin} {$newslot domain $cl}\n" "if {[$oldslot manager] eq $oldslot} {$newslot manager $newslot}}}}}\n" ":public method copy {obj dest} {\n" Index: generic/predefined.xotcl =================================================================== diff -u -re45455a7ad52d4d849a0408243d175b4b4a52bb3 -r670151ba40e8da27625ed679f2d3ff58d1763239 --- generic/predefined.xotcl (.../predefined.xotcl) (revision e45455a7ad52d4d849a0408243d175b4b4a52bb3) +++ generic/predefined.xotcl (.../predefined.xotcl) (revision 670151ba40e8da27625ed679f2d3ff58d1763239) @@ -298,6 +298,50 @@ # ::xotcl2::Class create ::xotcl::MetaSlot ::xotcl::relation ::xotcl::MetaSlot superclass ::xotcl2::Class + + ::xotcl::MetaSlot public method slotName {name baseObject} { + # Create slot parent object if needed + set slotParent ${baseObject}::slot + if {![::xotcl::is ${slotParent} object]} { + ::xotcl2::Object create ${slotParent} + } + return ${slotParent}::$name + } + + ::xotcl::MetaSlot method createFromParameterSyntax {target {-initblock ""} value default:optional} { + set opts [list] + set colonPos [string first : $value] + if {$colonPos == -1} { + set name $value + } else { + set properties [string range $value [expr {$colonPos+1}] end] + set name [string range $value 0 [expr {$colonPos -1}]] + foreach property [split $properties ,] { + if {$property eq "required"} { + lappend opts -required 1 + } elseif {$property eq "multivalued"} { + lappend opts -multivalued 1 + } elseif {[string match type=* $property]} { + set type [string range $property 5 end] + if {![string match ::* $type]} {set type ::$type} + } elseif {[string match arg=* $property]} { + set argument [string range $property 4 end] + lappend opts -arg $argument + } else { + set type $property + } + } + } + if {[info exists type]} { + lappend opts -type $type + } + + if {[info exists default]} { + lappend opts -default $default + } + + :create [:slotName $name $target] {*}$opts $initblock + } # ::xotcl::MetaSlot public method new args { # set slotobject [::xotcl::self callingobject]::slot @@ -321,14 +365,12 @@ # done via slot objects, which are defined later. proc createBootstrapAttributeSlots {class definitions} { - if {![::xotcl::is ${class}::slot object]} { - ::xotcl2::Object create ${class}::slot - } foreach att $definitions { if {[llength $att]>1} {foreach {att default} $att break} - ::xotcl::ObjectParameterSlot create ${class}::slot::$att + set slotObj [::xotcl::ObjectParameterSlot slotName $att $class] + ::xotcl::ObjectParameterSlot create $slotObj if {[info exists default]} { - ::xotcl::setinstvar ${class}::slot::$att default $default + ::xotcl::setinstvar $slotObj default $default unset default } ::xotcl::setter $class $att @@ -434,7 +476,6 @@ } ${:domain} __invalidateobjectparameter set cl [expr {${:per-object} ? "Object" : "Class"}] - # since the domain object might be xotcl1 or xotcl2, use dispatch ::xotcl::forward ${:domain} ${:name} \ ${:manager} \ [list %1 [${:manager} defaultmethods]] %self \ @@ -661,41 +702,6 @@ arg } - ::xotcl::Attribute object method createFromParameterSyntax {target value default:optional} { - set opts [list] - set colonPos [string first : $value] - if {$colonPos == -1} { - set name $value - } else { - set properties [string range $value [expr {$colonPos+1}] end] - set name [string range $value 0 [expr {$colonPos -1}]] - foreach property [split $properties ,] { - if {$property eq "required"} { - lappend opts -required 1 - } elseif {$property eq "multivalued"} { - lappend opts -multivalued 1 - } elseif {[string match type=* $property]} { - set type [string range $property 5 end] - if {![string match ::* $type]} {set type ::$type} - } elseif {[string match arg=* $property]} { - set argument [string range $property 4 end] - lappend opts -arg $argument - } else { - set type $property - } - } - } - if {[info exists type]} { - lappend opts -type $type - } - - if {[info exists default]} { - lappend opts -default $default - } - - ::xotcl::Attribute create ${target}::slot::$name {*}$opts - } - ::xotcl::Attribute method __default_from_cmd {obj cmd var sub op} { #puts "GETVAR [::xotcl::self proc] obj=$obj cmd=$cmd, var=$var, op=$op" $obj trace remove variable $var $op [list [::xotcl::self] [::xotcl::self proc] $obj $cmd] @@ -816,7 +822,7 @@ set infokind Class } if {[::xotcl::cmd::${infokind}Info::method ${:domain} name ${:name}] ne ""} { - #puts stderr "RESETTING ${:domain} name ${:name}" + #puts stderr "RESETTING ${:domain} slot ${:name}" ::xotcl::forward ${:domain} {*}$perObject ${:name} \ ${:manager} \ [list %1 [${:manager} defaultmethods]] %self \ @@ -830,7 +836,6 @@ if {$assignInfo ne "::xotcl::ObjectParameterSlot alias assign ::xotcl::setinstvar" && [lindex $assignInfo {end 0}] ne "::xotcl::setinstvar" } return if {[:info callable -which get] ne "::xotcl::ObjectParameterSlot alias get ::xotcl::setinstvar"} return - #puts stderr "**** optimizing [${:domain} info method definition ${:name}]" array set "" [:toParameterSyntax ${:name}] if {$(mparam) ne ""} { @@ -852,12 +857,7 @@ # compatibility and convenience ############################################ ::xotcl2::Class public method parameter arglist { - - # create subobject "slot" if necessary - if {![::xotcl::is [::xotcl::self]::slot object]} { - ::xotcl2::Object create [::xotcl::self]::slot - } - + foreach arg $arglist { ::xotcl::Attribute createFromParameterSyntax [self] {*}$arg } @@ -1061,7 +1061,7 @@ if {[::xotcl::is $origin class]} { set dest [:getDest $origin] foreach oldslot [$origin info slots] { - set newslot ${dest}::slot::[namespace tail $oldslot] + set newslot [::xotcl::Slot slotName [namespace tail $oldslot] $dest] if {[$oldslot domain] eq $origin} {$newslot domain $cl} if {[$oldslot manager] eq $oldslot} {$newslot manager $newslot} } Index: library/lib/test.xotcl =================================================================== diff -u -rc6066a15de738754028991b2b57b8f1d5a1cccaa -r670151ba40e8da27625ed679f2d3ff58d1763239 --- library/lib/test.xotcl (.../test.xotcl) (revision c6066a15de738754028991b2b57b8f1d5a1cccaa) +++ library/lib/test.xotcl (.../test.xotcl) (revision 670151ba40e8da27625ed679f2d3ff58d1763239) @@ -68,12 +68,12 @@ :public method call {msg cmd} { if {[:verbose]} {puts stderr "$msg: $cmd"} - #if {[catch {namespace eval ${:namespace} $cmd} result]} { + #if {[catch {::namespace eval ${:namespace} $cmd} result]} { #puts stderr ERROR=$result #} #puts stderr "$msg: $cmd => $result" #return $result - return [namespace eval ${:namespace} $cmd] + return [::namespace eval ${:namespace} $cmd] } :public method run args { @@ -93,7 +93,7 @@ if {$c > 1} { #set r0 [time ${:cmd} $c] #puts stderr "time {time ${:cmd} $c}" - set r1 [time {time {namespace eval ${:namespace} ${:cmd}} $c}] + set r1 [time {time {::namespace eval ${:namespace} ${:cmd}} $c}] #regexp {^(-?[0-9]+) +} $r0 _ mS0 regexp {^(-?[0-9]+) +} $r1 _ mS1 set ms [expr {$mS1*1.0/$c}] @@ -111,11 +111,11 @@ } } - namespace export Test + ::namespace export Test } proc ? {cmd expected {msg ""}} { - set namespace [uplevel {namespace current}] + set namespace [uplevel {::namespace current}] #puts stderr "eval in namespace $namespace" if {$msg ne ""} { set t [Test new -cmd $cmd -msg $msg -namespace $namespace] Index: tests/parameters.xotcl =================================================================== diff -u -r2cd9b650a6c6bb8a50473195278c7005e75188b0 -r670151ba40e8da27625ed679f2d3ff58d1763239 --- tests/parameters.xotcl (.../parameters.xotcl) (revision 2cd9b650a6c6bb8a50473195278c7005e75188b0) +++ tests/parameters.xotcl (.../parameters.xotcl) (revision 670151ba40e8da27625ed679f2d3ff58d1763239) @@ -1,10 +1,5 @@ package require XOTcl package require xotcl::test - -Test parameter count 10 - -catch {::xotcl::configure cacheinterface true} - ::xotcl::use xotcl2 #######################################################