Added error reporting API and fixed all known error paths.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_jc_stack_h_
20 #define _include_jc_stack_h_
25 #include "Functions.h"
26 #include "VirtualObjectVisitor.h"
66 Address lifoPosition_;
69 Frame(Frame *prev, bytecode *prevpc, Function *fun, Code *code, Address lifoPosition)
74 lifoPosition_(lifoPosition)
78 Frame(Frame *prev, bytecode *prevpc, Native *native, Address lifoPosition)
83 lifoPosition_(lifoPosition)
88 return reinterpret_cast<LocalSlot *>(this + 1);
90 LocalSlot *stackBase() {
91 return locals() + code_->nlocals();
93 Function *fun() const {
94 assert(fun_ && callee_->is(MapKind_Function));
97 Function *maybeFun() const {
98 return (fun_ && callee_->is(MapKind_Function)) ? fun_ : NULL;
100 bool isNative() const {
101 return callee_ && callee_->is(MapKind_Native);
103 Native *native() const {
111 Frame *prev() const {
114 bytecode *prevpc() const {
117 Address lifoPosition() const {
118 return lifoPosition_;
120 LocalSlot &arg(unsigned slot) {
121 assert(slot < fun()->nargs());
122 return *(reinterpret_cast<LocalSlot *>(this) - slot - 1);
124 void accept(VirtualObjectVisitor *visitor);
127 // RAII object for calling a function from C++.
146 LocalSlot &arg(unsigned index) {
147 assert(index < nargs_);
148 return args_[nargs_ - index - 1];
152 // RAII object for calling a native from C++.
158 LocalSlot *argsBase_;
170 return reinterpret_cast<int *>(argsBase_);
176 friend class InvokeArgs;
177 friend class NativeArgs;
180 static const size_t STACK_SIZE = 1024 * 1024;
189 Frame *pushInlineFrame(Handle<Function> fun);
190 Frame *popInlineFrame();
192 bool pushInvokeFrame(Handle<Function> fun, InvokeArgs &args);
193 bool pushNativeFrame(Handle<Native> native, NativeArgs &args, unsigned argc);
198 bool isInCallStack(Handle<Module> module);
199 void accept(VirtualObjectVisitor *visitor);
202 void popInvokeFrame(InvokeArgs &args);
203 void popNativeFrame(NativeArgs &args);
218 StackIter(Zone *zone);
221 const char *function() const;
222 unsigned lineNumber() const;
223 const char *source() const;
229 #endif // _include_jc_stack_h_