5
if {[namespace exists $class]} {
6
error "class $class already declared"
7
}
8
- namespace eval $class {
8
+ namespace eval $class "
9
variable __nextid 0
10
variable __sealed 0
11
variable __field_list {}
13
14
proc cb {name args} {
15
upvar this this
16
- set args [linsert $args 0 $name $this]
17
- return [uplevel [list namespace code $args]]
16
+ concat \[list ${class}::\$name \$this\] \$args
17
}
19
- }
18
+ "
19
namespace eval $class $body
20
}
21
50
set mbodyc {}
51
52
append mbodyc {set this } $class
54
- append mbodyc {::__o[incr } $class {::__nextid]} \;
55
- append mbodyc {namespace eval $this {}} \;
53
+ append mbodyc {::__o[incr } $class {::__nextid]::__d} \;
54
+ append mbodyc {create_this } $class \;
55
+ append mbodyc {set __this [namespace qualifiers $this]} \;
56
57
if {$__field_list ne {}} {
58
append mbodyc {upvar #0}
59
foreach n $__field_list {
60
set n [lindex $n 0]
61
- append mbodyc { ${this}::} $n { } $n
62
- regsub -all @$n\\M $body "\${this}::$n" body
61
+ append mbodyc { ${__this}::} $n { } $n
62
+ regsub -all @$n\\M $body "\${__this}::$n" body
63
}
64
append mbodyc \;
65
foreach n $__field_list {
80
set params [linsert $params 0 this]
81
set mbodyc {}
82
83
+ append mbodyc {set __this [namespace qualifiers $this]} \;
84
+
85
switch $deleted {
86
{} {}
87
ifdeleted {
86
- append mbodyc {if {![namespace exists $this]} }
88
+ append mbodyc {if {![namespace exists $__this]} }
89
append mbodyc \{ $del_body \; return \} \;
90
}
91
default {
100
if { [regexp -all -- $n\\M $body] == 1
101
&& [regexp -all -- \\\$$n\\M $body] == 1
102
&& [regexp -all -- \\\$$n\\( $body] == 0} {
101
- regsub -all \\\$$n\\M $body "\[set \${this}::$n\]" body
103
+ regsub -all \
104
+ \\\$$n\\M $body \
105
+ "\[set \${__this}::$n\]" body
106
} else {
103
- append decl { ${this}::} $n { } $n
104
- regsub -all @$n\\M $body "\${this}::$n" body
107
+ append decl { ${__this}::} $n { } $n
108
+ regsub -all @$n\\M $body "\${__this}::$n" body
109
}
110
}
111
}
116
namespace eval $class [list proc $name $params $mbodyc]
117
}
118
119
+proc create_this {class} {
120
+ upvar this this
121
+ namespace eval [namespace qualifiers $this] [list proc \
122
+ [namespace tail $this] \
123
+ [list name args] \
124
+ "eval \[list ${class}::\$name $this\] \$args" \
125
+ ]
126
+}
127
+
128
proc delete_this {{t {}}} {
129
if {$t eq {}} {
130
upvar this this
131
set t $this
132
}
133
+ set t [namespace qualifiers $t]
134
if {[namespace exists $t]} {namespace delete $t}
135
}
136