1
1
mirror of https://github.com/github/semantic.git synced 2024-12-25 07:55:12 +03:00

Merge pull request #404 from github/none-is-the-loneliest-umber

Compile Python None expressions.
This commit is contained in:
Rob Rix 2019-12-16 09:34:05 -05:00 committed by GitHub
commit ae6b2849f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -341,7 +341,11 @@ instance Compile Py.Module where
in fmap (locate it) . foldr compile buildRecord stmts
instance Compile Py.NamedExpression
instance Compile Py.None
instance Compile Py.None where
-- None is not overridable, and thus always points to the prelude's None.
compile _it cc _ = cc (pure "__semantic_prelude" ... "None")
instance Compile Py.NonlocalStatement
instance Compile Py.NotOperator

View File

@ -10,8 +10,16 @@
str <- type "str" object #record { __new__: \prim -> instance #unit prim #record{} };
NoneType <- type "None" object #record { __new__: \prim -> instance #unit prim #record{} };
None <- NoneType.__slots.__new__ #unit;
getitem <- \super -> \item -> \attr ->
if item.slots.?attr then item.slots.attr else #unit;
#record { type: type, object: object, str: str, getitem: getitem}
#record { type: type
, object: object
, str: str
, NoneType: NoneType
, None: None
, getitem: getitem}
}

View File

@ -0,0 +1,2 @@
# CHECK-TREE: { x <- __semantic_prelude.None; #record { x : x }}
x = None