Added support for ISourcePawnEngine natives.
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"
65 Address lifoPosition_;
68 Frame(Frame *prev, bytecode *prevpc, Function *fun, Code *code, Address lifoPosition)
73 lifoPosition_(lifoPosition)
77 Frame(Frame *prev, bytecode *prevpc, Native *native, Address lifoPosition)
82 lifoPosition_(lifoPosition)
87 return reinterpret_cast<LocalSlot *>(this + 1);
89 LocalSlot *stackBase() {
90 return locals() + code_->nlocals();
92 Function *fun() const {
93 assert(fun_ && callee_->is(MapKind_Function));
96 Function *maybeFun() const {
97 return (fun_ && callee_->is(MapKind_Function)) ? fun_ : NULL;
99 bool isNative() const {
100 return callee_ && callee_->is(MapKind_Native);
106 Frame *prev() const {
109 bytecode *prevpc() const {
112 Address lifoPosition() const {
113 return lifoPosition_;
115 LocalSlot &arg(unsigned slot) {
116 assert(slot < fun()->nargs());
117 return *(reinterpret_cast<LocalSlot *>(this) - slot - 1);
119 void accept(VirtualObjectVisitor *visitor);
122 // RAII object for calling a function from C++.
141 LocalSlot &arg(unsigned index) {
142 assert(index < nargs_);
143 return args_[nargs_ - index - 1];
147 // RAII object for calling a native from C++.
153 LocalSlot *argsBase_;
165 return reinterpret_cast<int *>(argsBase_);
171 friend class InvokeArgs;
172 friend class NativeArgs;
175 static const size_t STACK_SIZE = 1024 * 1024;
184 Frame *pushInlineFrame(Handle<Function> fun);
185 Frame *popInlineFrame();
187 bool pushInvokeFrame(Handle<Function> fun, InvokeArgs &args);
188 bool pushNativeFrame(Handle<Native> native, NativeArgs &args, unsigned argc);
193 bool isInCallStack(Handle<Module> module);
194 void accept(VirtualObjectVisitor *visitor);
197 void popInvokeFrame(InvokeArgs &args);
198 void popNativeFrame(NativeArgs &args);
208 #endif // _include_jc_stack_h_