-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from lyncmi07/34_source_code_positions
34 source code positions Closes 34
- Loading branch information
Showing
44 changed files
with
1,184 additions
and
730 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -29,6 +29,7 @@ library: | |
- text-latin1 | ||
- split | ||
- set-theory | ||
- transformers | ||
|
||
executables: | ||
no-syn-exe: | ||
|
This file contains 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 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 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,43 +1,53 @@ | ||
module Com.NoSyn.Ast.If.Block where | ||
|
||
import Prelude hiding (getContents) | ||
import Com.NoSyn.Ast.Traits.TargetCodeGeneratable | ||
import Com.NoSyn.Ast.Traits.Listable | ||
import Com.NoSyn.Ast.Traits.EnvironmentUpdater | ||
import Com.NoSyn.Ast.Traits.Blockable | ||
import Data.List | ||
import Data.Set.SetTheory | ||
import Control.Monad | ||
import Com.NoSyn.Error.CompilerStatus | ||
import Com.NoSyn.Error.SourcePosition | ||
import Com.NoSyn.Error.SourcePositionTraits | ||
import Com.NoSyn.Environment.ProgramEnvironment | ||
import Com.HigherOrderFunctions | ||
|
||
class (EnvironmentUpdater m) => Blockable m where | ||
blockSeparator :: m->String | ||
|
||
data Block a = | ||
StandardBlock [a] | ||
| SequentialBlock [a] | ||
StandardBlock [SourcePosition a] | ||
| SequentialBlock [SourcePosition a] | ||
deriving Show | ||
|
||
instance (EnvironmentUpdater a) => EnvironmentUpdater (Block a) where | ||
updateEnvironment programEnvironment (StandardBlock m) = do | ||
updatedProgramEnvironments <- sequence $ map (updateEnvironment programEnvironment) m | ||
let differenceProgramEnvironments = map (\x -> difference x programEnvironment) updatedProgramEnvironments in | ||
foldM (\x y -> concatenate (Error "Cannot override program environment with new definitions" (show (x, y))) x y) programEnvironment differenceProgramEnvironments | ||
updateEnvironment programEnvironment (SequentialBlock m) = | ||
foldM updateEnvironment programEnvironment m | ||
updateEnvironment programEnvironment spBlock = case getContents spBlock of | ||
StandardBlock m -> do | ||
updatedProgramEnvironments <- sequence $ map (updateEnvironment programEnvironment) m | ||
let differenceProgramEnvironments = map (\x -> difference x programEnvironment) updatedProgramEnvironments in | ||
foldM | ||
(\x y -> concatenate (PositionedError (getSourcePosition spBlock) "Cannot override program environment with new definitions" (show (x, y))) x y) | ||
programEnvironment | ||
differenceProgramEnvironments | ||
SequentialBlock m -> | ||
foldM updateEnvironment programEnvironment m | ||
|
||
instance (EnvironmentUpdater a, TargetCodeGeneratable a, Blockable a) => TargetCodeGeneratable (Block a) where | ||
generateD programEnvironment (StandardBlock a) = do | ||
generatedElements <- sequence $ map (generateD programEnvironment) a | ||
return $ | ||
concat $ | ||
intersperse (blockSeparator (head a)) generatedElements | ||
generateD programEnvironment (SequentialBlock a) = do | ||
generatedElements <- environmentUpdatingMapMonad updateEnvironment generateD programEnvironment a | ||
return $ | ||
concat $ | ||
intersperse (blockSeparator (head a)) generatedElements | ||
generateD programEnvironment spBlock = case getContents spBlock of | ||
StandardBlock a -> do | ||
generatedElements <- sequence $ map (generateD programEnvironment) a | ||
return $ concat $ intersperse (blockSeparator (head a)) generatedElements | ||
SequentialBlock a -> do | ||
generatedElements <- environmentUpdatingMapMonad updateEnvironment generateD programEnvironment $ a | ||
return $ concat $ intersperse (blockSeparator (head a)) generatedElements | ||
|
||
instance Listable Block where | ||
toList (StandardBlock a) = a | ||
toList (SequentialBlock a) = a | ||
toList (StandardBlock a) = getContents $ sequence a | ||
toList (SequentialBlock a) = getContents $ sequence a | ||
|
||
toSourcePositionedList :: Block a -> [SourcePosition a] | ||
toSourcePositionedList (StandardBlock l) = l | ||
toSourcePositionedList (SequentialBlock l) = l | ||
|
||
instance Functor Block where | ||
fmap f (StandardBlock a) = StandardBlock $ map (fmap f) a | ||
fmap f (SequentialBlock a) = SequentialBlock $ map (fmap f) a |
This file contains 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.