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

Add do notation #2937

Merged
merged 7 commits into from
Aug 21, 2024
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
2 changes: 2 additions & 0 deletions src/Juvix/Compiler/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Juvix.Compiler.Builtins
module Juvix.Compiler.Builtins.Cairo,
module Juvix.Compiler.Builtins.Byte,
module Juvix.Compiler.Builtins.ByteArray,
module Juvix.Compiler.Builtins.Monad,
)
where

Expand All @@ -28,5 +29,6 @@ import Juvix.Compiler.Builtins.IO
import Juvix.Compiler.Builtins.Int
import Juvix.Compiler.Builtins.List
import Juvix.Compiler.Builtins.Maybe
import Juvix.Compiler.Builtins.Monad
import Juvix.Compiler.Builtins.Nat
import Juvix.Compiler.Builtins.String
7 changes: 7 additions & 0 deletions src/Juvix/Compiler/Builtins/Monad.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Juvix.Compiler.Builtins.Monad where

import Juvix.Compiler.Internal.Extra
import Juvix.Prelude

checkMonadBind :: forall r. FunctionDef -> Sem r ()
checkMonadBind _ = return ()
117 changes: 113 additions & 4 deletions src/Juvix/Compiler/Concrete/Data/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ data BuiltinFunction
| BuiltinFromNat
| BuiltinFromInt
| BuiltinSeq
| BuiltinMonadBind
deriving stock (Show, Eq, Ord, Enum, Bounded, Generic, Data)

instance Hashable BuiltinFunction
Expand Down Expand Up @@ -189,6 +190,7 @@ instance Pretty BuiltinFunction where
BuiltinFromNat -> Str.fromNat
BuiltinFromInt -> Str.fromInt
BuiltinSeq -> Str.builtinSeq
BuiltinMonadBind -> Str.builtinMonadBind

data BuiltinAxiom
= BuiltinNatPrint
Expand Down Expand Up @@ -365,7 +367,26 @@ isNatBuiltin = \case
BuiltinNatLe -> True
BuiltinNatLt -> True
BuiltinNatEq -> True
_ -> False
--
BuiltinBoolIf -> False
BuiltinBoolOr -> False
BuiltinBoolAnd -> False
BuiltinIntEq -> False
BuiltinIntPlus -> False
BuiltinIntSubNat -> False
BuiltinIntNegNat -> False
BuiltinIntNeg -> False
BuiltinIntMul -> False
BuiltinIntDiv -> False
BuiltinIntMod -> False
BuiltinIntSub -> False
BuiltinIntNonNeg -> False
BuiltinIntLe -> False
BuiltinIntLt -> False
BuiltinFromNat -> False
BuiltinFromInt -> False
BuiltinSeq -> False
BuiltinMonadBind -> False

isIntBuiltin :: BuiltinFunction -> Bool
isIntBuiltin = \case
Expand All @@ -381,13 +402,101 @@ isIntBuiltin = \case
BuiltinIntNonNeg -> True
BuiltinIntLe -> True
BuiltinIntLt -> True
_ -> False
--
BuiltinNatPlus -> False
BuiltinNatSub -> False
BuiltinNatMul -> False
BuiltinNatUDiv -> False
BuiltinNatDiv -> False
BuiltinNatMod -> False
BuiltinNatLe -> False
BuiltinNatLt -> False
BuiltinNatEq -> False
BuiltinBoolIf -> False
BuiltinBoolOr -> False
BuiltinBoolAnd -> False
BuiltinFromNat -> False
BuiltinFromInt -> False
BuiltinSeq -> False
BuiltinMonadBind -> False

isCastBuiltin :: BuiltinFunction -> Bool
isCastBuiltin = \case
BuiltinFromNat -> True
BuiltinFromInt -> True
_ -> False
--
BuiltinIntEq -> False
BuiltinIntPlus -> False
BuiltinIntSubNat -> False
BuiltinIntNegNat -> False
BuiltinIntNeg -> False
BuiltinIntMul -> False
BuiltinIntDiv -> False
BuiltinIntMod -> False
BuiltinIntSub -> False
BuiltinIntNonNeg -> False
BuiltinIntLe -> False
BuiltinIntLt -> False
BuiltinNatPlus -> False
BuiltinNatSub -> False
BuiltinNatMul -> False
BuiltinNatUDiv -> False
BuiltinNatDiv -> False
BuiltinNatMod -> False
BuiltinNatLe -> False
BuiltinNatLt -> False
BuiltinNatEq -> False
BuiltinBoolIf -> False
BuiltinBoolOr -> False
BuiltinBoolAnd -> False
BuiltinSeq -> False
BuiltinMonadBind -> False

isIgnoredBuiltin :: BuiltinFunction -> Bool
isIgnoredBuiltin f = not (isNatBuiltin f) && not (isIntBuiltin f) && not (isCastBuiltin f)
isIgnoredBuiltin f
| spec == explicit = spec
| otherwise = impossible
where
spec :: Bool
spec =
(not . isNatBuiltin)
.&&. (not . isIntBuiltin)
.&&. (not . isCastBuiltin)
.&&. (/= BuiltinMonadBind)
$ f

explicit :: Bool
explicit = case f of
-- Cast
BuiltinFromNat -> False
BuiltinFromInt -> False
-- Int
BuiltinIntEq -> False
BuiltinIntPlus -> False
BuiltinIntSubNat -> False
BuiltinIntNegNat -> False
BuiltinIntNeg -> False
BuiltinIntMul -> False
BuiltinIntDiv -> False
BuiltinIntMod -> False
BuiltinIntSub -> False
BuiltinIntNonNeg -> False
BuiltinIntLe -> False
BuiltinIntLt -> False
-- Nat
BuiltinNatPlus -> False
BuiltinNatSub -> False
BuiltinNatMul -> False
BuiltinNatUDiv -> False
BuiltinNatDiv -> False
BuiltinNatMod -> False
BuiltinNatLe -> False
BuiltinNatLt -> False
BuiltinNatEq -> False
-- Monad
BuiltinMonadBind -> False
-- Ignored
BuiltinBoolIf -> True
BuiltinBoolOr -> True
BuiltinBoolAnd -> True
BuiltinSeq -> True
4 changes: 4 additions & 0 deletions src/Juvix/Compiler/Concrete/Keywords.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Juvix.Data.Keyword.All
kwCase,
kwCoercion,
kwColon,
kwDo,
kwElse,
kwEnd,
kwEq,
Expand All @@ -51,6 +52,7 @@ import Juvix.Data.Keyword.All
kwIterator,
kwLambda,
kwLeft,
kwLeftArrow,
kwLet,
kwMapsTo,
kwModule,
Expand Down Expand Up @@ -88,6 +90,7 @@ reservedKeywords =
kwAxiom,
kwCase,
kwColon,
kwDo,
kwElse,
kwEnd,
kwHiding,
Expand All @@ -97,6 +100,7 @@ reservedKeywords =
kwIn,
kwInductive,
kwLambda,
kwLeftArrow,
kwLet,
kwModule,
kwOf,
Expand Down
Loading
Loading