Supporting #line directives
Andrew Csillag
drew.csillag at starmedia.net
Mon Mar 6 13:05:09 EST 2000
Michael Hudson wrote:
>
> Andrew Csillag <drew.csillag at starmedia.net> writes:
>
> > I don't really want a debugger for it (although it would be neat), I
> > just want to make it so that I don't have to do so much work in order to
> > render a traceback that shows source lines in the original source file.
> > Python's bytecode already has a SET_LINENO instruction, if there were a
> > SET_FILENAME instruction, that would handle it nicely (of cource ceval.c
> > would probably require a bit of modification, but that's just a "simple
> > matter of programming" <0.3 wink>).
> >
> > Unfortunately, introspection doesn't help a bit here. With
> > introspection I can find out where functions and classes are defined in
> > python source, but not in the original (non-python) source.
>
> >>> def f():
> ... raise "hiya!"
> ...
> >>> from bytecodehacks import common
> >>> import new
> >>> f=new.function(common.copy_code_with_changes(
> ... f.func_code,filename="whatever.c"),f.func_globals)
> >>> f()
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> File "whatever.c", line 2, in f
> hiya!
> >>>
>
> Is this helping?
Not really :(. For example, consider a zope-like templating language
and the following program in source.fooml:
<!--#loop foo sequence_var-->
some text of the loop
<!--#val 'sequence_var + 5' format=urlquote-->
<!--#/loop-->
This would compile to something like this:
for sequence_var in foo:
_doc.write('some tex of the loop\012')
_tempvar = sequence_var + 5
_doc.write(_formatters.urlquote(str(_tempvar)))
Ideally, if sequence_var + 5 is invalid at runtime (say sequence_var is
a string),
I'd like the traceback to say something like this:
Traceback (innermost last):
...other stuff...
File "source.fooml", line 3 in ?
<!--#val 'sequence_var + 5' format=urlquote->
TypeError: illegal argument type for built-in operation
As opposed to a message pointing to _tempvar = sequence_var + 5 (which
tells the user of the templating language next to nothing).
--
print(lambda(q,p):'pmt:$%0.2f'%(q*p/(p-1)))((lambda(a,r,n),t:(a*r/
t,pow(1+r/t,n*12)))(map(input,('amt:','%rate:','years:')),1200.0))
More information about the Python-list
mailing list