Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pfalcon/python-compiler.old
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: pfalcon/python-compiler.old
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: for-block-scope
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Nov 29, 2020

  1. symbols: Basic block-level scoping infrastructure.

    We introduce BlockScope, as a subclass of FunctionScope, to piggyback on
    *some* of the scoping processing done for FunctionScope (but we otherwise
    going to ignore the rest of it).
    
    What we mostly need BlockScope for is like a container for remappings of
    var_name -> var_name.NN (numeric counter). We'd like to apply remapping
    "on the fly" (vs a separate pass on AST with explicit variable rewriting).
    The mapping is stored in Scope.defs (which previously was set emulated
    using dict, i.e. contained 1 as a value).
    
    For the rest of functionality, we try to forward it to the containing
    function scope (and for this, we maintain .func_parent pointer in BlockScope,
    note that it maybe also module or class scope).
    pfalcon committed Nov 29, 2020
    Configuration menu
    Copy the full SHA
    aa73dc4 View commit details
    Browse the repository at this point in the history
  2. symbols, pycodegen: Prototype of block-level scope for "for" variables.

    Due to the fact that this package doesn't include tokenizer and AST parser,
    this prototype applies block-level scope to all "for" statements, whereas
    the original proposal is to apply it only to the loops of new "for const"
    syntax. This prototype also explores block-level scope aspect, not the
    constness aspect.
    
    The implementation is based on basic block-level scoping support introduced
    in the previous commit.
    
    The only interesting part here is that we actually have to walk BlockScope
    subtree to (potentially) remap block-scope variable names. The original
    inspriring idea was to avoid scope-iteration at all, but we clearly don't
    do enough processing in symbols.py for that. And note that to achieve that,
    we'd need to duplicate mapping information in different scopes, i.e. would
    achieve O(1) lookups, but at the price of additional memory usage (likely,
    quadratic). OTOH, due to processing already done by symbols.py, we already
    have sparse namespacing info (comparing to the original AST), and in most
    cases, the scope tree will be rather shallow (or put it differently, price
    of O(n) compile-time lookups will be paid only by the code which (ab)uses
    nested scopes too much).
    pfalcon committed Nov 29, 2020
    Configuration menu
    Copy the full SHA
    b1f9c96 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d32397e View commit details
    Browse the repository at this point in the history
Loading