-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
built bundler & added bundle flow to the parser and compiler
- Loading branch information
Showing
5 changed files
with
110 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
module Bundler (bundleModules) where | ||
import qualified Data.Foldable as F | ||
import qualified Data.Set as S | ||
import Gibbon.L0.Syntax as L0 | ||
import Gibbon.Common | ||
import Data.Map as M | ||
import Data.List as L | ||
import Language.Haskell.Exts (ImportDecl) | ||
|
||
|
||
|
||
-- main bundler, takes a list of modules and the main module | ||
bundleModules :: ProgBundle0 a -> PassM Prog0 | ||
bundleModules bundle = do | ||
let (ProgBundle modules main) = bundle | ||
let (ProgModule main_name (Prog main_defs main_funs main_exp) main_imports) = main | ||
let (defs, funs) = F.foldr _bundleModule (main_defs, main_funs) modules | ||
return $ Prog defs funs main_exp | ||
|
||
-- main bundle fold | ||
-- builds the full program by folding definitons and functions into the main | ||
_bundleModule :: ProgModule0 a -> (DDefs0, FunDefs0) -> (DDefs0, FunDefs0) | ||
_bundleModule (ProgModule mod_name (Prog {ddefs, fundefs}) _) (defs1, funs1) = | ||
-- conflict checking,,, extract definition and function names | ||
let ddef_names1 = M.keysSet defs1 | ||
ddef_names2 = M.keysSet ddefs | ||
fn_names1 = M.keysSet funs1 | ||
fn_names2 = M.keysSet fundefs | ||
em1 = S.intersection ddef_names1 ddef_names2 | ||
em2 = S.intersection fn_names1 fn_names2 | ||
conflicts1 = F.foldr (\d acc -> | ||
if (ddefs M.! d) /= (defs1 M.! d) | ||
then d : acc | ||
else acc) | ||
[] em1 | ||
conflicts2 = F.foldr (\f acc -> | ||
if (fundefs M.! f) /= (funs1 M.! f) | ||
then dbgTraceIt | ||
(sdoc ((fundefs M.! f), (funs1 M.! f))) | ||
(f : acc) | ||
else acc) | ||
[] em2 | ||
in case (conflicts1, conflicts2) of | ||
([], []) -> | ||
(M.union ddefs defs1, M.union fundefs funs1) | ||
(_x:_xs, _) -> | ||
error $ | ||
"Conflicting definitions of " ++ | ||
show conflicts1 ++ " found in " ++ mod_name | ||
(_, _x:_xs) -> | ||
error $ | ||
"Conflicting definitions of " ++ | ||
show (S.toList em2) ++ " found in " ++ mod_name |
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
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