Skip to content

Commit

Permalink
gypsum: Introduce ModuleScope for per-file bindings
Browse files Browse the repository at this point in the history
ModuleScope is a scope for each file in a package. Global definitions
and imports are bound in ModuleScope initially. Definitions (but not
imports) are copied to GlobalScope after we have walked the AST.

This means that symbols that are imported in one file are not visible
in other files. Imported symbols shadow definitions in other files but
they are overloaded with definitions in the same file.

Fixes #34.
  • Loading branch information
jayconrod committed Feb 12, 2017
1 parent b0f5c37 commit 8e1f9d8
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 94 deletions.
18 changes: 13 additions & 5 deletions gypsum/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,17 @@ class Global(IrTopDefn):
id (DefnId): unique identifier for the global.
sourceName (str?): name of the definition in source code
astDefn (ast.Node?): the location in source code where the global is defined.
astVarDefn (ast.Node?): the location in source code of the variable definition
containing the field definition.
type (Type?): the type of the global. May be `None` before type analysis.
flags (frozenset[flag]): flags indicating how this global may be used. Valid flags are
`EXTERN`, `LET`, `PUBLIC`.
"""

def __init__(self, name, id, sourceName=None, astDefn=None, type=None, flags=frozenset()):
def __init__(self, name, id, sourceName=None, astDefn=None, astVarDefn=None,
type=None, flags=frozenset()):
super(Global, self).__init__(name, id, sourceName, astDefn)
self.astVarDefn = astVarDefn
self.type = type
self.flags = flags

Expand Down Expand Up @@ -1089,9 +1093,10 @@ def findCommonUpperBound(self, other):
PARAMETER = "parameter"

class Variable(IrDefinition):
def __init__(self, name, sourceName=None, astDefn=None, type=None, kind=LOCAL,
flags=frozenset()):
def __init__(self, name, sourceName=None, astDefn=None, astVarDefn=None,
type=None, kind=LOCAL, flags=frozenset()):
super(Variable, self).__init__(name, sourceName, astDefn)
self.astVarDefn = astVarDefn
self.type = type
self.kind = kind
self.flags = flags
Expand All @@ -1117,6 +1122,8 @@ class Field(IrDefinition):
name (Name): the name of the field.
sourceName (str?): name of the definition in source code
astDefn (ast.Node?): the location in source code where the field is defined.
astVarDefn (ast.Node?): the location in source code of the variable definition
containing the field definition.
type (Type?): the type of the field. May be `None` before type analysis.
flags (frozenset[flag]): flags indicating how this field is used. Valid flags are
`LET`, `PUBLIC`, `PROTECTED`, `PRIVATE`, `STATIC`.
Expand All @@ -1127,9 +1134,10 @@ class that inherits this field).
instructions. This will usually be `None` before semantic analysis.
"""

def __init__(self, name, sourceName=None, astDefn=None, type=None, flags=frozenset(),
definingClass=None, index=None):
def __init__(self, name, sourceName=None, astDefn=None, astVarDefn=None, type=None,
flags=frozenset(), definingClass=None, index=None):
super(Field, self).__init__(name, sourceName, astDefn)
self.astVarDefn = astVarDefn
self.type = type
self.flags = flags
self.definingClass = definingClass
Expand Down
Loading

0 comments on commit 8e1f9d8

Please sign in to comment.