Renamed jitcraft/ to src/, fixed some /Wp64 warnings.
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"
69 Address lifoPosition_;
72 Frame(Frame *prev, bytecode *prevpc, Function *fun, Code *code, Address lifoPosition)
77 lifoPosition_(lifoPosition)
81 Frame(Frame *prev, bytecode *prevpc, Native *native, Address lifoPosition)
86 lifoPosition_(lifoPosition)
91 return reinterpret_cast<LocalSlot *>(this + 1);
93 LocalSlot *stackBase() {
94 return locals() + code_->nlocals();
96 Function *fun() const {
97 assert(fun_ && callee_->is(MapKind_Function));
100 Function *maybeFun() const {
101 return (fun_ && callee_->is(MapKind_Function)) ? fun_ : NULL;
103 bool isNative() const {
104 return callee_ && callee_->is(MapKind_Native);
106 Native *native() const {
114 Frame *prev() const {
117 bytecode *prevpc() const {
120 Address lifoPosition() const {
121 return lifoPosition_;
123 LocalSlot &arg(unsigned slot) {
124 assert(slot < fun()->nargs());
125 return *(reinterpret_cast<LocalSlot *>(this) - slot - 1);
127 void accept(VirtualObjectVisitor *visitor);
130 // RAII object for calling a function from C++.
149 LocalSlot &arg(unsigned index) {
150 assert(index < nargs_);
151 return args_[nargs_ - index - 1];
155 // RAII object for calling a native from C++.
161 LocalSlot *argsBase_;
173 return reinterpret_cast<int *>(argsBase_);
179 friend class InvokeArgs;
180 friend class NativeArgs;
183 static const size_t STACK_SIZE = 1024 * 1024;
192 Frame *pushInlineFrame(Handle<Function> fun);
193 Frame *popInlineFrame();
195 bool pushInvokeFrame(Handle<Function> fun, InvokeArgs &args);
196 bool pushModuleFrame(Handle<Module> module, InvokeArgs &args);
197 bool pushNativeFrame(Handle<Native> native, NativeArgs &args, unsigned argc);
202 bool isInCallStack(Handle<Module> module);
203 void accept(VirtualObjectVisitor *visitor);
206 void popInvokeFrame(InvokeArgs &args);
207 void popNativeFrame(NativeArgs &args);
222 StackIter(Zone *zone);
225 const char *function() const;
226 unsigned lineNumber() const;
227 const char *source() const;
233 #endif // _include_jc_stack_h_