From: Armin R. <ar...@us...> - 2002-03-24 14:24:44
|
Update of /cvsroot/psyco/psyco/c/Python In directory usw-pr-cvs1:/tmp/cvs-serv18930/c/Python Modified Files: pycheader.h pycompiler.c pycompiler.h Log Message: sys._getframe() support Index: pycheader.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/Python/pycheader.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pycheader.h 18 Mar 2002 19:04:23 -0000 1.7 --- pycheader.h 24 Mar 2002 14:24:39 -0000 1.8 *************** *** 109,112 **** EXTERNFN vinfo_t* generic_call_check(PsycoObject* po, int flags, vinfo_t* vi); - #endif /* _PYCHEADER_H */ --- 109,111 ---- Index: pycompiler.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/Python/pycompiler.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** pycompiler.c 20 Mar 2002 21:58:44 -0000 1.23 --- pycompiler.c 24 Mar 2002 14:24:39 -0000 1.24 *************** *** 880,883 **** --- 880,929 ---- + #define FRAME_STACK_ALLOC_BY 83 /* about 1KB */ + + DEFINEFN + stack_frame_info_t* psyco_finfo(PsycoObject* callee) + { + Source sglobals; + static stack_frame_info_t* current = NULL; + static stack_frame_info_t* end = NULL; + if (current == end) { + current = (stack_frame_info_t*) + PyCore_MALLOC(FRAME_STACK_ALLOC_BY * + sizeof(stack_frame_info_t)); + if (current == NULL) + OUT_OF_MEMORY(); + end = current + FRAME_STACK_ALLOC_BY; + } + current->co = callee->pr.co; + sglobals = callee->vlocals.items[INDEX_LOC_GLOBALS]->source; + if (is_compiletime(sglobals)) + current->globals = (PyObject*) CompileTime_Get(sglobals)->value; + else + current->globals = NULL; /* uncommon */ + + return current++; + } + + DEFINEFN + PyFrameObject* psyco_emulate_frame(stack_frame_info_t* finfo, + PyObject* default_globals) + { + PyFrameObject* back; + PyFrameObject* result; + PyThreadState* tstate = PyThreadState_GET(); + + /* frame objects are not created in stack order + with Psyco, so it's probably better not to + create plain wrong chained lists */ + back = tstate->frame; + tstate->frame = NULL; + result = PyFrame_New(tstate, finfo->co, + finfo->globals!=NULL?finfo->globals:default_globals, + NULL); + tstate->frame = back; + return result; + } + /***************************************************************/ /*** Initialization ***/ Index: pycompiler.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/Python/pycompiler.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** pycompiler.h 18 Mar 2002 19:04:23 -0000 1.9 --- pycompiler.h 24 Mar 2002 14:24:39 -0000 1.10 *************** *** 49,52 **** --- 49,56 ---- #endif + #ifndef PyCode_GetNumFree + # define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars)) + #endif + #define MAX3(a,b,c) ((a)>(b)?((a)>(c)?(a):(c)):(b)>(c)?(b):(c)) *************** *** 377,380 **** --- 381,395 ---- } + /* to keep a trace of the Psyco stack frames */ + typedef struct stack_frame_info_s { + int stack_depth; + PyCodeObject* co; + PyObject* globals; /* NULL if not compile-time */ + } stack_frame_info_t; + + EXTERNFN stack_frame_info_t* psyco_finfo(PsycoObject* callee); + + EXTERNFN PyFrameObject* psyco_emulate_frame(stack_frame_info_t* finfo, + PyObject* default_globals); #endif /* _PYCOMPILER_H */ |