Skip to content

Commit 4d02d04

Browse files
committed
add evalT
1 parent e60220c commit 4d02d04

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
repos:
3+
- repo: local
4+
hooks:
5+
- id: hlint
6+
name: HLint
7+
# entry: stack exec hlint
8+
entry: hlint
9+
language: system
10+
files: ^(src/|app/|test/).+\.hs$
11+
pass_filenames: true
12+
13+
- id: stack-test
14+
name: Stack Tests
15+
entry: stack test
16+
language: system
17+
pass_filenames: false

README.org

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#+author: Felix Drees
33
#+STARTUP: latexpreview
44
#+OPTIONS: toc:nil tex:t # tex:verbatim num:nil
5-
#+keywords: while programs, turing complete, turing machines
5+
#+keywords: while
66

77
* while
88

@@ -132,7 +132,7 @@ stack run
132132
#+RESULTS:
133133
:
134134
: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
135-
: [Error]: Usage: stack run <filename>
135+
: [Error]: Usage: stack run <filename>
136136
: Use 'stack run <filename>' to interpret a while source file.
137137
: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
138138
:
@@ -146,17 +146,33 @@ stack run ./examples/multiplication-func.while
146146

147147
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
148148

149-
[Interpreting file] ./examples/multiplication-func.while
150-
[READING .WHILE FILE] "./examples/multiplication-func.while"
151-
[DONE TOKENIZE]
152-
[DONE PARSING AST]
153-
[RESULT OF EVALUATION]
149+
[Interpreting file] ./examples/multiplication-func.while
150+
[READING .WHILE FILE] "./examples/multiplication-func.while"
151+
[DONE TOKENIZE]
152+
[DONE PARSING AST]
153+
[RESULT OF EVALUATION]
154154
[("temp",28980),("b",0),("a",420),("rv",28980)]
155155

156156
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
157157

158158
#+end_example
159159

160+
or use
161+
162+
#+begin_src shell
163+
stack ghci
164+
165+
ghci> xs <- readFileContent "./examples/multiplication-func.while"
166+
[READING .WHILE FILE] "./examples/multiplication-func.while"
167+
ghci> eval ((runASTParser . tokenize) xs) []
168+
[("temp",28980),("b",0),("a",420),("rv",28980)]
169+
ghci> evalT ((runASTParser . tokenize) xs) []
170+
((),[("temp",28980),("b",0),("a",420),("rv",28980)])
171+
ghci>
172+
#+end_src
173+
174+
175+
160176

161177
*** compile
162178

@@ -186,6 +202,14 @@ stack exec hlint src/*.hs app/*.hs test/*.hs
186202
#+end_src
187203

188204

205+
*** pre commit
206+
207+
#+begin_src shell
208+
pre-commit run --all-files
209+
#+end_src
210+
211+
212+
189213
** requirements
190214

191215
*** using `apt`

app/Main.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Main (main) where
66
import System.Environment (getArgs)
77

88
import WhileParser (tokenize, readFileContent, runASTParser) -- WhileAST(..),
9-
import WhileEvaluation (eval) --, evalM, VarName, VarVal, VarState, VarStateWorld)
9+
import WhileEvaluation (eval, evalT, evalM) --, evalM, VarName, VarVal, VarState, VarStateWorld)
1010

1111

1212
-- | Define a data type to represent the command-line options
@@ -40,6 +40,8 @@ runInterpreter options = do
4040
let a = eval ast []
4141
print a
4242

43+
print $ evalT ast []
44+
4345
putStrLn $ "\n" ++ concat (replicate 40 "= ") ++ "=\n"
4446

4547

shell.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ pkgs.mkShell {
77
stack
88
ghc
99
hlint
10+
11+
#(python313.withPackages(ps: with ps; [
12+
# pre-commit
13+
# pre-commit-hooks
14+
#]))
15+
16+
pre-commit
1017
];
1118

1219
shellHook = ''
20+
# python -m pre-commit --version
21+
# pre-commit --version
1322
echo "Start developing..."
1423
'';
1524
}

src/WhileEvaluation.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
module WhileEvaluation
88
(evalM
9+
,evalT
910
,eval
1011
,VarName
1112
,VarVal

0 commit comments

Comments
 (0)