diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Eval.hs | 18 | ||||
-rw-r--r-- | src/Helper.hs | 2 | ||||
-rw-r--r-- | src/Parser.hs | 14 |
3 files changed, 33 insertions, 1 deletions
diff --git a/src/Eval.hs b/src/Eval.hs index 5ef743c..0478c02 100644 --- a/src/Eval.hs +++ b/src/Eval.hs @@ -266,6 +266,24 @@ evalCommand inp s@(EnvState env@(Environment envDefs) conf cache) = \case putStrLn " Byte" performGC pure $ EnvState (Environment M.empty) conf (EnvCache M.empty) + Length e -> do + let (res, _) = evalExp e (Environment M.empty) `runState` env + case res of + Left err -> print err + Right e' -> do + red <- reduce e' + print $ length $ toBinary e' + print $ length $ toBinary red + pure s + Blc e -> do + let (res, _) = evalExp e (Environment M.empty) `runState` env + case res of + Left err -> print err + Right e' -> do + red <- reduce e' + putStrLn $ toBinary e' + putStrLn $ toBinary red + pure s Time e -> do start <- getTime Monotonic let (res, _) = evalExp e (Environment M.empty) `runState` env diff --git a/src/Helper.hs b/src/Helper.hs index bfeeb66..2b2e31c 100644 --- a/src/Helper.hs +++ b/src/Helper.hs @@ -147,7 +147,7 @@ instance Show Expression where . foldr1 (\x y -> x . showString " " . y) (map shows ms) . showString "\ESC[33m)\ESC[0m" showsPrec _ (Prefix p e) = shows p . showString " " . shows e -data Command = Input String | Watch String | Import String String | Test Expression Expression | ClearState | Time Expression +data Command = Input String | Watch String | Import String String | Test Expression Expression | ClearState | Time Expression | Length Expression | Blc Expression deriving (Show) data Instruction = Define Identifier Expression [Instruction] | Evaluate Expression | Comment | Commands [Command] | ContextualInstruction Instruction String deriving (Show) diff --git a/src/Parser.hs b/src/Parser.hs index d796682..392d4a6 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -269,6 +269,18 @@ parseTime = do e <- parseExpression pure $ Time e +parseLength :: Parser Command +parseLength = do + _ <- string ":length" <* sc <?> "length instruction" + e <- parseExpression + pure $ Length e + +parseBlc :: Parser Command +parseBlc = do + _ <- string ":blc" <* sc <?> "blc instruction" + e <- parseExpression + pure $ Blc e + parseClearState :: Parser Command parseClearState = do _ <- string ":free" <?> "free instruction" @@ -334,5 +346,7 @@ parseReplLine = <|> (Commands . (: []) <$> try parseWatch) <|> (Commands . (: []) <$> try parseImport) <|> (Commands . (: []) <$> try parseTime) + <|> (Commands . (: []) <$> try parseLength) + <|> (Commands . (: []) <$> try parseBlc) <|> (Commands . (: []) <$> try parseClearState) <|> try parseEvaluate |