Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix let expressions in the repl #1763

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Juvix/Compiler/Internal/Data/InfoTable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,23 @@ instance Monoid InfoTable where
buildTable :: (Foldable f) => f Module -> InfoTable
buildTable = mconcatMap buildTable1

buildTableRepl :: (Foldable f) => Expression -> f Module -> InfoTable
buildTableRepl e = extendWithReplExpression e . buildTable

buildTable1 :: Module -> InfoTable
buildTable1 = run . evalState (mempty :: Cache) . buildTable1'

buildTable' :: (Members '[State Cache] r, Foldable f) => f Module -> Sem r InfoTable
buildTable' = mconcatMap buildTable1'

extendWithReplExpression :: Expression -> InfoTable -> InfoTable
extendWithReplExpression e =
over
infoFunctions
( HashMap.union
(HashMap.fromList [(f ^. funDefName, FunctionInfo f) | LetFunDef f <- universeBi e])
)

-- | moduleName ↦ infoTable
type Cache = HashMap Name InfoTable

Expand Down
6 changes: 3 additions & 3 deletions src/Juvix/Compiler/Internal/Translation/FromInternal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ arityCheckExpression InternalResult {..} exp =
runReader table (ArityChecking.inferReplExpression exp)
where
table :: InfoTable
table = buildTable _resultModules
table = buildTableRepl exp _resultModules

typeCheckExpressionType ::
(Members '[Error JuvixError, NameIdGen, Builtins] r) =>
InternalTypedResult ->
Expression ->
Sem r TypedExpression
typeCheckExpressionType (InternalTypedResult {..}) exp =
typeCheckExpressionType InternalTypedResult {..} exp =
mapError (JuvixError @TypeCheckerError)
$ do
runReader _resultFunctions
Expand All @@ -64,7 +64,7 @@ typeCheckExpressionType (InternalTypedResult {..}) exp =
$ inferExpression' Nothing exp
where
table :: InfoTable
table = buildTable _resultModules
table = buildTableRepl exp _resultModules

typeCheckExpression ::
(Members '[Error JuvixError, NameIdGen, Builtins] r) =>
Expand Down
10 changes: 10 additions & 0 deletions tests/smoke/Commands/repl.smoke.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ tests:
Nat
exit-status: 0

- name: eval-let-expression
command:
- juvix
- repl
stdin: "let {x : Nat; x := 2 + 1} in x"
stdout:
contains:
"suc (suc (suc zero))"
exit-status: 0

- name: load-builtin-bool
command:
shell:
Expand Down