Skip to content

Commit

Permalink
Various minor performance optimizations.
Browse files Browse the repository at this point in the history
  • Loading branch information
bendmorris committed Jan 9, 2011
1 parent cd50950 commit 407f6c6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
7 changes: 3 additions & 4 deletions Bindings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ newBindingHash [] hash = hash
newBindingHash (h:t) hash = addBinding (h) (newBindingHash t hash)
-- adds a Binding to a VarDict, removing bindings that are now irrelevant
addBinding :: Binding -> VarDict -> VarDict
addBinding binding vars = [if n == hash
then binding : (removeBindingFrom binding (vars !! n))
else vars !! n
| n <- [0 .. (hashSize - 1)]]
addBinding binding vars = [vars !! n | n <- [0 .. (hash - 1)]]
++ [binding : (removeBindingFrom binding (vars !! hash))] ++
[vars !! n | n <- [(hash + 1) .. (hashSize - 1)]]
where hash = varHash (fst binding)

samePattern [] [] = True
Expand Down
2 changes: 1 addition & 1 deletion Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ iolist (h:t) = do item <- h
ieval :: Expr -> VarDict -> IO Expr
ieval expr vars =
do subbed <- subfile expr vars
result <- subfile (eval subbed vars) vars
let result = eval subbed vars
case result of
Val v -> return result
Exception e -> return result
Expand Down
6 changes: 2 additions & 4 deletions ReadFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ wexecute verbose (h:t) bindings =
wexecute verbose t bindings
otherwise -> do new <- newBindings
wexecute verbose t (addBindings new bindings)
where -- scope is determined by amount of leading whitespace
name = case position of
where name = case position of
Just p -> sourceName p
Nothing -> ""
line = case position of
Expand All @@ -79,7 +78,6 @@ wexecute verbose (h:t) bindings =
column = case position of
Just p -> sourceColumn p
Nothing -> 1
-- parse the code
showPosition = name ++ ": Line " ++ show line ++ ", column " ++ show column
position = fst h

Expand Down Expand Up @@ -126,7 +124,7 @@ importFile verbose s =
then ([], Val (HFunc (Name (qualifier ++ n))))
else snd binding
otherwise -> otherwise) | binding <- val],
--(length (name newbinding) > 0 && (name newbinding) !! 0 /= '_') &&
(name newbinding) !! 0 /= '_' &&
(s == ["std", "lib"] ||
not (isInfixOf "std.lib." (name newbinding)))]
where qualifier = (foldl (++) [] [i ++ "." | i <- s, i /= "main" ])
Expand Down
2 changes: 1 addition & 1 deletion build_deb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mkdir usr
cd usr
mkdir bin
cd ../..
ghc --make scotch
ghc --make scotch -O2
cp scotch deb/usr/bin
cp scotch.lib deb/usr/bin -r
rm deb/usr/bin/scotch.lib/.svn -rf
Expand Down
8 changes: 4 additions & 4 deletions scotch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ loop verbose bindings state =
otherwise -> do return (Exception "Parse error - multiple expressions entered in interpreter")
imp' <- case parsed of
Import s -> importFile verbose s
otherwise -> do return (False, [[],[]])
otherwise -> do return (False, [])
imp <- case imp' of
(False, []) -> do -- the imported module failed to open
(False, []) -> do -- there was no attempted import
return emptyHash
(False, f) -> do -- the imported module failed to open
putStrLn ("Failed to open " ++ show (parsed))
return emptyHash
(False, f) -> do -- there was no attempted import
return emptyHash
(True, b) -> do -- successful module import
return b
-- evaluate parsed input
Expand Down

0 comments on commit 407f6c6

Please sign in to comment.