chiark / gitweb /
16cc78de2162dc71227058bd19704445d3ad95bd
[chiark-tcl.git] / base / tcmdifgen
1 #!/usr/bin/perl
2
3 # code generator to help with writing Tcl extensions
4 # Copyright 2006 Ian Jackson
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21
22 # Input format is line-based, ws-significant, offside rule (some kind
23 #  of, anyway).
24 #
25 #  Type TYPE:       C-TYPE-DECLARATOR
26 #     Defines TYPE as a type (for arguments and return values)
27 #     which corresponds to the C type specified.  C-TYPE-DECLARATOR
28 #     must contain one `@' where the identifier would go.
29 #     The type may contain allocated memory, etc., in which case
30 #     `Init' and `Fini' must be used.
31 #
32 #     TYPE may be either TYPENAME or TYPENAME(ARGS) - in this case,
33 #     ARGS should be C argument declarations as for in a function
34 #     prototype, of extra arguments for the application-supplied
35 #     parser/returner functions.  Each time a TYPE is used elsewhere,
36 #     the ARGS should be the actual arguments to pass, and will be
37 #     textually copied into the calls to the parser/returner
38 #     functions.
39 #
40 #     `Type' causes declarations in the .h file of these functions:
41 #        int cht_pat_TYPENAME(Tcl_Interp*, Tcl_Obj *obj, C-TYPE *val, ARGS);
42 #        Tcl_Obj *cht_ret_TYPENAME(Tcl_Interp*, C-TYPE val, ARGS);
43 #
44 #     cht_pat_... must attempt to parse obj into the appropriate type.
45 #     val will already have been initialised with `Init' statements if
46 #     relevant.  Whether cht_pat_... fails or succeeds it may allocate
47 #     memory into the object and must leave the object valid (for
48 #     `Fini').
49 #
50 #     cht_ret_... must convert the value back to a new Tcl_Obj.  It may
51 #     not fail.
52 #
53 #  Init TYPENAME    C-STATEMENTS
54 #     Provides some statements which are used to initialise a variable
55 #     of type TYPENAME.  C-STATEMENTS should contain one or more `@',
56 #     which will be replaced by the actual variable name.  The
57 #     variable will have been declared with the C declarator specified
58 #     with `Type'.  C-STATEMENTS may not fail or longjmp, and they may
59 #     not allocate memory or other resources.  If no `Init' is
60 #     supplied then there is no invariant (so no `Fini' may be
61 #     supplied either, and the type is `flat' - no memory, external
62 #     refs, etc.)
63 #
64 #  Fini TYPENAME    C-STATEMENTS
65 #     Provides some statements (like `Init') which are used to free a
66 #     variable of type TYPENAME.  The variable will already have been
67 #     initialised with the `Init' statements, and may have been
68 #     modified since by application per-type or per-command code.  Its
69 #     invariant will be satisfied before C-STATEMENTS.  Afterwards the
70 #     invariant may or may not be satisfied, but it may not have any
71 #     memory or other resources allocated.  C-STATEMENTS may not fail
72 #     or longjmp.
73 #
74 #  H-Include    C-INCLUDE-SPECIFIER
75 #     Arranges for generated .h files to #include the specified
76 #     file.  C-INCLUDE-SPECIFIER should include the <..> or "..".
77 #
78 #  Table [*]TABLENAME C-ENTRY-TYPE
79 #     Starts a table of commands or subcommands.  The generated .h
80 #     will contain a definition of C-ENTRY-TYPE containing
81 #         const char *name;
82 #         Tcl_ObjCmdProc *func;
83 #     and the generated .c will contain
84 #         const C-ENTRY-TYPE C-ARRAY-NAME[];
85 #     where C-ARRAY-NAME is TABLENAME, with `_entries' appended
86 #     and `cht_' prepended.  The entries are indented one level (one
87 #     or more spaces) and look like this:
88 #        ENTRYNAME [ C-EXTRA-ENTRY-VALUES ]
89 #            FORMALARGNAME   TYPE
90 #            ...
91 #          [ =>  RESULT-TYPE ]
92 #     This will cause the declaration of
93 #        int cht_do_TABLENAME_ENTRYNAME(ClientData cd, Tcl_Interp *ip,
94 #                                   FORMAL-ARGUMENTS, RESULT-C-TYPE*);
95 #     which is the procedure which the application must supply to
96 #     implement the function.  If the `=> RESULT-TYPE' is omitted, so
97 #     is the result argument to the function.  Each argument to the
98 #     function is of the C type corresponding to the specified type.
99 #     TYPE may be `...', in which case the C function will be passed
100 #     two args (int objc, Tcl_Obj *const *objv) for the remaining
101 #     arguments.
102 #
103 #     The cht_do_... function should not eat any memory associated with
104 #     the arguments.  The result buffer (if any) will be initialised
105 #     using the `Init' and should on success contain the relevant
106 #     result.  On failure it should leave the result unmodified (or at
107 #     least, not in need of freeing).
108 #
109 #     As an alternative, the arguments can be replaced with just
110 #            dispatch(TYPE-ARGS-FOR-ENUM)
111 #     which is a shorthand for
112 #            subcmd   enum(TYPE-ARGS-FOR-ENUM)
113 #            args     ...
114 #     and also generates and uses a standard dispatch function.
115 #
116 #     There will be an entry in C-ARRAY-NAME for every table entry.
117 #     The name will be ENTRYNAME, and the func will be a function
118 #     suitable for use as a Tcl command procedure, which parses the
119 #     arguments, processes the command, and sets any result, as
120 #     applicable.
121 #
122 #     `*' should be used if the table name is not useful for error
123 #     messages.  It suppresses `TABLENAME ' from the front of the
124 #     autogenerated argument parsing error strings.
125 #
126 #  EntryExtra C-ENTRY-TYPE
127 #     Introduces a section of additional C code which will be inserted
128 #     into the definition of C-ENTRY-TYPE by `Table'.  The C
129 #     code, which follows on several indented lines, should be
130 #     structure member definitions.
131 #
132 #     When EntryExtra is used, in the corresponding Table, each
133 #     ENTRYNAME should be followed on the same line by whitespace and
134 #     EXTRA-VALUES; the EXTRA-VALUES are used as initialisers for the
135 #     additional structure elements.
136 #
137 #  NoEntryDefine C-ENTRY-TYPE
138 #     Prevents the definition of C-ENTRY-TYPE by Table.
139 #     The C type must be defined elsewhere.
140 #
141 #  Also expected are these functions:
142 #    void cht_setstringresult(Tcl_Interp*, const char*);
143 #        sets the Tcl result from the supplied string
144 #    int cht_pat_enum(Tcl_Interp*, Tcl_Obj*, const void **c_e_t_array,
145 #                 const void *c_e_t_return, size_t c_e_t_sz, const char *what);
146 #        scans a table of C-ENTRY-TYPEs looking for the
147 #        string matching the string supplied by the script
148 #        (as a Tcl_Obj).  On error sets the result, using
149 #        what (a noun phrase describing the type of thing).
150 #        Assumes (unportably!) that the name and func members
151 #        are in the same places no matter what the rest of
152 #        the struct contains.
153 #  and the two predefined types `int' (C `int') and `obj' (Tcl_Obj*,
154 #  unmodified.)  The corresponding definitions are in tcmdiflib.c.
155
156 use IO;
157 use Data::Dumper;
158
159 parse('builtins','DATA');
160
161 while (@ARGV) {
162     $_= shift @ARGV;
163     if (m/^\-p([-_0-9a-z]+)$/) {
164         $prefix= $1;
165         $prefix =~ y/-/_/;
166     } elsif (m/^\-w(c|h)$/) {
167         $write= $1;
168     } elsif (m/^\-o(.+)$/) {
169         $output= $1;
170     } elsif (m/^\-/) {
171         die "unknown option $_\n";
172     } else {
173         if (!defined $prefix) { $prefix= $_;  $prefix =~ s/\.[^.]+$//; }
174         $x= new IO::File $_,'r' or die "$_: $!\n";
175         parse($_,$x);
176     }
177 }
178
179 die "must say -w<something>\n" if !defined $write;
180
181 sub zilch () {
182     undef $c_table;
183     undef $c_entryextra;
184     undef $c_of;
185 }
186
187 sub enumargs ($) {
188     my ($a) = @_;
189     $a =~ m:/(.*),: or die "invalid enum type \`$a'\n";
190     my ($a_tab, $ee_type, $estr) = ($`,$1,$');
191     if ($ee_type !~ m/^[^_]/) {
192         $ee_type= $a_tab.$ee_type;
193         $a_tab= lc($a_tab).'_entries';
194     }
195     return ($a_tab, $ee_type, $estr);
196 }
197
198 sub parse ($$) {
199     my ($wh,$f) = @_;
200     while (defined($_= $f->getline)) {
201         chomp; s/\s+$//;
202         next if m/^\s*\#/;
203         next if !m/\S/;
204         while (s/\t/ ' 'x(8 - (length $`) % 8) /e) { }
205
206         s/^\s*//;
207         $this_indent= length $&;
208         while (@i && $this_indent < $i[0]) {
209             shift @i;
210         }
211         if ($this_indent && (!@i || $this_indent > $i[0])) {
212             unshift @i, $this_indent;
213         }
214
215         if (@i==0 && m/^Table\s+(\*?)(\w+)\s+(\w+)$/) {
216             zilch();
217             $c_table= $2;
218             $table_x{$c_table}{T}= $1;
219             $table_x{$c_table}{C}= $3;
220             $entrytype_x{$3}= '' unless exists $entrytype_x{$3};
221         } elsif (@i==0 && m/^Untabled$/) {
222             zilch();
223             $c_table= '';
224         } elsif (@i==0 && m/^(C|H)\-Include\s+(\S.*)$/) {
225             o(lc $1, 30, "#include $2\n");
226         } elsif (@i==0 && m/^EntryExtra\s+(\w+)$/) {
227             zilch();
228             $c_entryextra= $1;
229         } elsif (@i==0 && m/^NoEntryDefine\s+(\w+)$/) {
230             zilch();
231             $entrytype_x{$1}= " ";
232         } elsif (@i>=1 && defined $c_entryextra) {
233             $entrytype_x{$c_entryextra} .= "  $_\n";
234         } elsif (@i==1 && m/^[a-z].*$/ && defined $c_table) {
235             if (m/^[-_0-9A-Za-z]+$/) {
236                 $c_entry= $_;
237             } elsif (m/^([-_0-9A-Za-z]+)\s+(\S.*)$/) {
238                 $c_entry= $1;
239                 $tables{$c_table}{$c_entry}{I} .= ", $2";
240             } else {
241                 badsyntax($wh,$.,"bad entry");
242             }
243             $tables{$c_table}{$c_entry}{A} = [ ];
244         } elsif (@i==2 && m/^\.\.\.\s+(\w+)$/ && defined $c_entry) {
245             $tables{$c_table}{$c_entry}{V}= $1;
246         } elsif (@i==2 && m:^dispatch\(((.*)/(.*)\,.*)\)$: && defined $c_entry) {
247             my $enumargs= $1;
248             my $subcmdtype= $2.$3;
249             $tables{$c_table}{$c_entry}{D}= $subcmdtype;
250             $tables{$c_table}{$c_entry}{V}= 'obj';
251             push @{ $tables{$c_table}{$c_entry}{A} },
252                 { N => 'subcmd', T => 'enum', A => $enumargs, O => '' };
253         } elsif (@i==2 && m/^(\??)([a-z]\w*)\s*(\S.*)/
254                  && defined $c_entry) {
255             ($opt, $var, $type) = ($1,$2,$3);
256             ($type, $xtypeargs) = split_type_args($type);
257             push @{ $tables{$c_table}{$c_entry}{A} },
258                 { N => $var, T => $type, A => $xtypeargs, O => ($opt eq '?') };
259         } elsif (@i==2 && m/^\=\>\s*(\S.*)$/ && defined $c_entry) {
260             ($type, $xtypeargs) = split_type_args($1);
261             $tables{$c_table}{$c_entry}{R}= $type;
262             $tables{$c_table}{$c_entry}{X}= $xtypeargs;
263         } elsif (@i==0 && m/^Type\s+([^\:]+)\:\s+(\S.*)$/) {
264             ($typename,$ctype)= ($1,$2);
265             $ctype .= ' @' unless $ctype =~ m/\@/;
266             ($typename,$xtypeargs) = split_type_args($typename);
267             $types{$typename}= { C => $ctype, X => $xtypeargs };
268         } elsif (@i==0 && s/^Init\s+(\w+)\s+(\S.*)//) {
269             $type_init{$1}= $2;
270         } elsif (@i==0 && s/^Fini\s+(\w+)\s+(\S.*)//) {
271             $type_fini{$1}= $2;
272         } else {
273             badsyntax($wh,$., sprintf
274                       "bad directive (indent level %d)", scalar @i);
275         }
276     }
277     $f->error and die $!;
278     $f->close;
279 }
280
281 #print Dumper(\%tables),"\n";
282 #print Dumper(\%types),"\n";
283
284 foreach $t (sort keys %types) {
285     $type= $types{$t};
286     $c= $type->{C};
287     $xta= $type->{X};
288     $decl= "int cht_pat_$t(Tcl_Interp *ip, Tcl_Obj *obj, ";
289     $decl .= subst_in_decl('*val', $c, "type $t");
290     $decl .= ", $xta",  if length $xta;
291     $decl .= ");\n";
292     o('h',160, $decl);
293
294     $decl= "Tcl_Obj *cht_ret_$t(Tcl_Interp *ip, ".subst_in_decl('val',$c);
295     $decl .= ", $xta" if length $xta;
296     $decl .= ");\n";
297     o('h',170, $decl);
298 }
299
300 foreach $c_entrytype (sort keys %entrytype_x) {
301     next if $entrytype_x{$c_entrytype} =~ m/^\s$/;
302     o('h', 20, "typedef struct $c_entrytype $c_entrytype;\n");
303     o('h', 100,
304       "struct $c_entrytype {\n".
305       "  const char *name;\n".
306       "  Tcl_ObjCmdProc *func;\n".
307       $entrytype_x{$c_entrytype}.
308       "};\n\n");
309 }
310
311 foreach $c_table (sort keys %tables) {
312     $r_table= $tables{$c_table};
313     $x_table= $table_x{$c_table};
314     $op_tab= '';
315
316     foreach $c_entry (sort keys %$r_table) {
317         $c_entry_c= $c_entry; $c_entry_c =~ y/-/_/;
318         $r_entry= $r_table->{$c_entry};
319         $pa_decl= "int pa_${c_table}_${c_entry_c}(ClientData cd,".
320             " Tcl_Interp *ip, int objc, Tcl_Obj *const *objv)";
321         $pa_func= "cht_do_${c_table}_${c_entry_c}";
322         if (exists $r_entry->{D}) {
323             $pa_func= "cht_dispatch_$r_entry->{D}";
324         }
325         $do_decl= "int $pa_func(";
326         @do_al= ('ClientData cd', 'Tcl_Interp *ip');
327         @do_aa= qw(cd ip);
328         $pa_init= '';
329         $pa_argc= "  objc--; objv++;\n";
330         $pa_vars= "  int rc;\n";
331         $pa_body= '';
332         $pa_rslt= '';
333         $pa_free= '';
334         $pa_fini= '';
335         $any_mand= 0;
336         $any_optl= 0;
337         $any_eerr= 0;
338         $any_eargc= 0;
339         $pa_hint= '';
340         $pa_hint .= "$c_table " if length $c_table &&
341             !length $table_x{$c_table}{T};
342         $pa_hint.= $c_entry;
343         foreach $arg (@{ $r_entry->{A} }) {
344             $n= $arg->{N};
345             $t= $arg->{T};
346             $a= $arg->{A};
347             push @do_al, make_decl($n, $t, $arg->{A},
348                                    "table $c_table entry $c_entry arg $n");
349             $pa_vars .= make_decl_init("a_$n", $t, $a, \$pa_init, "pa_vars");
350             if ($arg->{O}) {
351                 $pa_hint .= " ?$n?";
352                 if ($any_mand) {
353                     $any_mand= 0;
354                     $any_eerr= 1;
355                 }
356                 $pa_body .= "  if (!objc--) goto end_optional;\n";
357                 $any_optl= 1;
358             } else {
359                 $pa_hint .= " $n";
360                 $pa_body .= "  if (!objc--) goto wrong_count_args;\n";
361                 $any_mand++;
362                 $any_eargc= 1;
363                 die if $any_optl;
364             }
365             $paarg= "&a_$n";
366             $pafin= '';
367             if ($t eq 'enum') {
368                 $pa_vars .= "  const void *v_$n= 0;\n";
369                 $paarg= "&v_$n";
370                 $pafin= "\n  a_$n= v_$n; ";
371                 ($a_tab, $ee_type, $estr) = enumargs($a);
372                 $a = "cht_$a_tab, sizeof($ee_type), $estr";
373                 o('h', 210, "extern const $ee_type cht_$a_tab".'[]'.";\n");
374             }
375             if (exists $type_fini{$t}) {
376                 $pa_fini .= '  '.subst_in("a_$n", $type_fini{$t})."\n";
377             }
378             $pa_body .= "  rc= cht_pat_$t(ip, *objv++, $paarg";
379             $pa_body .= ", ".$a if length $a;
380             $pa_body .= ");$pafin if (rc) goto rc_err;\n";
381             push @do_aa, "a_$n";
382         }
383         if (exists $r_entry->{V}) {
384             $pa_hint .= " ...";
385             $va= $r_entry->{V};
386             push @do_al, subst_in_decl("${va}c", 'int @');
387             push @do_al, subst_in_decl("${va}v", 'Tcl_Obj *const *@');
388             push @do_aa, "objc+1", "objv-1";
389         } else {
390             if (!$any_optl) {
391                 $pa_body .= "  if (objc) goto wrong_count_args;\n";
392                 $any_eargc= 1;
393             }
394         }
395         if ($any_optl) {
396             $pa_body .= "end_optional:\n";
397         }
398         if (exists $r_entry->{R}) {
399             $t= $r_entry->{R};
400             $xta= $r_entry->{X};
401             push @do_al, make_decl("*result", $t, "cht_do_al result");
402             $pa_vars .= make_decl_init("result", $t, $xta, \$pa_init,
403                                        "pa_vars result");
404             push @do_aa, "&result";
405             $pa_rslt .= "  Tcl_SetObjResult(ip, cht_ret_$t(ip, result";
406             $pa_rslt .= ", $xta" if length $xta;
407             $pa_rslt .= "));\n";
408         }
409         $pa_body .= "\n";
410         $pa_body .= "  rc= $pa_func(";
411         $pa_body .= join ', ', @do_aa;
412         $pa_body .= ");\n";
413         $pa_body .= "  if (rc) goto rc_err;\n";
414
415         $pa_rslt .= "  rc= TCL_OK;\n\n";
416         $pa_rslt .= "rc_err:\n";
417         
418         $pa_fini .= "  return rc;\n";
419         if ($any_eargc) {
420             $pa_fini .= "\nwrong_count_args:\n";
421             $pa_fini .= "  e=\"wrong # args: should be \\\"$pa_hint\\\"\";\n";
422             $pa_fini .= "  goto e_err;";
423             $any_eerr= 1;
424         }
425         if ($any_eerr) {
426             $pa_vars .= "  const char *e;\n";
427             $pa_fini .= "\n";
428             $pa_fini .= "e_err:\n";
429             $pa_fini .= "  cht_setstringresult(ip,e);\n";
430             $pa_fini .= "  rc= TCL_ERROR; goto rc_err;\n";
431         }
432         $pa_vars .= "\n";
433         $pa_init .= "\n" if length $pa_init;
434         $pa_fini .= "}\n\n";
435
436         if (length $c_table) {
437             $static= 'static ';
438         } else {
439             $static= '';
440             o('h',90, "$pa_decl;\n");
441         }
442         o('c',100,
443           $static.$pa_decl." {\n".
444           $pa_vars.
445           $pa_init.
446           $pa_argc.
447           $pa_body.
448           $pa_rslt.
449           $pa_free.
450           $pa_fini);
451         $do_decl .= join ', ', @do_al;
452         $do_decl .= ")";
453
454         if (exists $r_entry->{D}) {
455             my $subcmdtype= $r_entry->{D};
456             if (!exists $dispatch_done{$subcmdtype}) {
457                 my $di_body='';
458                 $di_body .= "static $do_decl {\n";
459                 $di_body .= "  return subcmd->func(0,ip,objc,objv);\n";
460                 $di_body .= "}\n";
461                 o('c',50, $di_body) or die $!;
462             }
463         } else {
464             o('h',100, $do_decl.";\n") or die $!;
465         }
466
467         $op_tab .= sprintf("  { %-20s %-40s%s },\n",
468                            "\"$c_entry\",",
469                            "pa_${c_table}_${c_entry_c}",
470                            $r_entry->{I});
471     }
472     if (length $c_table) {
473         $decl= "const $x_table->{C} cht_${c_table}_entries[]";
474         o('h', 500, "extern $decl;\n");
475         o('c', 100,
476           "$decl = {\n".
477           $op_tab.
478           "  { 0 }\n".
479           "};\n\n");
480     }
481 }
482
483 o(c, 0, "#include \"$prefix.h\"\n");
484
485 o(h, 0,
486   "#ifndef INCLUDED_\U${prefix}_H\n".
487   "#define INCLUDED_\U${prefix}_H\n\n");
488
489 o(h, 999,
490   "#endif /*INCLUDED_\U${prefix}_H*/\n");
491
492 if (defined $output) {
493     $oh= new IO::File "$output.tmp", 'w' or die "$output.tmp: $!\n";
494 } else {
495     $oh= 'STDOUT';
496 }
497
498 print $oh "/* AUTOGENERATED - DO NOT EDIT */\n" or die $!;
499 foreach $pr (sort keys %{ $o{$write} }) {
500     print $oh "\n" or die $!;
501     print $oh $o{$write}{$pr} or die $!;
502 }
503
504 die if $oh->error;
505 die $! unless $oh->close;
506
507 if (defined $output) {
508     rename "$output.tmp", $output or die $!;
509 }
510
511 sub o ($$) {
512     my ($wh,$pr,$s) = @_;
513     $o{$wh}{sprintf "%010d", $pr} .= $s;
514 }
515
516 sub split_type_args ($) {
517     my ($type) = @_;
518     my ($xtypeargs);
519     if ($type =~ m/^\w+$/) {
520         $xtypeargs='';
521     } elsif ($type =~ m/^(\w+)\((.+)\)$/) {
522         $type= $1;
523         $xtypeargs= $2;
524     } else {
525         badsyntax($wh,$.,"bad type name/args \`$type'\n");
526     }
527     return ($type,$xtypeargs);
528 }
529
530 sub make_decl_init ($$$$$) {
531     my ($n, $t, $a, $initcode, $why) = @_;
532     my ($o,$init);
533     $o= make_decl($n,$t,$a,"$why _init");
534     if (exists $type_init{$t}) {
535         $init= $type_init{$t};
536         $$initcode .= "  ".subst_in("$n", $init)."\n"
537             if length $init;
538     } else {
539         $o .= ' =0';
540     }
541     return "  ".$o.";\n";
542 }
543
544 sub make_decl ($$$$) {
545     my ($n, $t, $ta, $why) = @_;
546     my ($type);
547     if ($t eq 'enum') {
548         ($a_tab, $ee_type, $estr) = enumargs($ta);
549         $c= "const $ee_type* @";
550     } else { 
551         defined $types{$t} or die "unknown type $t ($why)\n";
552         $c= $types{$t}{C};
553     }
554     return subst_in_decl($n,$c);
555 }
556
557 sub subst_in_decl ($$$) {
558     my ($val, $pat, $why) = @_;
559     local ($_) = subst_in($val, $pat, $why);
560     s/ *(\**) *$/$1/;
561     return $_;
562 }
563     
564 sub subst_in ($$$) {
565     my ($val, $pat, $why) = @_;
566     $pat =~ m/\@/ or die "$pat for $val in $why ?";
567     $pat =~ s/\@/$val/g;
568     return $pat;
569 }
570
571 sub badsyntax ($$$) {
572     die "$_[0]:$_[1]: $_[2]\n";
573 }
574
575 __DATA__
576 Type int:       int
577 Type obj:       Tcl_Obj *@