From: Armin R. <ar...@us...> - 2002-02-28 11:55:55
|
Update of /cvsroot/psyco/psyco/c In directory usw-pr-cvs1:/tmp/cvs-serv9908/c Modified Files: dispatcher.c encoding.h processor.c processor.h psyco.c psyco.h pycencoding.h Log Message: more fixes, and sys.exc_xxx fully implemented Index: dispatcher.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/dispatcher.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dispatcher.c 11 Feb 2002 19:14:14 -0000 1.13 --- dispatcher.c 28 Feb 2002 11:55:51 -0000 1.14 *************** *** 670,673 **** --- 670,674 ---- CodeBufferObject* target_codebuf = *target; int sdepth = get_stack_depth(&target_codebuf->snapshot); + int popsdepth; char pops[REG_TOTAL+2]; *************** *** 703,706 **** --- 704,708 ---- /* update the registers (1): reg-to-reg moves and exchanges */ + popsdepth = po->stack_depth; memset(pops, -1, sizeof(pops)); for (i=0; i<REG_TOTAL; i++) *************** *** 714,728 **** if (rg != i) { ! vinfo_t* c = REG_NUMBER(po, i); ! if (c != NULL) ! { ! SET_RUNTIME_REG_TO(c, rg); ! REG_NUMBER(po, rg) = c; ! XCHG_REGS(i, rg); ! } ! else ! LOAD_REG_FROM_REG(i, rg); ! /* an update is omitted because we are about to ! release 'po' anyway: 'REG_NUMBER(po, i) = a;' */ } dm.copy_regs[i] = NULL; --- 716,724 ---- if (rg != i) { ! NEED_REGISTER(i); ! LOAD_REG_FROM_REG(i, rg); ! SET_RUNTIME_REG_TO(a, i); ! REG_NUMBER(po, rg) = NULL; ! REG_NUMBER(po, i) = a; } dm.copy_regs[i] = NULL; *************** *** 745,762 **** } /* update the registers (2): stack-to-register POPs */ ! for (i=0; pops[i]>=0 || pops[i+1]>=0; i++) ! { ! char reg = pops[i]; ! if (reg<0) ! { /* If there is only one 'garbage' stack entry, POP it as well. If there are more, give up and use regular MOVs to load the rest */ ! po->stack_depth -= 4; ! reg = pops[++i]; ! POP_REG(reg); ! } ! POP_REG(reg); ! dm.copy_regs[(int) reg] = NULL; ! po->stack_depth -= 4; ! } if (code > dm.code_limit) /* start a new buffer if we wrote past the end */ code = data_new_buffer(code, &dm); --- 741,759 ---- } /* update the registers (2): stack-to-register POPs */ ! if (popsdepth == po->stack_depth) ! for (i=0; pops[i]>=0 || pops[i+1]>=0; i++) ! { ! char reg = pops[i]; ! if (reg<0) ! {/* If there is only one 'garbage' stack entry, POP it as well. If there are more, give up and use regular MOVs to load the rest */ ! po->stack_depth -= 4; ! reg = pops[++i]; ! POP_REG(reg); ! } ! POP_REG(reg); ! dm.copy_regs[(int) reg] = NULL; ! po->stack_depth -= 4; ! } if (code > dm.code_limit) /* start a new buffer if we wrote past the end */ code = data_new_buffer(code, &dm); Index: encoding.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/encoding.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** encoding.h 26 Feb 2002 23:08:00 -0000 1.9 --- encoding.h 28 Feb 2002 11:55:51 -0000 1.10 *************** *** 39,42 **** --- 39,43 ---- #define REG_FUNCTIONS_RETURN REG_386_EAX #define REG_ANY_CALLER_SAVED REG_386_EAX /* just any "trash" register */ + #define REG_ANY_CALLEE_SAVED REG_386_EBX /* saved by C functions */ typedef enum { *************** *** 525,540 **** } while (0) - /* C functions that want to return several values can do so by - taking an array of longs as arguments. Use the following - macro to reserve space in the stack. In the register 'rg' will - be copied the address of the reserved space. - Use psyco_alloc_space_array() to allocate the reserved space - to an array of vinfo_t's. */ - #define RESERVE_STACK_SPACE(cnt, rg) do { \ - STACK_CORRECTION(4*(cnt)); \ - po->stack_depth += 4*(cnt); \ - LOAD_REG_FROM_REG(rg, REG_386_ESP); \ - } while (0) - /* load the 'dst' register with the run-time address of 'source' which must be in the stack */ --- 526,529 ---- *************** *** 911,919 **** } while (0) ! #define EMIT_TRACE(msg) do { \ TEMP_SAVE_REGS_FN_CALLS; \ PUSH_IMMED((long) code); \ PUSH_IMMED((long) (msg)); \ ! CALL_C_FUNCTION(psyco_trace_execution, 2); \ STACK_CORRECTION(-8); \ TEMP_RESTORE_REGS_FN_CALLS; \ --- 900,908 ---- } while (0) ! #define EMIT_TRACE(msg, fn) do { \ TEMP_SAVE_REGS_FN_CALLS; \ PUSH_IMMED((long) code); \ PUSH_IMMED((long) (msg)); \ ! CALL_C_FUNCTION(fn, 2); \ STACK_CORRECTION(-8); \ TEMP_RESTORE_REGS_FN_CALLS; \ Index: processor.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/processor.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** processor.c 18 Feb 2002 07:56:34 -0000 1.8 --- processor.c 28 Feb 2002 11:55:52 -0000 1.9 *************** *** 2,5 **** --- 2,6 ---- #include "vcompiler.h" #include "codemanager.h" + #include "pycencoding.h" #include "Python/pycompiler.h" /* for exception handling stuff */ *************** *** 116,131 **** DEFINEFN code_t* psyco_finish_return(PsycoObject* po, NonVirtualSource retval) { code_t* code = po->code; ! int retpos = getstack(po->vlocals.items[INDEX_LOC_CONTINUATION]->source); ! ! /* load the return value into EAX */ ! if (retval != SOURCE_DUMMY) ! LOAD_REG_FROM(retval, REG_FUNCTIONS_RETURN); ! /* 'retpos' is the position in the stack of the return value. */ ! /* clean up the stack up to that position */ extra_assert(retpos != RunTime_StackNone); STACK_CORRECTION(retpos - po->stack_depth); --- 117,171 ---- DEFINEFN + void psyco_emit_header(PsycoObject* po, int nframelocal) + { + int j = nframelocal; + vinfo_array_t* array; + extra_assert(LOC_CONTINUATION->array->count == 0); + + BEGIN_CODE + INITIALIZE_FRAME_LOCALS(nframelocal); + po->stack_depth += 4*nframelocal; + END_CODE + + array = LOC_CONTINUATION->array = array_new(nframelocal); + while (j--) + array->items[j] = vinfo_new(RunTime_NewStack + (po->stack_depth - 4*j, REG_NONE, false)); + } + + DEFINEFN code_t* psyco_finish_return(PsycoObject* po, NonVirtualSource retval) { code_t* code = po->code; ! int retpos; ! int nframelocal = LOC_CONTINUATION->array->count; ! /* 'retpos' is the position in the stack of the return address. */ ! retpos = getstack(LOC_CONTINUATION->source); extra_assert(retpos != RunTime_StackNone); + + /* load the return value into EAX for regular functions, EBX for functions + with a prologue */ + if (retval != SOURCE_DUMMY) { + reg_t rg = nframelocal>0 ? REG_ANY_CALLEE_SAVED : REG_FUNCTIONS_RETURN; + LOAD_REG_FROM(retval, rg); + } + + if (nframelocal > 0) + { + /* psyco_emit_header() was used; first clear the stack only up to and not + including the frame-local data */ + int framelocpos = retpos + 4*nframelocal; + extra_assert(framelocpos == + getstack(LOC_CONTINUATION->array->items[0]->source)); + STACK_CORRECTION(framelocpos - po->stack_depth); + po->stack_depth = framelocpos; + + /* perform Python-specific cleanup */ + FINALIZE_FRAME_LOCALS(nframelocal); + LOAD_REG_FROM_REG(REG_FUNCTIONS_RETURN, REG_ANY_CALLEE_SAVED); + } + + /* now clean up the stack up to retpos */ STACK_CORRECTION(retpos - po->stack_depth); *************** *** 952,956 **** char argtags[MAX_ARGUMENTS_COUNT]; long raw_args[MAX_ARGUMENTS_COUNT], args[MAX_ARGUMENTS_COUNT]; ! int count, i, j; vinfo_t* vresult; bool has_refs = false; --- 992,996 ---- char argtags[MAX_ARGUMENTS_COUNT]; long raw_args[MAX_ARGUMENTS_COUNT], args[MAX_ARGUMENTS_COUNT]; ! int count, i, j, stackbase, totalstackspace = 0; vinfo_t* vresult; bool has_refs = false; *************** *** 1018,1021 **** --- 1058,1062 ---- case 'A': has_refs = true; + totalstackspace += 4*((vinfo_array_t*) arg)->count; break; *************** *** 1109,1112 **** --- 1150,1156 ---- BEGIN_CODE SAVE_REGS_FN_CALLS; + stackbase = po->stack_depth; + po->stack_depth += totalstackspace; + STACK_CORRECTION(totalstackspace); for (i=count; i--; ) { switch (argtags[i]) { *************** *** 1129,1139 **** int j = array->count; if (j > 0) { ! RESERVE_STACK_SPACE(j, REG_ANY_CALLER_SAVED); ! } ! while (j--) { ! array->items[j] = vinfo_new ! (RunTime_NewStack(po->stack_depth - 4*j, ! REG_NONE, ! with_reference)); } CALL_SET_ARG_FROM_RT (RunTime_New(REG_ANY_CALLER_SAVED, --- 1173,1185 ---- int j = array->count; if (j > 0) { ! do { ! stackbase += 4; ! array->items[--j] = vinfo_new ! (RunTime_NewStack(stackbase, ! REG_NONE, ! with_reference)); ! } while (j); ! LOAD_ADDRESS_FROM_RT (array->items[0]->source, ! REG_ANY_CALLER_SAVED); } CALL_SET_ARG_FROM_RT (RunTime_New(REG_ANY_CALLER_SAVED, Index: processor.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/processor.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** processor.h 15 Feb 2002 12:46:36 -0000 1.7 --- processor.h 28 Feb 2002 11:55:52 -0000 1.8 *************** *** 326,329 **** --- 326,335 ---- /*** code termination ***/ + /* write a function header reserving 'nframelocal' machine words for + local storage. These are put in an array under LOC_CONTINUATION as + run-time values. Do not use this with nframelocal==0; no header is + needed (so far) in this case. */ + EXTERNFN void psyco_emit_header(PsycoObject* po, int nframelocal); + /* write a return, clearing the stack as necessary, and releases 'po'. */ EXTERNFN code_t* psyco_finish_return(PsycoObject* po, NonVirtualSource retval); Index: psyco.c =================================================================== RCS file: /cvsroot/psyco/psyco/c/psyco.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** psyco.c 27 Feb 2002 11:35:46 -0000 1.24 --- psyco.c 28 Feb 2002 11:55:52 -0000 1.25 *************** *** 133,136 **** --- 133,137 ---- po->last_used_reg = REG_LOOP_START; po->pr.auto_recursion = recursion; + po->pr.mp_flags = psyco_mp_flags(merge_points); /* duplicate the inputvinfos. If two arguments share some common part, they *************** *** 239,242 **** --- 240,247 ---- if (is_proxycode(co)) co = ((PsycoFunctionObject*) PyTuple_GET_ITEM(co->co_consts, 1))->psy_code; + else + if (--recursion < 0) /* the recursion limit only applies to non-proxified + functions */ + goto fail_to_default; tuple_size = PsycoTuple_Load(arg_tuple); *************** *** 951,954 **** --- 956,964 ---- { debug_printf(("psyco: trace %p for %s\n", code_position, msg)); + } + DEFINEFN void psyco_trace_execution_noerr(char* msg, void* code_position) + { + debug_printf(("psyco: trace %p for %s\n", code_position, msg)); + assert(!PyErr_Occurred()); } #endif Index: psyco.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/psyco.h,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** psyco.h 26 Feb 2002 23:03:34 -0000 1.17 --- psyco.h 28 Feb 2002 11:55:52 -0000 1.18 *************** *** 153,161 **** #endif #if VERBOSE_LEVEL >= 4 ! # define TRACE_EXECUTION(msg) do { \ ! BEGIN_CODE EMIT_TRACE(msg); END_CODE } while (0) EXTERNFN void psyco_trace_execution(char* msg, void* code_position); #else ! # define TRACE_EXECUTION(msg) do { } while (0) /* nothing */ #endif --- 153,165 ---- #endif #if VERBOSE_LEVEL >= 4 ! # define TRACE_EXECUTION(msg) do { \ ! BEGIN_CODE EMIT_TRACE(msg, psyco_trace_execution); END_CODE } while (0) ! # define TRACE_EXECUTION_NOERR(msg) do { \ ! BEGIN_CODE EMIT_TRACE(msg, psyco_trace_execution_noerr); END_CODE } while (0) EXTERNFN void psyco_trace_execution(char* msg, void* code_position); + EXTERNFN void psyco_trace_execution_noerr(char* msg, void* code_position); #else ! # define TRACE_EXECUTION(msg) do { } while (0) /* nothing */ ! # define TRACE_EXECUTION_NOERR(msg) do { } while (0) /* nothing */ #endif Index: pycencoding.h =================================================================== RCS file: /cvsroot/psyco/psyco/c/pycencoding.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pycencoding.h 26 Feb 2002 23:08:00 -0000 1.4 --- pycencoding.h 28 Feb 2002 11:55:52 -0000 1.5 *************** *** 324,327 **** --- 324,349 ---- } + /* called by psyco_emit_header() */ + #define INITIALIZE_FRAME_LOCALS(nframelocal) do { \ + STACK_CORRECTION(4*((nframelocal)-1)); \ + PUSH_IMMED(0); /* f_exc_type, initially NULL */ \ + } while (0) + + /* called by psyco_finish_return() */ + #define FINALIZE_FRAME_LOCALS(nframelocal) do { \ + CODE_FOUR_BYTES(code, \ + 0x83, \ + 0x3C, /* CMP [ESP], 0 */ \ + 0x24, \ + 0); \ + code[4] = 0x70 | CC_E; /* JE exit */ \ + code[5] = 11 - 6; \ + code[6] = 0xE8; /* CALL cimpl_finalize_frame_locals */ \ + code += 11; \ + *(long*)(code-4) = (code_t*)(&cimpl_finalize_frame_locals) - code; \ + } while (0) + + /* implemented in pycompiler.c */ + EXTERNFN void cimpl_finalize_frame_locals(PyObject*, PyObject*, PyObject*); #endif /* _PYCENCODING_H */ |