Index: generic/predefined.h =================================================================== diff -u -rafa1cb8064311ef406ae50c499c026c8576393f8 -r0c8c36d48b1a146780b7ba8966196ad1b7075dda --- generic/predefined.h (.../predefined.h) (revision afa1cb8064311ef406ae50c499c026c8576393f8) +++ generic/predefined.h (.../predefined.h) (revision 0c8c36d48b1a146780b7ba8966196ad1b7075dda) @@ -437,6 +437,21 @@ "namespace eval $object $cmds}}\n" "::xotcl2::Class instforward slots %self contains \\\n" "-object {%::xotcl::dispatch [::xotcl::self] -objscope ::subst [::xotcl::self]::slot}\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::Class instforward slots %self contains \\\n" "-object {%::xotcl::dispatch [::xotcl::self] -objscope ::subst [::xotcl::self]::slot}\n" "::xotcl2::Class method parameter arglist {\n" @@ -499,7 +514,6 @@ "::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 contains ::xotcl::classes::xotcl2::Object::contains\n" "::xotcl::alias ::xotcl2::Object defaultmethod ::xotcl::classes::xotcl::Object::defaultmethod\n" "::xotcl::Object method -per-object unsetExitHandler {} {\n" "::xotcl::Object method -per-object __exitHandler {} {\n" Index: generic/predefined.xotcl =================================================================== diff -u -rafa1cb8064311ef406ae50c499c026c8576393f8 -r0c8c36d48b1a146780b7ba8966196ad1b7075dda --- generic/predefined.xotcl (.../predefined.xotcl) (revision afa1cb8064311ef406ae50c499c026c8576393f8) +++ generic/predefined.xotcl (.../predefined.xotcl) (revision 0c8c36d48b1a146780b7ba8966196ad1b7075dda) @@ -833,6 +833,27 @@ } ::xotcl2::Class instforward slots %self contains \ -object {%::xotcl::dispatch [::xotcl::self] -objscope ::subst [::xotcl::self]::slot} + +# this will go into the optional xotcl block +::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::Class instforward slots %self contains \ -object {%::xotcl::dispatch [::xotcl::self] -objscope ::subst [::xotcl::self]::slot} # @@ -933,7 +954,7 @@ # 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 contains ::xotcl::classes::xotcl2::Object::contains ::xotcl::alias ::xotcl2::Object defaultmethod ::xotcl::classes::xotcl::Object::defaultmethod #interp alias {} ::xotcl::classes::xotcl::Class::parameter {} ::xotcl::classes::xotcl2::Class::parameter Index: library/serialize/Serializer.xotcl =================================================================== diff -u -r5ec6a6f960964d861d68c052d8e2e7d68b711449 -r0c8c36d48b1a146780b7ba8966196ad1b7075dda --- library/serialize/Serializer.xotcl (.../Serializer.xotcl) (revision 5ec6a6f960964d861d68c052d8e2e7d68b711449) +++ library/serialize/Serializer.xotcl (.../Serializer.xotcl) (revision 0c8c36d48b1a146780b7ba8966196ad1b7075dda) @@ -198,7 +198,7 @@ } Serializer instproc Object-serialize o { my collect-var-traces $o - append cmd [list [$o info class] create [$o self]] + append cmd [list [$o info class] create [::xotcl::dispatch $o -objscope ::xotcl::self]] # slots needs to be initialized when optimized, since # parametercmds are not serialized #if {![$o istype ::xotcl::Slot]} {append cmd " -noinit"} @@ -220,10 +220,10 @@ set setcmd [list] if {![my exists ignoreVarsRE] || ![regexp [my set ignoreVarsRE] ${o}::$v]} { - if {[$o array exists $v]} { - lappend setcmd array set $v [$o array get $v] + if {[::xotcl::dispatch $o ::array exists $v]} { + lappend setcmd array set $v [::xotcl::dispatch $o ::array get .$v] } else { - lappend setcmd set $v [$o set $v] + lappend setcmd set $v [::xotcl::instvar $o $v] } incr nrVars append cmd \t [my pcmd $setcmd] " \\\n" @@ -280,7 +280,7 @@ return $arglist } Serializer instproc category c { - if {[$c istype ::xotcl::Class]} {return Class} {return Object} + if {[::xotcl::is $c type ::xotcl::Class]} {return Class} {return Object} } Serializer instproc allChildren o { set set $o @@ -312,8 +312,8 @@ } Serializer instproc topoSort {set all} { - if {[my array exists s]} {my array unset s} - if {[my array exists level]} {my array unset level} + if {[array exists .s]} {array unset .s} + if {[array exists .level]} {array unset .level} foreach c $set { if {!$all && [string match "::xotcl::*" $c] && @@ -323,7 +323,7 @@ } set stratum 0 while {1} { - set set [my array names s] + set set [array names .s] if {[llength $set] == 0} break incr stratum #my warn "$stratum set=$set" @@ -379,10 +379,11 @@ set post_cmds "" # register for introspection purposes "trace" under a different name ::xotcl::alias ::xotcl::Object __trace__ -objscope ::trace + ::xotcl::alias ::xotcl2::Object __trace__ -objscope ::trace my topoSort $list $all - #foreach i [lsort [my array names level]] {my warn "$i: [my set level($i)]"} + #foreach i [lsort [array names .level]] {my warn "$i: [my set level($i)]"} set result "" - foreach l [lsort -integer [my array names level]] { + foreach l [lsort -integer [array names .level]] { foreach i [my set level($l)] { #my warn "serialize $i" #append result "# Stratum $l\n" @@ -393,7 +394,8 @@ set namespace($e) 1 set namespace([namespace qualifiers $e]) 1 } - ::xotcl::Object instproc __trace__ {} {} + ::xotcl::Object method __trace__ {} {} + ::xotcl2::Object method __trace__ {} {} # Handling of variable traces: traces might require a # different topological sort, which is hard to handle. @@ -461,7 +463,7 @@ Serializer proc serializeExportedMethods {s} { set r "" - foreach k [my array names exportMethods] { + foreach k [array names .exportMethods] { foreach {o p m} [split $k ,] break #if {$o ne "::xotcl::Object" && $o ne "::xotcl::Class"} { #error "method export only for ::xotcl::Object and\ @@ -502,8 +504,8 @@ append r "::xotcl::configure softrecreate [::xotcl::configure softrecreate]" append r \n [my serializeExportedMethods $s] # export the objects and classes - #$s warn "export objects = [my array names exportObjects]" - #$s warn "export objects = [my array names exportMethods]" + #$s warn "export objects = [array names .exportObjects]" + #$s warn "export objects = [array names .exportMethods]" append r [$s serialize-objects [$s allInstances ::xotcl::Object] 0] foreach o [list ::xotcl::Object ::xotcl::Class] { foreach x {mixin instmixin invar instinvar} { Index: tests/mixinoftest.xotcl =================================================================== diff -u -r91e9b1a3b1c3e60a8538156b4aa37d5a664d5133 -r0c8c36d48b1a146780b7ba8966196ad1b7075dda --- tests/mixinoftest.xotcl (.../mixinoftest.xotcl) (revision 91e9b1a3b1c3e60a8538156b4aa37d5a664d5133) +++ tests/mixinoftest.xotcl (.../mixinoftest.xotcl) (revision 0c8c36d48b1a146780b7ba8966196ad1b7075dda) @@ -479,7 +479,6 @@ ? {b1 info precedence} "::B ::A ::xotcl::Object" foreach o {A O B a1 b1 o1} {$o destroy} - #foreach o [::xotcl::test::Test info instances] {$o destroy} #::xotcl::test::Test destroy #puts [lsort [::xotcl::Object allinstances]] Index: tests/slottest.xotcl =================================================================== diff -u -r5556c6d63ea6f4d90705386490253530f0272b57 -r0c8c36d48b1a146780b7ba8966196ad1b7075dda --- tests/slottest.xotcl (.../slottest.xotcl) (revision 5556c6d63ea6f4d90705386490253530f0272b57) +++ tests/slottest.xotcl (.../slottest.xotcl) (revision 0c8c36d48b1a146780b7ba8966196ad1b7075dda) @@ -46,9 +46,9 @@ # y {incr ::hu} # z {my trace add variable z read T1}} Class C -slots { - Attribute x -initcmd {set x 1} - Attribute y -initcmd {incr ::hu} - Attribute z -initcmd {my trace add variable z read T1} + Attribute create x -initcmd {set x 1} + Attribute create y -initcmd {incr ::hu} + Attribute create z -initcmd {my trace add variable z read T1} } C create c1 @@ -61,8 +61,8 @@ ? {set ::hu} 1 Class D -slots { - Attribute x -initcmd {set x 2} - Attribute z -initcmd {my trace add variable z read T2} + Attribute create x -initcmd {set x 2} + Attribute create z -initcmd {my trace add variable z read T2} } -superclass C D create c1 ? {c1 set x} 2 @@ -119,7 +119,7 @@ #t {O2 superclass O} "superclass 1" ? {O superclass} "::xotcl::Object" -::xotcl::Slot instproc slot {object name property} { +::xotcl::Slot method slot {object name property} { switch $property { self {return [self]} domain {return [my domain]} @@ -129,7 +129,6 @@ ? {O superclass slot self} "::xotcl::Class::slot::superclass" ? {O superclass slot domain} "::xotcl::Class" - ? {O2 superclass} "::O" O2 superclass add M ? {O2 superclass} "::M ::O" @@ -146,24 +145,24 @@ # application classes ###################### Class Person -slots { - Attribute name - Attribute age -default 0 + Attribute create name + Attribute create age -default 0 } Class Article -slots { - Attribute title - Attribute date + Attribute create title + Attribute create date } Class publishes -slots { - Role written_by -references Person -multivalued true - Role has_published -references Paper -multivalued true + Role create written_by -references Person -multivalued true + Role create has_published -references Paper -multivalued true } Class Project -slots { - Attribute name - Role manager -references Person - Role member -references Person -multivalued true + Attribute create name + Role create manager -references Person + Role create member -references Person -multivalued true } puts [Person serialize] @@ -274,9 +273,9 @@ Class C2 -slots { - Attribute a - Attribute b -default 10 - Attribute c -default "Hello World" + Attribute create a + Attribute create b -default 10 + Attribute create c -default "Hello World" } C2 c2 -a 1 ? {c2 procsearch a} "::C2 instforward a" @@ -290,9 +289,9 @@ ::xotcl::Slot instmixin add ::xotcl::Slot::Optimizer Class C3 -slots { - Attribute a - Attribute b -default 10 - Attribute c -default "Hello World" + Attribute create a + Attribute create b -default 10 + Attribute create c -default "Hello World" } C3 c3 -a 1 ? {c3 procsearch a} "::C3 instparametercmd a" @@ -313,7 +312,7 @@ Class create A -parameter {{foo 1}} # or Class create A -slots { - Attribute foo -default 1 + Attribute create foo -default 1 } A create a1 -foo 234 ;# calls default foo setter @@ -350,9 +349,9 @@ # Class Person -slots { - Attribute name - Attribute age -default 0 - Attribute projects -default {} -multivalued true + Attribute create name + Attribute create age -default 0 + Attribute create projects -default {} -multivalued true } Person p1 -name "Gustaf" @@ -361,8 +360,8 @@ ? {p1 projects} {} Class Project -slots { - Attribute name - Attribute description + Attribute create name + Attribute create description } Project project1 -name XOTcl -description "A highly flexible OO scripting language" @@ -372,7 +371,7 @@ #p1 projects add some-other-value #? {p1 projects} "some-other-value ::project1" -::xotcl::Slot instproc check { +::xotcl::Slot method check { {-keep_old_value:boolean true} value predicate type obj var } { @@ -388,16 +387,16 @@ if {$keep_old_value} {$obj set __oldvalue($var) $value} } -::xotcl::Slot instproc checkall {values predicate type obj var} { +::xotcl::Slot method checkall {values predicate type obj var} { foreach value $values { my check -keep_old_value false $value $predicate $type $obj $var } $obj set __oldvalue($var) $value } Person slots { - Attribute projects -default "" -multivalued true -type ::Project - Attribute salary -type integer + Attribute create projects -default "" -multivalued true -type ::Project + Attribute create salary -type integer } Person p2 -name "Gustaf" @@ -458,7 +457,7 @@ ##### Class create A -slots { - Attribute foo -default 1 -proc assign { domain var value} { + Attribute create foo -default 1 -proc assign { domain var value} { if {$value < 0 || $value > 99} { error "$value is not in the range of 0 .. 99" }