git.haldean.org del / 93f5328
just need to find the source file now Haldean Brown 2 years ago
5 changed file(s) with 34 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
3030 , Language.Del.Imports
3131 , Language.Del.InRep
3232 , Language.Del.Inlining
33 , Language.Del.Load
3334 , Language.Del.Ops
3435 , Language.Del.Properties
3536 , Language.Del.Reader
0 (import http://git.haldean.org/del/raw/master/examples/sphere.del s)
0 (import sphere.del s)
1
2 (* (import http://git.haldean.org/del/raw/master/examples/sphere.del s) *)
13
24 (define root:color (v:f3)
35 (if (< (s.sphere 1.0 v) 0.001)
33
44 import Debug.Trace
55 import qualified Data.Map.Strict as Map
6 import Data.Maybe
76 import qualified Data.Text as T
87 import Language.Del.AST
98 import Language.Del.CompileDefs
1211 import Language.Del.Imports
1312 import Language.Del.InRep
1413 import Language.Del.Inlining
14 import Language.Del.Load
1515 import Language.Del.Ops
1616 import Language.Del.Properties
1717 import qualified Language.Del.Reader as R
1818 import Language.Del.TypeCheck
1919 import Language.Del.Types
20
21 buildAST :: [R.Form] -> AST
22 buildAST fs = AST defs imps
23 where namePair (R.DefForm n t a b) = Just (n, Def n t a b)
24 namePair _ = Nothing
25 defs = Map.fromList $ mapMaybe namePair fs
26 importFromForm (R.ImportForm s a) = Just $ Import s a
27 importFromForm _ = Nothing
28 imps = mapMaybe importFromForm fs
2920
3021 -- Drops all definitions other than the root definition
3122 dropNonRoot :: AST -> Artifact Def
00 module Language.Del.Imports where
11
2 import qualified Data.Map.Strict as Map
3 import qualified Data.Text as T
24 import Language.Del.AST
35 import Language.Del.CompileDefs
4 import qualified Data.Text as T
5 import qualified Data.Map.Strict as Map
6 import Language.Del.Load
7 import qualified Language.Del.Reader as R
68
79 mergeBinds :: T.Text -> Map.Map T.Text Def -> Map.Map T.Text Def -> Artifact (Map.Map T.Text Def)
810 mergeBinds alias orig new =
1416 then Failure $ ImportNameClash alias (Map.keys overlap)
1517 else return $ Map.union orig aliased
1618
19 findSourceFile :: T.Text -> IO FilePath
20 findSourceFile = undefined
1721
1822 loadImport :: Source -> IO (Artifact AST)
19 loadImport = undefined
23 loadImport (Right _) = error "URL imports not yet supported"
24 loadImport (Left name) = do
25 path <- findSourceFile name
26 contents <- readFile path >>= return . T.pack
27 let forms = R.read contents
28 case forms of
29 Success f -> return $ Success (buildAST f)
30 Failure e -> return $ Failure e
2031
2132 collectImports :: [Source] -> AST -> IO (Artifact AST)
2233 collectImports loaded (AST m ((Import src alias):xs)) =
0 module Language.Del.Load where
1
2 import qualified Data.Map.Strict as Map
3 import Data.Maybe
4 import Language.Del.AST
5 import qualified Language.Del.Reader as R
6
7 buildAST :: [R.Form] -> AST
8 buildAST fs = AST defs imps
9 where namePair (R.DefForm n t a b) = Just (n, Def n t a b)
10 namePair _ = Nothing
11 defs = Map.fromList $ mapMaybe namePair fs
12 importFromForm (R.ImportForm s a) = Just $ Import s a
13 importFromForm _ = Nothing
14 imps = mapMaybe importFromForm fs