diff -r b765a6383849 -r b40b0e18a918 jitcraft/Stack.h --- a/jitcraft/Stack.h Mon Jul 09 22:25:52 2012 -0700 +++ b/jitcraft/Stack.h Tue Jul 10 02:11:13 2012 -0700 @@ -56,7 +56,11 @@ Frame *prev_; bytecode *prevpc_; - Function *fun_; + union { + Function *fun_; + Native *native_; + Object *callee_; + }; Code *code_; Address lifoPosition_; @@ -70,6 +74,15 @@ { } + Frame(Frame *prev, bytecode *prevpc, Native *native, Address lifoPosition) + : prev_(prev), + prevpc_(prevpc), + native_(native), + code_(NULL), + lifoPosition_(lifoPosition) + { + } + LocalSlot *locals() { return reinterpret_cast(this + 1); } @@ -77,13 +90,17 @@ return locals() + code_->nlocals(); } Function *fun() const { - assert(fun_); + assert(fun_ && callee_->is(MapKind_Function)); return fun_; } Function *maybeFun() const { - return fun_; + return (fun_ && callee_->is(MapKind_Function)) ? fun_ : NULL; + } + bool isNative() const { + return callee_ && callee_->is(MapKind_Native); } Code *code() const { + assert(code_); return code_; } Frame *prev() const { @@ -127,9 +144,32 @@ } }; +// RAII object for calling a native from C++. +class NativeArgs +{ + friend class Stack; + + Stack *stack_; + LocalSlot *argsBase_; + + public: + NativeArgs() + : stack_(NULL), + argsBase_(NULL) + { + } + + ~NativeArgs(); + + intptr_t *args() { + return reinterpret_cast(argsBase_); + } +}; + class Stack { friend class InvokeArgs; + friend class NativeArgs; private: static const size_t STACK_SIZE = 1024 * 1024; @@ -145,6 +185,7 @@ Frame *popInlineFrame(); bool pushInvokeFrame(Handle fun, InvokeArgs &args); + bool pushNativeFrame(Handle native, NativeArgs &args, unsigned argc); Top *top() { return &top_; @@ -154,6 +195,7 @@ private: void popInvokeFrame(InvokeArgs &args); + void popNativeFrame(NativeArgs &args); private: char *buffer_;