1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

Merge remote-tracking branch 'origin/master' into precise-alacarte-matching

This commit is contained in:
Timothy Clem 2020-01-15 10:06:56 -08:00
commit 42ee75445d
4 changed files with 20 additions and 7 deletions

View File

@ -1,4 +1,3 @@
{-# OPTIONS_GHC -Wno-unused-imports -Wno-unused-top-binds #-}
module Main (main) where
import Gauge

View File

@ -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

View File

@ -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}

View File

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