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