- Timestamp:
- 11/13/2008 10:22:06 PM (8 weeks ago)
- Location:
- trunk/fipy
- Files:
-
- 2 modified
-
tools/inline/inline.py (modified) (4 diffs)
-
variables/variable.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fipy/tools/inline/inline.py
r2817 r2819 9 9 else: 10 10 return pythonFn(*args) 11 12 def _frameComment(code, level=2): 13 frame = inspect.getouterframes(inspect.currentframe())[level] 11 12 def _getframeinfo(level, context=1): 13 """ 14 Much faster alternative to `inspect.getouterframes(inspect.currentframe())[level]` 15 """ 16 frame = inspect.currentframe() 17 for l in range(level+1): 18 frame = frame.f_back 19 20 return (frame,) + inspect.getframeinfo(frame, context=context) 14 21 22 def _rawCodeComment(code, level=2): 23 finfo = _getframeinfo(level=level) 24 15 25 # note: 16 26 # don't use #line because it actually makes it harder … … 24 34 %s 25 35 */ 26 ''' % (frame[1], frame[2] - len(code.splitlines()), frame[3]) 36 ''' % (finfo[1], finfo[2] - len(code.splitlines()), finfo[3]) 37 38 def _operatorVariableComment(canInline=True, level=3): 39 if canInline and inlineFlagOn: 40 finfo = _getframeinfo(level=level) 41 42 # note: 43 # don't use #line because it actually makes it harder 44 # to find the offending code in both the C++ source and in the Python 45 #line %d "%s" 46 47 if finfo[4] is not None: 48 code = "\n".join(finfo[4]) 49 else: 50 code = "" 51 52 return ''' 53 /* 54 %s:%d 55 56 %s 57 */ 58 ''' % (finfo[1], finfo[2], code) 59 else: 60 return "" 27 61 28 62 def _runInline(code_in, converters=None, verbose=0, comment=None, **args): … … 53 87 54 88 if comment is None: 55 comment = _ frameComment(code_in)89 comment = _rawCodeComment(code_in) 56 90 57 91 code = "\n" + comment + "\n" + code … … 104 138 105 139 if comment is None: 106 comment = _ frameComment(code_in)140 comment = _rawCodeComment(code_in) 107 141 108 142 code = "\n" + comment + "\n" + code -
trunk/fipy/variables/variable.py
r2817 r2819 42 42 from fipy.tools import numerix 43 43 from fipy.tools import parser 44 from fipy.tools.inline import inline 44 45 45 46 class Variable(object): … … 804 805 return operatorVariable._OperatorVariableClass(baseClass=baseClass) 805 806 806 def _inlineComment(self, level=3):807 frame = inspect.getouterframes(inspect.currentframe())[level]808 809 # note:810 # don't use #line because it actually makes it harder811 # to find the offending code in both the C++ source and in the Python812 #line %d "%s"813 814 if frame[4] is not None:815 code = "\n".join(frame[4])816 else:817 code = ""818 819 return '''820 /*821 %s:%d822 823 %s824 */825 ''' % (frame[1], frame[2], code)826 827 828 807 def _UnaryOperatorVariable(self, op, operatorClass=None, opShape=None, canInline=True, unit=None): 829 808 """ … … 849 828 canInline = False 850 829 851 var = unOp(op=op, var=[self], opShape=opShape, canInline=canInline, unit=unit, inlineComment=self._inlineComment()) 852 # var.comment = self._frameComment(level=7) 853 854 return var 830 return unOp(op=op, var=[self], opShape=opShape, canInline=canInline, unit=unit, 831 inlineComment=inline._operatorVariableComment(canInline=canInline)) 855 832 856 833 def _shapeClassAndOther(self, opShape, operatorClass, other): … … 898 875 binOp = binaryOperatorVariable._BinaryOperatorVariable(operatorClass) 899 876 900 var = binOp(op=op, var=[self, other], opShape=opShape, canInline=canInline, unit=unit, inlineComment=self._inlineComment()) 901 # var.comment = self._frameComment(level=7) 902 903 return var 877 return binOp(op=op, var=[self, other], opShape=opShape, canInline=canInline, unit=unit, 878 inlineComment=inline._operatorVariableComment(canInline=canInline)) 904 879 905 880 def __add__(self, other):
FiPy: A Finite Volume PDE Solver Using Python