[IronPython] [python] Re: Missing Compiler Flag

Dino Viehland dinov at exchange.microsoft.com
Wed Oct 3 19:38:28 CEST 2007


BTW the fix for this finally got checked in today (and therefore will be in the next release).  We don't yet pass all of test_codeop but we now pass half of it - we still have some issues w/ test_incomplete and test_valid.  But the flag is respected and appears to be doing the right thing now.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland
Sent: Friday, September 21, 2007 4:20 PM
To: Discussion of IronPython
Subject: Re: [IronPython] [python] Re: Missing Compiler Flag

Awesome, thanks for tracking this down.  I'll probably take a look at this next week.  This might have also provided some insight into how the Python command line works - so maybe that can be improved as a well (I just fixed a couple of those bugs but I'm sure we've got more lurking out there).

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Friday, September 21, 2007 3:05 PM
To: Discussion of IronPython
Subject: Re: [IronPython] [python] Re: Missing Compiler Flag

Michael Foord wrote:
> Hello Dino,
>
> I think I've got it. With this flag set, the compile function will
> return None *if* an indented line would be valid.
>

*so*... compile only returns a code object if the source code is
complete. An indented code block is only complete when there is a dedent
that completes the block.

PyCF_DONT_IMPLY_DEDENT is a 'parser flag' which says "don't imply a
dedent at the end of a block until we actually get an explicit dedent".

All the best,

Michael
http://www.ironpython.info/




> This allows the interactive interpreter to decide which prompt to
> present the user with (and whether to execute the code it has buffered
> or to wait for more input).
>
> For example (from CPython):
>
> PyCF_DONT_IMPLY_DEDENT = 0x200
> def _compile(source, filename, symbol):
>     return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT)
>
> source = 'def x():\n    print x'
> print _compile(source, 'test', 'single')
> None
>
> Without the flag set returns a code object.
>
> There is similar code in the DLRConsole but it uses
> "Microsoft.Scripting.SourceCodeUnit" which isn't present in 2.0a4.
>
> All the best,
>
> Michael
> http://www.ironpython.info/
>
>
> Dino Viehland wrote:
>
>> Ok, I closed 12908 as a dup.  If there's no info on it we can always try reverse engineering it (or see if test_codeop fails when we just ignore the flag instead of throwing - that might be the simplest thing to do).
>>
>> -----Original Message-----
>> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
>> Sent: Friday, September 21, 2007 1:23 PM
>> To: Discussion of IronPython
>> Subject: Re: [IronPython] [python] Re: Missing Compiler Flag
>>
>> Dino Viehland wrote:
>>
>>
>>> Strangely it doesn't seem to be in the documentation for compile() either :(
>>>
>>> Do you know what this option does by any chance :) ?
>>>
>>> I've opened bug #12908
>>>
>>>
>> Great - it can go with 12907. :-)
>>
>> It is  something to do with dedenting. ;-)
>>
>> I can't find much about it on the intarwebz. It is defined in
>> pythonrun.h and seems to be used in pythonrun.c and it is involved with
>> parsing which makes sense.
>>
>> I'll try asking around. *sigh*
>>
>> Michael Foord
>> http://www.manning.com/foord
>>
>>
>>
>>> (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=12908) so we at least have it tracked...
>>>
>>> -----Original Message-----
>>> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
>>> Sent: Friday, September 21, 2007 12:57 PM
>>> To: Discussion of IronPython
>>> Subject: [IronPython] Missing Compiler Flag
>>>
>>> Hello all,
>>>
>>> There's another problem with the interactive interpreter in IronPython
>>> (it affects the ability to use the code standard library module).
>>>
>>> The PyCF_DONT_IMPLY_DEDENT compiler flag is not recognised in IronPython.
>>>
>>> The flag is defined in the 'codeop' standard library module:
>>>
>>> PyCF_DONT_IMPLY_DEDENT = 0x200          # Matches pythonrun.h
>>>
>>> Attempting to use this in IronPython:
>>>
>>>  >>> compile('print x', 'test', 'single', 0x200, 1)
>>> Traceback (most recent call last):
>>>   File , line 0, in <stdin>##1
>>>   File , line 0, in Compile##4
>>> ValueError: unrecognized flags
>>>
>>> Without this flag the code module can't recognize blocks of code with
>>> several indented lines. :-(
>>>
>>> All the best,
>>>
>>>
>>> Michael Foord
>>> http://www.manning.com/foord
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.ironpython.com
>>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.ironpython.com
>>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>>
>>>
>>>
>>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>

_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list