mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Merge pull request #407 from github/not-the-branch-you're-looking-for
Compile `not` statements.
This commit is contained in:
commit
fd494852fe
@ -46,6 +46,9 @@ pattern SingleIdentifier name <- Py.ExpressionList
|
||||
]
|
||||
}
|
||||
|
||||
prelude :: Has Core sig t => [Name] -> t Name
|
||||
prelude = foldl' (\a b -> a ... b) (pure "__semantic_prelude")
|
||||
|
||||
-- We leave the representation of Core syntax abstract so that it's not
|
||||
-- possible for us to 'cheat' by pattern-matching on or eliminating a
|
||||
-- compiled term.
|
||||
@ -196,8 +199,8 @@ instance Compile Py.ClassDefinition where
|
||||
bindings <- asks @Bindings (toList . unBindings)
|
||||
let buildName n = (n, pure n)
|
||||
contents = record . fmap buildName $ bindings
|
||||
typefn = pure "__semantic_prelude" ... "type"
|
||||
object = pure "__semantic_prelude" ... "object"
|
||||
typefn = prelude ["type"]
|
||||
object = prelude ["object"]
|
||||
|
||||
pure (typefn $$ Core.string (coerce n) $$ object $$ contents)
|
||||
|
||||
@ -343,11 +346,15 @@ instance Compile Py.Module where
|
||||
instance Compile Py.NamedExpression
|
||||
|
||||
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")
|
||||
-- None is not an lvalue, and thus always points to the prelude's None.
|
||||
compile _it cc _ = cc (prelude ["None"])
|
||||
|
||||
instance Compile Py.NonlocalStatement
|
||||
instance Compile Py.NotOperator
|
||||
|
||||
instance Compile Py.NotOperator where
|
||||
compile _it@Py.NotOperator{ argument } cc next = do
|
||||
val <- compile argument pure next
|
||||
cc (prelude ["not"] $$ val)
|
||||
|
||||
instance Compile Py.ParenthesizedExpression where
|
||||
compile it@Py.ParenthesizedExpression { extraChildren } cc
|
||||
@ -384,7 +391,7 @@ instance Compile Py.String where
|
||||
|
||||
if any isNothing contents
|
||||
then pure . invariantViolated $ "Couldn't string-desugar " <> show it
|
||||
else let new = pure "__semantic_prelude" ... "str" ... "__slots" ... "__new__"
|
||||
else let new = prelude ["str", "__slots", "__new__"]
|
||||
in cc $ locate it (new $$ Core.string (mconcat (catMaybes contents)))
|
||||
|
||||
instance Compile Py.Subscript
|
||||
|
@ -10,6 +10,10 @@
|
||||
|
||||
str <- type "str" object #record { __new__: \prim -> instance #unit prim #record{} };
|
||||
|
||||
// We will fill in the actual definition of these operators
|
||||
// pending the presence of more eliminators.
|
||||
not <- \val -> if val then #false else #true;
|
||||
|
||||
NoneType <- type "None" object #record { __new__: \prim -> instance #unit prim #record{} };
|
||||
None <- NoneType.__slots.__new__ #unit;
|
||||
|
||||
@ -19,6 +23,7 @@
|
||||
#record { type: type
|
||||
, object: object
|
||||
, str: str
|
||||
, not: not
|
||||
, NoneType: NoneType
|
||||
, None: None
|
||||
, getitem: getitem}
|
||||
|
2
semantic-python/test/fixtures/4-03-not-expression.py
vendored
Normal file
2
semantic-python/test/fixtures/4-03-not-expression.py
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# CHECK-TREE: { x <- __semantic_prelude.not #true; #record { x: x }}
|
||||
x = not True
|
Loading…
Reference in New Issue
Block a user