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 |
5189
|
42 extern int main_loop (void); |
1907
|
43 |
2796
|
44 extern void |
|
45 do_octave_atexit (void); |
2077
|
46 |
1
|
47 // Current command to execute. |
578
|
48 extern tree_statement_list *global_command; |
1
|
49 |
4238
|
50 // Pointer to parent function that is currently being evaluated. |
4748
|
51 extern octave_function *curr_parent_function; |
4238
|
52 |
4217
|
53 // TRUE means we are ready to interpret commands, but not everything |
|
54 // is ready for interactive use. |
7185
|
55 extern OCTINTERP_API bool octave_interpreter_ready; |
4217
|
56 |
4172
|
57 // TRUE means we've processed all the init code and we are good to go. |
7185
|
58 extern OCTINTERP_API bool octave_initialized; |
4172
|
59 |
5743
|
60 class |
|
61 octave_call_stack |
|
62 { |
|
63 protected: |
|
64 |
|
65 octave_call_stack (void) : cs () { } |
|
66 |
|
67 public: |
|
68 |
|
69 typedef std::list<octave_function *>::iterator iterator ; |
|
70 |
|
71 static bool instance_ok (void) |
|
72 { |
|
73 bool retval = true; |
|
74 |
|
75 if (! instance) |
|
76 instance = new octave_call_stack (); |
|
77 |
|
78 if (! instance) |
|
79 { |
|
80 ::error ("unable to create call stack object!"); |
|
81 |
|
82 retval = false; |
|
83 } |
|
84 |
|
85 return retval; |
|
86 } |
|
87 |
|
88 // Current function (top of stack). |
5744
|
89 static octave_function *current (void) { return top (); } |
5743
|
90 |
|
91 // Caller function, may be built-in. |
|
92 static octave_function *caller (void) |
|
93 { |
|
94 return instance_ok () ? instance->do_caller (): 0; |
|
95 } |
|
96 |
5744
|
97 // First script on the stack. |
|
98 static octave_user_script *caller_script (void) |
5743
|
99 { |
5744
|
100 return instance_ok () ? instance->do_caller_user_script (): 0; |
|
101 } |
|
102 |
|
103 // First user-defined function on the stack. |
|
104 static octave_user_function *caller_user_function (void) |
|
105 { |
|
106 return instance_ok () ? instance->do_caller_user_function (): 0; |
|
107 } |
|
108 |
|
109 // First user-defined function on the stack. |
|
110 static octave_function *caller_user_script_or_function (void) |
|
111 { |
|
112 return instance_ok () ? instance->do_caller_user_script_or_function (): 0; |
5743
|
113 } |
|
114 |
|
115 static void push (octave_function *f) |
|
116 { |
|
117 if (instance_ok ()) |
|
118 instance->do_push (f); |
|
119 } |
|
120 |
5744
|
121 static octave_function *top (void) |
|
122 { |
|
123 return instance_ok () ? instance->do_top (): 0; |
|
124 } |
|
125 |
5743
|
126 static void pop (void) |
|
127 { |
|
128 if (instance_ok ()) |
|
129 instance->do_pop (); |
|
130 } |
|
131 |
|
132 // A function for popping the top of the call stack that is suitable |
|
133 // for use as an unwind_protect handler. |
|
134 static void unwind_pop (void *) { pop (); } |
|
135 |
5744
|
136 // A function for popping an octave_user_script from the top of the |
|
137 // call stack that is suitable for use as an unwind_protect handler. |
|
138 static void unwind_pop_script (void *); |
|
139 |
5743
|
140 static void clear (void) |
|
141 { |
|
142 if (instance_ok ()) |
|
143 instance->do_clear (); |
|
144 } |
|
145 |
|
146 private: |
|
147 |
|
148 // The current call stack. |
|
149 std::list<octave_function *> cs; |
|
150 |
|
151 static octave_call_stack *instance; |
|
152 |
|
153 octave_function *do_caller (void); |
|
154 |
5744
|
155 octave_user_script *do_caller_user_script (void); |
|
156 |
|
157 octave_user_function *do_caller_user_function (void); |
|
158 |
|
159 octave_function *do_caller_user_script_or_function (void); |
5743
|
160 |
|
161 void do_push (octave_function *f) { cs.push_front (f); } |
|
162 |
5744
|
163 octave_function *do_top (void) { return cs.empty () ? 0 : cs.front (); } |
|
164 |
5743
|
165 void do_pop (void) |
|
166 { |
|
167 if (! cs.empty ()) |
|
168 cs.pop_front (); |
|
169 } |
|
170 |
|
171 void do_clear (void) { cs.clear (); } |
|
172 }; |
|
173 |
1
|
174 #endif |
|
175 |
|
176 /* |
|
177 ;;; Local Variables: *** |
|
178 ;;; mode: C++ *** |
|
179 ;;; End: *** |
|
180 */ |