This repository was archived by the owner on Apr 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 459
Python support using Core #119
Merged
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
4a9255a
Stub in a semantic-python package.
robrix e4e5370
Correct some fields for Core.
robrix ebc025b
Add some dependencies.
robrix 7ec058c
Fix a disagreement between the LICENSE file and Copyright field.
robrix 52fa1a1
Cabal complains if this file isn’t here.
robrix 5563bc1
Depend on tree-sitter-python.
robrix 6894a75
Stub in a Language.Python.Core module.
robrix 40e9999
Add bug-reports fields.
robrix 83a6c6c
Make the different cabal files line up.
robrix d09ab40
Add stability fields to core & python.
robrix 32c7698
Change the category for semantic to Language.
robrix dd352cb
Add extra-source-files to semantic.
robrix b09e1a6
Add a description to semantic-core.
robrix b8d5747
We’re only supporting 8.6 at present anyway.
robrix afa8b79
Wrap.
robrix 5a2a9f4
Turn on warnings.
robrix 04762dc
Add an export list.
robrix dd08319
Stub in a function to compile a Python module.
robrix fb5b898
Qualify Python stuff if we need to.
robrix 598000c
Stub in compilation to Core.
robrix 7da6b95
Error messages are good, actually.
robrix 41afbd6
Rename compileModule to compile.
robrix 23e18ad
Note a FIXME.
robrix 37cab16
Rephrase Compile as a typeclass.
robrix f09b361
Define compilation of Either.
robrix 07fa556
Move the Either instance up.
robrix 135b8b1
Give a default definition for Compile which just fails.
robrix 0a329ae
Stub in compilation of statements.
robrix c3184f0
Extract the default definition.
robrix c435155
Compile IfStatement.
robrix 602494f
Define generic compilation of sum types.
robrix 3b7a2f1
DerivingVia.
robrix 3728f06
Split out the SimpleStatement cases.
robrix 5b539e8
Add a FIXME re: the orphan instances.
robrix c8d1de4
Alphabetize.
robrix ead494a
These are incurred by IfStatement.
robrix 4e24a1e
No, really alphabetize.
robrix bd9aaa5
Really really.
robrix 2367717
Derive the Either instance.
robrix 1a6812e
Split out instances for Expression.
robrix c15bbcb
Not via.
robrix eb72442
Split out instances for PrimaryExpression.
robrix 9088708
Compile boolean literals.
robrix 6dd5010
:fire: the orphan instances.
robrix b1a89c0
:fire: redundant parens.
robrix f2a9ebe
Qualify the import of TreeSitter.Python.AST.
robrix be842df
Represent strings as Text.
robrix 7583226
Represent paths as Text.
robrix 1bd25ac
Represent user variables as Text.
robrix 06e3c7f
Factor the common bits of the string out.
robrix e9968ca
Use Text for gensym’d names.
robrix 31d396e
Merge branch 'master' into semantic-python
robrix d64e12d
Compile identifiers.
robrix 1164c87
Compile function definitions.
robrix cf8b344
Handle all the unimplemented cases with a helper.
robrix 9ea288a
Merge branch 'master' into semantic-python
robrix 6097e45
:fire: an obsolete FIXME.
robrix 2f07736
Generate Text.
robrix 2009e4a
Fix the IsString instance.
robrix ce1d209
Correct the doctest runner.
robrix 58d819f
Turn on overloaded strings in the doctests.
robrix ffdefb0
Fix the doctest for concrete.
robrix 324e605
Run the doctests in CI.
robrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| packages: . semantic-core | ||
| packages: . semantic-core semantic-python | ||
|
|
||
| jobs: $ncpus | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| {-# LANGUAGE FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, RecordWildCards, TypeOperators, UndecidableInstances #-} | ||
| {-# LANGUAGE FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, OverloadedStrings, RecordWildCards, TypeOperators, UndecidableInstances #-} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pretty much all the changes to |
||
| module Analysis.Concrete | ||
| ( Concrete(..) | ||
| , concrete | ||
|
|
@@ -29,6 +29,7 @@ import Data.Loc | |
| import qualified Data.Map as Map | ||
| import Data.Monoid (Alt(..)) | ||
| import Data.Name | ||
| import Data.Text (Text, pack) | ||
| import Prelude hiding (fail) | ||
|
|
||
| type Precise = Int | ||
|
|
@@ -41,7 +42,7 @@ data Concrete | |
| = Closure Loc Name Core.Core Precise | ||
| | Unit | ||
| | Bool Bool | ||
| | String String | ||
| | String Text | ||
| | Obj Frame | ||
| deriving (Eq, Ord, Show) | ||
|
|
||
|
|
@@ -60,7 +61,7 @@ type Heap = IntMap.IntMap Concrete | |
|
|
||
| -- | Concrete evaluation of a term to a value. | ||
| -- | ||
| -- >>> snd (concrete [File (Loc "bool" emptySpan) (Core.Bool True)]) | ||
| -- >>> map fileBody (snd (concrete [File (Loc "bool" emptySpan) (Core.Bool True)])) | ||
| -- [Right (Bool True)] | ||
| concrete :: [File Core.Core] -> (Heap, [File (Either (Loc, String) Concrete)]) | ||
| concrete | ||
|
|
@@ -184,28 +185,32 @@ heapValueGraph h = heapGraph (const id) (const fromAddr) h | |
| heapAddressGraph :: Heap -> G.Graph (EdgeType, Precise) | ||
| heapAddressGraph = heapGraph (\ addr v -> (Value v, addr)) (fmap G.vertex . (,) . either Edge Slot) | ||
|
|
||
| addressStyle :: Heap -> G.Style (EdgeType, Precise) String | ||
| addressStyle :: Heap -> G.Style (EdgeType, Precise) Text | ||
| addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes } | ||
| where vertex (_, addr) = maybe (show addr <> " = ?") (((show addr <> " = ") <>) . fromConcrete) (IntMap.lookup addr heap) | ||
| where vertex (_, addr) = pack (show addr) <> " = " <> maybe "?" fromConcrete (IntMap.lookup addr heap) | ||
| edgeAttributes _ (Slot name, _) = ["label" G.:= fromName name] | ||
| edgeAttributes _ (Edge Core.Import, _) = ["color" G.:= "blue"] | ||
| edgeAttributes _ (Edge Core.Lexical, _) = ["color" G.:= "green"] | ||
| edgeAttributes _ _ = [] | ||
| fromConcrete = \case | ||
| Unit -> "()" | ||
| Bool b -> show b | ||
| String s -> show s | ||
| Bool b -> pack $ show b | ||
| String s -> pack $ show s | ||
| Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> p <> ":" <> showPos s <> "-" <> showPos e <> "]" | ||
| Obj _ -> "{}" | ||
| showPos (Pos l c) = show l <> ":" <> show c | ||
| showPos (Pos l c) = pack (show l) <> ":" <> pack (show c) | ||
| fromName (User s) = s | ||
| fromName (Gen sym) = fromGensym sym | ||
| fromName (Path p) = show p | ||
| fromName (Path p) = pack $ show p | ||
| fromGensym (Root s) = s | ||
| fromGensym (ss :/ (s, i)) = fromGensym ss <> "." <> s <> show i | ||
| fromGensym (ss :/ (s, i)) = fromGensym ss <> "." <> s <> pack (show i) | ||
|
|
||
| data EdgeType | ||
| = Edge Core.Edge | ||
| | Slot Name | ||
| | Value Concrete | ||
| deriving (Eq, Ord, Show) | ||
|
|
||
|
|
||
| -- $setup | ||
| -- >>> :seti -XOverloadedStrings | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to bring this into line with
semantic.cabal.