|
From: Samuele P. <pe...@in...> - 2001-03-12 22:20:36
|
Hi. [Jeremy Hylton] > > >>>>> "SP" == Samuele Pedroni <pe...@in...> writes: > > SP> * CPython 2.1 introduces a symtable module that give access > SP> to the scope info about variables, for the moment the interface > SP> is experimental and related to the actual internals, I don't > SP> know if it is worth to support (?) > > I don't think it's worth supporting yet. I'd like to improve the > interface and make it a bit less implementation specific. Do you have > any ideas on that subject? To be honest between a2 and b1 of CPython 2.1 I have not looked that much at your C code (I have looked at previous versions of it), I was mostly busy writing jython nested scopes. I can report what the different phases on jython side detect plus some random notes. 1. phase (its an entire new compiler phase) for each scope it dinstiguishes between: param var local var explicitly global var (from global decl, internally there is distinction between funcdef global that affect nested scopes and classdef global that do not) and free var at the same time free variable from inner scopes are propagated to outer scopes, so cells are dectected, clearly explicit fundef global stop the propagation. special case: in a class scope a variable can be at the same time local or global and free. The same AFAIK is true for CPython. 2. phase (parallel to bytecode generation) free variable final detection: free var from 1. phase can either be explicit globals because of an outer scope decl, implicit global (= top level free) or truly free vars that should be bound to a cell from an outer scope. (impl/expl global info here is propagated top-down). Does symtable in CPython collect results similar to those of phase 1. or more precise one like those from 2. final phase? Then for each scope we should report (with a dict-like structure or accessor functions or ..) the info for the variable in there, and which of them introduce new scope (class,func, lambda(?)) with ptrs to the related info. Possible issues: lambdas or should we ignore them, and code like this def f(x,y): def g(): return x h=g def g(): return y return (h,g) should we be able to distringuish the two g defs? maybe we should use somehow line infos for that. What are the uses that you imagine for symtable? regards, Samuele Pedroni. |