1
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, |
|
4 2003, 2004, 2005, 2006, 2007 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
1
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
1
|
21 |
|
22 */ |
|
23 |
1670
|
24 #if !defined (octave_toplev_h) |
|
25 #define octave_toplev_h 1 |
1
|
26 |
1355
|
27 #include <cstdio> |
1
|
28 |
5743
|
29 #include <list> |
3503
|
30 #include <string> |
|
31 |
2086
|
32 class octave_value; |
2796
|
33 class octave_value_list; |
5743
|
34 class octave_function; |
5744
|
35 class octave_user_script; |
578
|
36 class tree_statement_list; |
1572
|
37 class charMatrix; |
1
|
38 |
2796
|
39 extern void |
|
40 clean_up_and_exit (int) GCC_ATTR_NORETURN; |
574
|
41 |
7202
|
42 extern void recover_from_exception (void); |
|
43 |
5189
|
44 extern int main_loop (void); |
1907
|
45 |
2796
|
46 extern void |
|
47 do_octave_atexit (void); |
2077
|
48 |
1
|
49 // Current command to execute. |
578
|
50 extern tree_statement_list *global_command; |
1
|
51 |
4238
|
52 // Pointer to parent function that is currently being evaluated. |
4748
|
53 extern octave_function *curr_parent_function; |
4238
|
54 |
4217
|
55 // TRUE means we are ready to interpret commands, but not everything |
|
56 // is ready for interactive use. |
7185
|
57 extern OCTINTERP_API bool octave_interpreter_ready; |
4217
|
58 |
4172
|
59 // TRUE means we've processed all the init code and we are good to go. |
7185
|
60 extern OCTINTERP_API bool octave_initialized; |
4172
|
61 |
5743
|
62 class |
|
63 octave_call_stack |
|
64 { |
|
65 protected: |
|
66 |
|
67 octave_call_stack (void) : cs () { } |
|
68 |
|
69 public: |
|
70 |
|
71 typedef std::list<octave_function *>::iterator iterator ; |
|
72 |
|
73 static bool instance_ok (void) |
|
74 { |
|
75 bool retval = true; |
|
76 |
|
77 if (! instance) |
|
78 instance = new octave_call_stack (); |
|
79 |
|
80 if (! instance) |
|
81 { |
|
82 ::error ("unable to create call stack object!"); |
|
83 |
|
84 retval = false; |
|
85 } |
|
86 |
|
87 return retval; |
|
88 } |
|
89 |
|
90 // Current function (top of stack). |
5744
|
91 static octave_function *current (void) { return top (); } |
5743
|
92 |
|
93 // Caller function, may be built-in. |
|
94 static octave_function *caller (void) |
|
95 { |
|
96 return instance_ok () ? instance->do_caller (): 0; |
|
97 } |
|
98 |
5744
|
99 // First script on the stack. |
|
100 static octave_user_script *caller_script (void) |
5743
|
101 { |
5744
|
102 return instance_ok () ? instance->do_caller_user_script (): 0; |
|
103 } |
|
104 |
|
105 // First user-defined function on the stack. |
|
106 static octave_user_function *caller_user_function (void) |
|
107 { |
|
108 return instance_ok () ? instance->do_caller_user_function (): 0; |
|
109 } |
|
110 |
|
111 // First user-defined function on the stack. |
|
112 static octave_function *caller_user_script_or_function (void) |
|
113 { |
|
114 return instance_ok () ? instance->do_caller_user_script_or_function (): 0; |
5743
|
115 } |
|
116 |
|
117 static void push (octave_function *f) |
|
118 { |
|
119 if (instance_ok ()) |
|
120 instance->do_push (f); |
|
121 } |
|
122 |
5744
|
123 static octave_function *top (void) |
|
124 { |
|
125 return instance_ok () ? instance->do_top (): 0; |
|
126 } |
|
127 |
5743
|
128 static void pop (void) |
|
129 { |
|
130 if (instance_ok ()) |
|
131 instance->do_pop (); |
|
132 } |
|
133 |
|
134 // A function for popping the top of the call stack that is suitable |
|
135 // for use as an unwind_protect handler. |
|
136 static void unwind_pop (void *) { pop (); } |
|
137 |
5744
|
138 // A function for popping an octave_user_script from the top of the |
|
139 // call stack that is suitable for use as an unwind_protect handler. |
|
140 static void unwind_pop_script (void *); |
|
141 |
5743
|
142 static void clear (void) |
|
143 { |
|
144 if (instance_ok ()) |
|
145 instance->do_clear (); |
|
146 } |
|
147 |
|
148 private: |
|
149 |
|
150 // The current call stack. |
|
151 std::list<octave_function *> cs; |
|
152 |
|
153 static octave_call_stack *instance; |
|
154 |
|
155 octave_function *do_caller (void); |
|
156 |
5744
|
157 octave_user_script *do_caller_user_script (void); |
|
158 |
|
159 octave_user_function *do_caller_user_function (void); |
|
160 |
|
161 octave_function *do_caller_user_script_or_function (void); |
5743
|
162 |
|
163 void do_push (octave_function *f) { cs.push_front (f); } |
|
164 |
5744
|
165 octave_function *do_top (void) { return cs.empty () ? 0 : cs.front (); } |
|
166 |
5743
|
167 void do_pop (void) |
|
168 { |
|
169 if (! cs.empty ()) |
|
170 cs.pop_front (); |
|
171 } |
|
172 |
|
173 void do_clear (void) { cs.clear (); } |
|
174 }; |
|
175 |
1
|
176 #endif |
|
177 |
|
178 /* |
|
179 ;;; Local Variables: *** |
|
180 ;;; mode: C++ *** |
|
181 ;;; End: *** |
|
182 */ |