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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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; |
2891
|
35 class octave_user_function; |
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. |
|
55 extern bool octave_interpreter_ready; |
|
56 |
4172
|
57 // TRUE means we've processed all the init code and we are good to go. |
|
58 extern bool octave_initialized; |
|
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). |
|
89 static octave_function *current (void) |
|
90 { |
|
91 return instance_ok () ? instance->do_current (): 0; |
|
92 } |
|
93 |
|
94 // Caller function, may be built-in. |
|
95 static octave_function *caller (void) |
|
96 { |
|
97 return instance_ok () ? instance->do_caller (): 0; |
|
98 } |
|
99 |
|
100 // First scripting language function on the stack. |
|
101 static octave_user_function *caller_script (void) |
|
102 { |
|
103 return instance_ok () ? instance->do_caller_script (): 0; |
|
104 } |
|
105 |
|
106 static void push (octave_function *f) |
|
107 { |
|
108 if (instance_ok ()) |
|
109 instance->do_push (f); |
|
110 } |
|
111 |
|
112 static void pop (void) |
|
113 { |
|
114 if (instance_ok ()) |
|
115 instance->do_pop (); |
|
116 } |
|
117 |
|
118 // A function for popping the top of the call stack that is suitable |
|
119 // for use as an unwind_protect handler. |
|
120 static void unwind_pop (void *) { pop (); } |
|
121 |
|
122 static void clear (void) |
|
123 { |
|
124 if (instance_ok ()) |
|
125 instance->do_clear (); |
|
126 } |
|
127 |
|
128 private: |
|
129 |
|
130 // The current call stack. |
|
131 std::list<octave_function *> cs; |
|
132 |
|
133 static octave_call_stack *instance; |
|
134 |
|
135 octave_function *do_current (void) { return cs.empty () ? 0 : cs.front (); } |
|
136 |
|
137 octave_function *do_caller (void); |
|
138 |
|
139 octave_user_function *do_caller_script (void); |
|
140 |
|
141 void do_push (octave_function *f) { cs.push_front (f); } |
|
142 |
|
143 void do_pop (void) |
|
144 { |
|
145 if (! cs.empty ()) |
|
146 cs.pop_front (); |
|
147 } |
|
148 |
|
149 void do_clear (void) { cs.clear (); } |
|
150 }; |
|
151 |
1
|
152 #endif |
|
153 |
|
154 /* |
|
155 ;;; Local Variables: *** |
|
156 ;;; mode: C++ *** |
|
157 ;;; End: *** |
|
158 */ |