File: getbacktrace.tex

package info (click to toggle)
sollya 8.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,592 kB
  • sloc: ansic: 124,655; yacc: 7,543; lex: 2,440; makefile: 888; cpp: 77
file content (101 lines) | stat: -rw-r--r-- 3,268 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
\subsection{getbacktrace}
\label{labgetbacktrace}
\noindent Name: \textbf{getbacktrace}\\
\phantom{aaa}returns the list of \sollya procedures currently run\\[0.2cm]
\noindent Library name:\\
\verb|   sollya_obj_t sollya_lib_getbacktrace();|\\[0.2cm]
\noindent Usage: 
\begin{center}
\textbf{getbacktrace}() : \textsf{void} $\rightarrow$ \textsf{list}\\
\end{center}
\noindent Description: \begin{itemize}

\item The \textbf{getbacktrace} command allows the stack of \sollya procedures that are
   currently run to be inspected. When called, \textbf{getbacktrace} returns an
   ordered list of structures, each of which contains an element
   \verb|passed_args| and an element \verb|called_proc|. The element \verb|called_proc|
   contains the \sollya object representing the procedure being run. The
   element \verb|passed_args| contains an ordered list of all effective
   arguments passed to the procedure when it was called. The procedure called
   last (\emph{i.e.}, on top of the stack) comes first in the list returned
   by \textbf{getbacktrace}. When any of the procedure called takes no arguments, the
   \verb|passed_args| element of the corresponding structure evaluates to an empty
   list.

\item When called from outside any procedure (at toplevel), \textbf{getbacktrace} returns
   an empty list.

\item When called for a stack containing a call to a variadic procedure that was
   called with an infinite number of effective arguments, the corresponding
   \verb|passed_args| element evaluates to an end-elliptic list.
\end{itemize}
\noindent Example 1: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> procedure testA() {
        "Current backtrace:";
        getbacktrace();
  };
> procedure testB(X) {
        "X = ", X;
        testA();
  };
> procedure testC(X, Y) {
        "X = ", X, ", Y = ", Y;
        testB(Y);
  };
> testC(17, 42);
X = 17, Y = 42
X = 42
Current backtrace:
[|{ .passed_args = [| |], .called_proc = proc()
{
"Current backtrace:";
getbacktrace();
return void;
} }, { .passed_args = [|42|], .called_proc = proc(X)
{
"X = ", X;
testA();
return void;
} }, { .passed_args = [|17, 42|], .called_proc = proc(X, Y)
{
"X = ", X, ", Y = ", Y;
testB(Y);
return void;
} }|]
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> getbacktrace();
[| |]
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 3: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> procedure printnumargs(X) {
        var L, t;
        "number of arguments: ", X;
        L = getbacktrace();
        "Backtrace:";
        for t in L do {
          "  " @ objectname(t.called_proc) @ ", ", t.passed_args;
        };
  };
> procedure numargs(l = ...) {
        "l[17] = ", l[17];
        printnumargs(length(l));
  };
> procedure test() {
        numargs @ [|25, 26, 27 ...|];
  };
> test();
l[17] = 42
number of arguments: infty
Backtrace:
  printnumargs, [|infty|]
  numargs, [|25, 26, 27...|]
  test, [| |]
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{proc} (\ref{labproc}), \textbf{procedure} (\ref{labprocedure}), \textbf{objectname} (\ref{labobjectname}), \textbf{bind} (\ref{labbind}), \textbf{@} (\ref{labconcat})