Hi, Dag Sverre Seljebotn wote: > Sebastien Binet wrote: >> Just for fun and to see how cython works, I am trying to write a >> CythonInterpreter inheriting from the usual code.InteractiveConsole.
Way cool. I always wanted something like that for quickly checking out code snippets without going all the way through writing a module and pyximporting it. >> So far so good, I manage to compile cython-oneliners (leveraging >> pyximport.load_module) but then I'd need some help for multi-lines >> statements: >> ## ex: >> cdef class Foo: >> pass >> ## >> >> for this to work in a reasonnable timely fashion, I'd need to see if >> parsing the snippet of code is valid cython (without compiling). The current parser isn't made for parsing things interactively, so I have no idea if this is trivial or hard to do. You might get away with checking for parser errors that indicate a missing indentation after the last character that you passed. Every parse error inside or before the last line would indicate a 'real' parser error. >> (I guess I'd need to know if the parsing failed b/c of unsupported python >> constructs or if it is b/c the cython command is incomplete) > > I don't think this is possible currently as Cython can generate errors at > any point in its pipeline. This isn't the point here, though. All he needs is to know if a command is complete or if he should keep reading stuff from the console. > In time it might be possible to stop the > pipeline at an earlier stage, but I wouldn't expect great speedups here > still as parsing takes a significant part of the time (don't remember the > numbers though). Parse time really isn't a problem here. I think the main problem will be that you need to load and reload tons of modules (again, not a timing issue). Maybe giving the module a public C-API interface and accessing it through ctypes would work better? But that's not something that needs solving as a first step. I'm fine with loading a couple of thousand modules in an interactive session for now. The main use case is testing stuff, so restarting the interpreter when it gets too heavy isn't a huge problem IMHO. Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
