Skip to content

Commit

Permalink
Remove profile effect
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Mar 18, 2024
1 parent c56f1e4 commit 90a0ce4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 45 deletions.
12 changes: 1 addition & 11 deletions app/Commands/Dev/Nockma/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module Commands.Dev.Nockma.Eval where

import Commands.Base hiding (Atom)
import Commands.Dev.Nockma.Eval.Options
import Juvix.Compiler.Nockma.EvalCompiled
import Juvix.Compiler.Nockma.Evaluator
import Juvix.Compiler.Nockma.Pretty
import Juvix.Compiler.Nockma.Translation.FromSource qualified as Nockma

Expand All @@ -13,15 +11,7 @@ runCommand opts = do
parsedTerm <- Nockma.parseTermFile afile
case parsedTerm of
Left err -> exitJuvixError (JuvixError err)
Right (TermCell c) -> do
(counts, res) <-
runOpCounts
. runReader defaultEvalOptions
. runOutputSem @(Term Natural) (say . ppTrace)
$ evalCompiledNock' (c ^. cellLeft) (c ^. cellRight)
putStrLn (ppPrint res)
let statsFile = replaceExtension' ".profile" afile
writeFileEnsureLn statsFile (prettyText counts)
Right (TermCell c) -> impossible
Right TermAtom {} -> exitFailMsg "Expected nockma input to be a cell"
where
file :: AppPath File
Expand Down
7 changes: 2 additions & 5 deletions app/Commands/Dev/Nockma/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ runCommand opts = do
case parsedTerm of
t@(TermCell {}) -> do
let formula = anomaCallTuple parsedEnvTerm parsedArgs
(counts, res) <-
runOpCounts
. runReader defaultEvalOptions
res <-
runReader defaultEvalOptions
. runOutputSem @(Term Natural) (say . ppTrace)
$ evalCompiledNock' t formula
putStrLn (ppPrint res)
let statsFile = replaceExtension' ".profile" afile
writeFileEnsureLn statsFile (prettyText counts)
TermAtom {} -> exitFailMsg "Expected nockma input to be a cell"
where
inputFile :: AppPath File
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Nockma/EvalCompiled.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Juvix.Compiler.Nockma.Language
import Juvix.Compiler.Nockma.Pretty (ppTrace)
import Juvix.Prelude

evalCompiledNock' :: (Members '[State OpCounts, Reader EvalOptions, Output (Term Natural)] r) => Term Natural -> Term Natural -> Sem r (Term Natural)
evalCompiledNock' :: (Members '[Reader EvalOptions, Output (Term Natural)] r) => Term Natural -> Term Natural -> Sem r (Term Natural)
evalCompiledNock' stack mainTerm = do
evalT <-
runError @(ErrNockNatural Natural)
Expand Down
52 changes: 26 additions & 26 deletions src/Juvix/Compiler/Nockma/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ import Juvix.Compiler.Nockma.Language
import Juvix.Prelude hiding (Atom, Path)
import Juvix.Prelude.Pretty

newtype OpCounts = OpCounts
{ _opCountsMap :: HashMap NockOp Int
}
-- newtype OpCounts = OpCounts
-- { _opCountsMap :: HashMap NockOp Int
-- }

makeLenses ''OpCounts
-- makeLenses ''OpCounts

initOpCounts :: OpCounts
initOpCounts = OpCounts mempty
-- initOpCounts :: OpCounts
-- initOpCounts = OpCounts mempty

ignoreOpCounts :: Sem (State OpCounts ': r) a -> Sem r a
ignoreOpCounts = evalState initOpCounts
-- ignoreOpCounts :: Sem (State OpCounts ': r) a -> Sem r a
-- ignoreOpCounts = evalState initOpCounts

countOp :: (Members '[State OpCounts] r) => NockOp -> Sem r ()
countOp op =
modify
( over
(opCountsMap . at op)
( \case
Nothing -> Just 1
Just n -> Just (n + 1)
)
)
-- countOp :: (Members '[State OpCounts] r) => NockOp -> Sem r ()
-- countOp op =
-- modify
-- ( over
-- (opCountsMap . at op)
-- ( \case
-- Nothing -> Just 1
-- Just n -> Just (n + 1)
-- )
-- )

runOpCounts :: Sem (State OpCounts ': r) a -> Sem r (OpCounts, a)
runOpCounts = runState initOpCounts
-- runOpCounts :: Sem (State OpCounts ': r) a -> Sem r (OpCounts, a)
-- runOpCounts = runState initOpCounts

instance Pretty OpCounts where
pretty :: OpCounts -> Doc a
pretty (OpCounts m) = vsepHard [pretty op <+> ":" <+> pretty (fromMaybe 0 (m ^. at op)) | op <- allElements]
-- instance Pretty OpCounts where
-- pretty :: OpCounts -> Doc a
-- pretty (OpCounts m) = vsepHard [pretty op <+> ":" <+> pretty (fromMaybe 0 (m ^. at op)) | op <- allElements]

asAtom :: (Members '[Reader EvalCtx, Error (NockEvalError a)] r) => Term a -> Sem r (Atom a)
asAtom = \case
Expand Down Expand Up @@ -163,11 +163,11 @@ eval ::
Term a ->
Term a ->
Sem s (Term a)
eval initstack initterm = ignoreOpCounts (evalProfile initstack initterm)
eval initstack initterm = evalProfile initstack initterm

evalProfile ::
forall s a.
(Integral a, Members '[State OpCounts, Reader EvalOptions, Output (Term a), Error (NockEvalError a), Error (ErrNockNatural a)] s, NockNatural a) =>
(Integral a, Members '[Reader EvalOptions, Output (Term a), Error (NockEvalError a), Error (ErrNockNatural a)] s, NockNatural a) =>
Term a ->
Term a ->
Sem s (Term a)
Expand Down Expand Up @@ -240,7 +240,7 @@ evalProfile inistack initerm =

goOperatorCell :: OperatorCell a -> Sem r (Term a)
goOperatorCell c = do
countOp (c ^. operatorCellOp)
-- countOp (c ^. operatorCellOp)
case c ^. operatorCellOp of
OpAddress -> goOpAddress
OpQuote -> return goOpQuote
Expand Down
2 changes: 1 addition & 1 deletion test/Anoma/Compilation/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ allTests =
"Test017: Tail recursion through higher-order functions"
$(mkRelDir ".")
$(mkRelFile "test017.juvix")
[nockNatLiteral 1000]
[nockNatLiteral 100]
$ checkNatOutput [500500],
mkAnomaCallTest
"Test018: Higher-order functions and recursion"
Expand Down
1 change: 0 additions & 1 deletion test/Nockma/Compile/Tree/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ runNockmaAssertion hout _main tab = do
. runOutputSem @(Term Natural)
(embed . hPutStrLn hout . Nockma.ppTest)
. runReader NockmaEval.defaultEvalOptions
. NockmaEval.ignoreOpCounts
$ evalCompiledNock' (anomaRes ^. anomaClosure) (anomaCall (anomaRes ^. anomaEnv) [])
let ret = getReturn res
whenJust ret (hPutStrLn hout . Nockma.ppTest)
Expand Down

0 comments on commit 90a0ce4

Please sign in to comment.