OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [doc/] [Interp.3] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1989-1993 The Regents of the University of California.
3
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4
'\"
5
'\" See the file "license.terms" for information on usage and redistribution
6
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7
'\"
8
'\" RCS: @(#) $Id: Interp.3,v 1.1.1.1 2002-01-16 10:25:24 markom Exp $
9
'\"
10
.so man.macros
11
.TH Tcl_Interp 3 7.5 Tcl "Tcl Library Procedures"
12
.BS
13
.SH NAME
14
Tcl_Interp \- client-visible fields of interpreter structures
15
.SH SYNOPSIS
16
.nf
17
\fB#include \fR
18
.sp
19
typedef struct {
20
        char *\fIresult\fR;
21
        Tcl_FreeProc *\fIfreeProc\fR;
22
        int \fIerrorLine\fR;
23
} Tcl_Interp;
24
 
25
typedef void Tcl_FreeProc(char *\fIblockPtr\fR);
26
.BE
27
 
28
.SH DESCRIPTION
29
.PP
30
The \fBTcl_CreateInterp\fR procedure returns a pointer to a Tcl_Interp
31
structure.  This pointer is then passed into other Tcl procedures
32
to process commands in the interpreter and perform other operations
33
on the interpreter.  Interpreter structures contain many many fields
34
that are used by Tcl, but only three that may be accessed by
35
clients:  \fIresult\fR, \fIfreeProc\fR, and \fIerrorLine\fR.
36
.PP
37
The \fIresult\fR and \fIfreeProc\fR fields are used to return
38
results or error messages from commands.
39
This information is returned by command procedures back to \fBTcl_Eval\fR,
40
and by \fBTcl_Eval\fR back to its callers.
41
The \fIresult\fR field points to the string that represents the
42
result or error message, and the \fIfreeProc\fR field tells how
43
to dispose of the storage for the string when it isn't needed anymore.
44
The easiest way for command procedures to manipulate these
45
fields is to call procedures like \fBTcl_SetResult\fR
46
or \fBTcl_AppendResult\fR;  they
47
will hide all the details of managing the fields.
48
The description below is for those procedures that manipulate the
49
fields directly.
50
.PP
51
Whenever a command procedure returns, it must ensure
52
that the \fIresult\fR field of its interpreter points to the string
53
being returned by the command.
54
The \fIresult\fR field must always point to a valid string.
55
If a command wishes to return no result then \fIinterp->result\fR
56
should point to an empty string.
57
Normally, results are assumed to be statically allocated,
58
which means that the contents will not change before the next time
59
\fBTcl_Eval\fR is called or some other command procedure is invoked.
60
.VS
61
In this case, the \fIfreeProc\fR field must be zero.
62
Alternatively, a command procedure may dynamically
63
allocate its return value (e.g. using \fBTcl_Alloc\fR)
64
and store a pointer to it in \fIinterp->result\fR.
65
In this case, the command procedure must also set \fIinterp->freeProc\fR
66
to the address of a procedure that can free the value, or \fBTCL_DYNAMIC\fR
67
if the storage was allocated directly by Tcl or by a call to
68
\fBTcl_Alloc\fR.
69
.VE
70
If \fIinterp->freeProc\fR is non-zero, then Tcl will call \fIfreeProc\fR
71
to free the space pointed to by \fIinterp->result\fR before it
72
invokes the next command.
73
If a client procedure overwrites \fIinterp->result\fR when
74
\fIinterp->freeProc\fR is non-zero, then it is responsible for calling
75
\fIfreeProc\fR to free the old \fIinterp->result\fR (the \fBTcl_FreeResult\fR
76
macro should be used for this purpose).
77
.PP
78
\fIFreeProc\fR should have arguments and result that match the
79
\fBTcl_FreeProc\fR declaration above:  it receives a single
80
argument which is a pointer to the result value to free.
81
.VS
82
In most applications \fBTCL_DYNAMIC\fR is the only non-zero value ever
83
used for \fIfreeProc\fR.
84
.VE
85
However, an application may store a different procedure address
86
in \fIfreeProc\fR in order to use an alternate memory allocator
87
or in order to do other cleanup when the result memory is freed.
88
.PP
89
As part of processing each command, \fBTcl_Eval\fR initializes
90
\fIinterp->result\fR
91
and \fIinterp->freeProc\fR just before calling the command procedure for
92
the command.  The \fIfreeProc\fR field will be initialized to zero,
93
and \fIinterp->result\fR will point to an empty string.  Commands that
94
do not return any value can simply leave the fields alone.
95
Furthermore, the empty string pointed to by \fIresult\fR is actually
96
part of an array of \fBTCL_RESULT_SIZE\fR characters (approximately 200).
97
If a command wishes to return a short string, it can simply copy
98
it to the area pointed to by \fIinterp->result\fR.  Or, it can use
99
the sprintf procedure to generate a short result string at the location
100
pointed to by \fIinterp->result\fR.
101
.PP
102
It is a general convention in Tcl-based applications that the result
103
of an interpreter is normally in the initialized state described
104
in the previous paragraph.
105
Procedures that manipulate an interpreter's result (e.g. by
106
returning an error) will generally assume that the result
107
has been initialized when the procedure is called.
108
If such a procedure is to be called after the result has been
109
changed, then \fBTcl_ResetResult\fR should be called first to
110
reset the result to its initialized state.
111
.PP
112
The \fIerrorLine\fR
113
field is valid only after \fBTcl_Eval\fR returns
114
a \fBTCL_ERROR\fR return code.  In this situation the \fIerrorLine\fR
115
field identifies the line number of the command being executed when
116
the error occurred.  The line numbers are relative to the command
117
being executed:  1 means the first line of the command passed to
118
\fBTcl_Eval\fR, 2 means the second line, and so on.
119
The \fIerrorLine\fR field is typically used in conjunction with
120
\fBTcl_AddErrorInfo\fR to report information about where an error
121
occurred.
122
\fIErrorLine\fR should not normally be modified except by \fBTcl_Eval\fR.
123
 
124
.SH KEYWORDS
125
free, initialized, interpreter, malloc, result

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.