1
1
mirror of https://github.com/github/semantic.git synced 2024-12-28 09:21:35 +03:00

First attempt at compiling string literals.

This commit is contained in:
Patrick Thomson 2019-10-16 17:22:18 -04:00
parent cd69e8aab5
commit b5d6e7186f
2 changed files with 17 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import Data.Coerce
import Data.Foldable import Data.Foldable
import Data.Function import Data.Function
import Data.List.NonEmpty (NonEmpty (..)) import Data.List.NonEmpty (NonEmpty (..))
import Data.Traversable
import GHC.Records import GHC.Records
import Source.Span (Span) import Source.Span (Span)
import Syntax.Stack (Stack (..)) import Syntax.Stack (Stack (..))
@ -355,7 +356,15 @@ instance Compile Py.SetComprehension
deriving instance Compile Py.SimpleStatement deriving instance Compile Py.SimpleStatement
instance Compile Py.String instance Compile Py.String where
compile it@Py.String { extraChildren } cc _ = do
contents <- for extraChildren $ \case
Prj Py.EscapeSequence { text } -> pure text
other -> fail ("Couldn't string-desugar " <> show other)
let new = pure "__semantic_prelude" ... "str" ... "__class" ... "__new__"
cc $ locate it (new $$ Core.string (mconcat contents))
instance Compile Py.Subscript instance Compile Py.Subscript
instance Compile Py.True where instance Compile Py.True where

View File

@ -2,7 +2,13 @@
type <- \name -> \bases -> \dict -> type <- \name -> \bases -> \dict ->
#record { __name: name, __bases: bases, __dict: dict }; #record { __name: name, __bases: bases, __dict: dict };
instance <- \class -> \prim -> \slots ->
#record { __class: class, __prim: prim, __slots: slots }
object <- type "object" #unit #record{}; object <- type "object" #unit #record{};
#record { type: type, object: object } str <- type "str" object #record { }
str.__class.__new__ = \contents -> instance str contents #record{}
#record { type: type, object: object, string: string }
} }