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

execute macro actions in phase 1 #240

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
6 changes: 3 additions & 3 deletions src/Expander.hs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@
[ ( "open-syntax"
, Scheme [] $ tFun [tSyntax] (Prims.primitiveDatatype "Syntax-Contents" [tSyntax])
, ValueClosure $ HO $
\(ValueSyntax stx) ->

Check warning on line 413 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.2.8

Pattern match(es) are non-exhaustive

Check warning on line 413 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.5

Pattern match(es) are non-exhaustive

Check warning on line 413 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.5

Pattern match(es) are non-exhaustive
case syntaxE stx of
Id name ->
primitiveCtor "identifier-contents" [ValueString name]
Expand All @@ -428,9 +428,9 @@
, Scheme [] $
tFun [tSyntax, tSyntax, Prims.primitiveDatatype "Syntax-Contents" [tSyntax]] tSyntax
, ValueClosure $ HO $
\(ValueSyntax locStx) ->

Check warning on line 431 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.2.8

Pattern match(es) are non-exhaustive

Check warning on line 431 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.5

Pattern match(es) are non-exhaustive

Check warning on line 431 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.5

Pattern match(es) are non-exhaustive
ValueClosure $ HO $
\(ValueSyntax scopesStx) ->

Check warning on line 433 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / stack / ghc 9.2.8

Pattern match(es) are non-exhaustive

Check warning on line 433 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.5

Pattern match(es) are non-exhaustive

Check warning on line 433 in src/Expander.hs

View workflow job for this annotation

GitHub Actions / ubuntu-latest / ghc 9.2.5

Pattern match(es) are non-exhaustive
ValueClosure $ HO $
-- N.B. Assuming correct constructors
\(ValueCtor ctor [arg]) ->
Expand Down Expand Up @@ -1306,7 +1306,7 @@
ValueSyntax $ addScope p stepScope stx
case macroVal of
ValueMacroAction act -> do
res <- interpretMacroAction prob act
res <- inEarlierPhase $ interpretMacroAction prob act
case res of
StuckOnType loc ty env cases kont ->
forkAwaitingTypeCase loc prob ty env cases kont
Expand Down Expand Up @@ -1432,8 +1432,8 @@
getIdent (ValueSyntax stx) = mustBeIdent stx
getIdent _other = throwError $ InternalError $ "Not a syntax object in " ++ opName
compareFree id1 id2 = do
b1 <- resolve id1
b2 <- resolve id2
b1 <- inLaterPhase $ resolve id1
b2 <- inLaterPhase $ resolve id2
return $ Done $
flip primitiveCtor [] $
if b1 == b2 then "true" else "false"
Expand Down
5 changes: 5 additions & 0 deletions src/Expander/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Expander.Monad
, getDecl
, getState
, inEarlierPhase
, inLaterPhase
, inPhase
, isExprChecked
, importing
Expand Down Expand Up @@ -407,6 +408,10 @@ inEarlierPhase :: Expand a -> Expand a
inEarlierPhase act =
Expand $ local (over (expanderLocal . expanderPhase) prior) $ runExpand act

inLaterPhase :: Expand a -> Expand a
inLaterPhase act =
Expand $ local (over (expanderLocal . expanderPhase) posterior) $ runExpand act

moduleScope :: ModuleName -> Expand Scope
moduleScope mn = moduleScope' mn

Expand Down
5 changes: 4 additions & 1 deletion src/Phase.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Phase (Phase(..), runtime, prior, Phased(..)) where
module Phase (Phase(..), runtime, prior, posterior, Phased(..)) where

import Control.Lens
import Data.Data (Data)
Expand Down Expand Up @@ -34,6 +34,9 @@ runtime = Phase 0
prior :: Phase -> Phase
prior (Phase i) = Phase (i + 1)

posterior :: Phase -> Phase
posterior (Phase i) = Phase (i - 1)

class Phased a where
shift :: Natural -> a -> a

Expand Down
Loading