From 80587be6cc3d3fc42a5c936dc596b1803e18c21a Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Wed, 30 Oct 2019 15:13:34 -0400 Subject: [PATCH] Adjust prelude definitions since we can't yet assign to slots. --- semantic-python/src/Language/Python/Core.hs | 2 +- semantic-python/src/Prelude.score | 2 +- semantic-python/test/Test.hs | 23 +++++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index a8a406ec6..1212c76a9 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -363,7 +363,7 @@ instance Compile Py.String where Prj Py.EscapeSequence { text } -> pure text other -> fail ("Couldn't string-desugar " <> show other) - let new = pure "__semantic_prelude" ... "str" + let new = pure "__semantic_prelude" ... "str" ... "__slots" ... "__new__" cc $ locate it (new $$ Core.string (mconcat contents)) instance Compile Py.Subscript diff --git a/semantic-python/src/Prelude.score b/semantic-python/src/Prelude.score index 6c36e993b..e71bfd357 100644 --- a/semantic-python/src/Prelude.score +++ b/semantic-python/src/Prelude.score @@ -8,7 +8,7 @@ // object's superclass is type itself object <- type "object" type #record{}; - str <- type "str" object #record { }; + str <- type "str" object #record { __new__: \prim -> instance #unit prim #record{} }; getitem <- \super -> \item -> \attr -> if item.slots.?attr then item.slots.attr else #unit; diff --git a/semantic-python/test/Test.hs b/semantic-python/test/Test.hs index c1590fdb0..ca3504a9f 100644 --- a/semantic-python/test/Test.hs +++ b/semantic-python/test/Test.hs @@ -1,7 +1,10 @@ -{-# LANGUAGE DeriveAnyClass, DerivingStrategies, GeneralizedNewtypeDeriving, OverloadedStrings, TypeApplications, TypeOperators, ScopedTypeVariables #-} +{-# LANGUAGE DeriveAnyClass, DerivingStrategies, GeneralizedNewtypeDeriving, OverloadedStrings, ScopedTypeVariables, + TypeApplications, TypeOperators #-} module Main (main) where +import Analysis.Concrete (Concrete) +import qualified Analysis.Concrete as Concrete import Analysis.File import Analysis.ScopeGraph import Control.Effect @@ -12,39 +15,37 @@ import Control.Monad.Catch import Control.Monad.IO.Class import Control.Monad.Trans.Resource (ResourceT, runResourceT) import Core.Core -import qualified Core.Parser -import Core.Pretty import qualified Core.Eval as Eval import Core.Name +import qualified Core.Parser +import Core.Pretty import qualified Data.Aeson as Aeson -import Analysis.Concrete (Concrete) -import qualified Analysis.Concrete as Concrete import qualified Data.Aeson.Encode.Pretty as Aeson import qualified Data.ByteString.Char8 as ByteString import qualified Data.ByteString.Lazy.Char8 as ByteString.Lazy import qualified Data.ByteString.Streaming.Char8 as ByteStream import Data.Foldable import Data.Function +import qualified Data.IntMap as IntMap import Data.List (sort) +import qualified Data.Map as Map import Data.Maybe +import Data.Text (Text) import GHC.Stack import qualified Language.Python.Core as Py import Prelude hiding (fail) -import qualified Data.Map as Map -import qualified Data.IntMap as IntMap import Source.Span +import Streaming import qualified Streaming.Process import Syntax.Term import System.Directory import System.Exit -import Streaming +import System.Path (()) import qualified System.Path as Path import qualified System.Path.Directory as Path -import System.Path (()) import Text.Show.Pretty (ppShow) import qualified Text.Trifecta as Trifecta import qualified TreeSitter.Python as TSP -import Data.Text (Text) import qualified TreeSitter.Unmarshal as TS import qualified Test.Tasty as Tasty @@ -59,7 +60,7 @@ parsePrelude = do let ePrelude = Trifecta.parseByteString (Core.Parser.core <* Trifecta.eof) mempty preludesrc case Trifecta.foldResult (Left . show) Right ePrelude of Right r -> pure r - Left s -> HUnit.assertFailure ("Couldn't parse prelude: " <> s) + Left s -> HUnit.assertFailure ("Couldn't parse prelude: " <> s) assertJQExpressionSucceeds :: Show a => Directive.Directive -> a -> Term (Ann Span :+: Core) Name -> HUnit.Assertion assertJQExpressionSucceeds directive tree core = do