Skip to content

Commit

Permalink
Add lines/s flag
Browse files Browse the repository at this point in the history
  • Loading branch information
augustss committed Jan 1, 2025
1 parent ce1c21c commit f88a408
Show file tree
Hide file tree
Showing 9 changed files with 5,158 additions and 5,132 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ bin/umhs: bin/mhs

#
timecompile: bin/mhs
time bin/mhs +RTS -v -RTS $(MHSINC) MicroHs.Main
time bin/mhs +RTS -v -RTS -s $(MHSINC) MicroHs.Main

#
timecachecompile: bin/mhs
@-rm -f .mhscache
time bin/mhs +RTS -v -RTS -CW AllOfLib
time bin/mhs +RTS -v -RTS -CR $(MHSINC) MicroHs.Main
time bin/mhs +RTS -v -RTS -CR -s $(MHSINC) MicroHs.Main

#
cachelib:
Expand Down Expand Up @@ -213,8 +213,8 @@ nfibtest: bin/mhs bin/mhseval

######

VERSION=0.11.1.1
HVERSION=0,11,1,1
VERSION=0.11.1.2
HVERSION=0,11,1,2
MCABAL=$(HOME)/.mcabal
MCABALMHS=$(MCABAL)/mhs-$(VERSION)
MDATA=$(MCABALMHS)/packages/mhs-$(VERSION)/data
Expand Down
2 changes: 1 addition & 1 deletion MicroHs.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: MicroHs
version: 0.11.1.1
version: 0.11.1.2
-- *** When changing the version number, also
-- *** run 'sh updateversion.sh'
-- *** Yeah, it stinks.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ it will be the entry point to the program.
* `-T` generate dynamic function usage statistics
* `-z` compress combinator code generated in the `.c` file
* `-l` show every time a module is loaded
* `-s` show compilation speed in lines/s
* `-XCPP` run `cpphs` on source files
* `-Dxxx` passed to `cpphs`
* `-Ixxx` passed to `cpphs`
Expand Down
10,259 changes: 5,136 additions & 5,123 deletions generated/mhs.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/libs.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: libs
version: 0.11.1.1
version: 0.11.1.2
license: Apache
license-file: LICENSE
maintainer: lennart@augustsson.net
Expand Down
2 changes: 1 addition & 1 deletion paths/Paths_MicroHs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ getDataDir :: IO FilePath
getDataDir = return "."

version :: Version
version = makeVersion [0,11,1,1]
version = makeVersion [0,11,1,2]
2 changes: 2 additions & 0 deletions src/MicroHs/Flags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data Flags = Flags {
paths :: [FilePath], -- module search path
output :: String, -- output file
loading :: Bool, -- show loading message
speed :: Bool, -- show lines/s
readCache :: Bool, -- read and use cache
writeCache :: Bool, -- generate cache
useTicks :: Bool, -- emit ticks
Expand All @@ -34,6 +35,7 @@ defaultFlags dir = Flags {
paths = [".", dir ++ "/lib"],
output = "out.comb",
loading = False,
speed = False,
readCache = False,
writeCache = False,
useTicks = False,
Expand Down
5 changes: 4 additions & 1 deletion src/MicroHs/Ident.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module MicroHs.Ident(
qualOf,
addIdentSuffix,
SLoc(..), noSLoc,
showSLoc,
showSLoc, slocFile,
) where
import Prelude(); import MHSPrelude hiding(head)
import Data.Char
Expand Down Expand Up @@ -179,3 +179,6 @@ showSLoc (SLoc fn l c) =
if l == 0 then "no location" else
if l == -1 then "end-of-file" else
"line " ++ show l ++ ", col " ++ show c

slocFile :: SLoc -> FilePath
slocFile (SLoc f _ _) = f
9 changes: 8 additions & 1 deletion src/MicroHs/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ main = do
_ -> error usage

usage :: String
usage = "Usage: mhs [--version] [--numeric-version] [-v] [-q] [-l] [-r] [-C[R|W]] [-XCPP] [-DDEF] [-IPATH] [-T] [-z] [-iPATH] [-oFILE] [-a[PATH]] [-L[PATH|PKG]] [-PPKG] [-Q PKG [DIR]] [-tTARGET] [-optc OPTION] [MODULENAME..|FILE]"
usage = "Usage: mhs [--version] [--numeric-version] [-v] [-q] [-l] [-s] [-r] [-C[R|W]] [-XCPP] [-DDEF] [-IPATH] [-T] [-z] [-iPATH] [-oFILE] [-a[PATH]] [-L[PATH|PKG]] [-PPKG] [-Q PKG [DIR]] [-tTARGET] [-optc OPTION] [MODULENAME..|FILE]"

decodeArgs :: Flags -> [String] -> [String] -> (Flags, [String], [String])
decodeArgs f mdls [] = (f, mdls, [])
Expand All @@ -75,6 +75,7 @@ decodeArgs f mdls (arg:args) =
"-q" -> decodeArgs f{verbose = -1} mdls args
"-r" -> decodeArgs f{runIt = True} mdls args
"-l" -> decodeArgs f{loading = True} mdls args
"-s" -> decodeArgs f{speed = True} mdls args
"-CR" -> decodeArgs f{readCache = True} mdls args
"-CW" -> decodeArgs f{writeCache = True} mdls args
"-C" -> decodeArgs f{readCache=True, writeCache = True} mdls args
Expand Down Expand Up @@ -207,6 +208,7 @@ mainListPkg' _flags pkgfn = do

mainCompile :: Flags -> Ident -> IO ()
mainCompile flags mn = do
t0 <- getTimeMilli
(cash, (rmn, allDefs)) <- do
cash <- getCached flags
(rds, _, cash') <- compileCacheTop flags mn cash
Expand Down Expand Up @@ -236,6 +238,11 @@ mainCompile flags mn = do
when (verbosityGT flags 0) $
putStrLn $ "final pass " ++ padLeft 6 (show (t2-t1)) ++ "ms"

when (speed flags) $ do
let fns = filter (isSuffixOf ".hs") $ map (slocFile . slocIdent) $ cachedModuleNames cash
locs <- sum . map (length . lines) <$> mapM readFile fns
putStrLn $ show (locs * 1000 `div` (t2 - t0)) ++ " lines/s"

let cCode = makeCArray flags outData ++ makeFFI flags allDefs

-- Decode what to do:
Expand Down

0 comments on commit f88a408

Please sign in to comment.