-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #609 from smucclaw/fendor/backend/simala
Add renamer phase and a simala backend for natural4 This PR introduces two new things: * A Renamer/Name resolver phase for Rules * A Transpiler which allows transpiling a Rule to a Simala Decl. The renamer implements lexical scope checking for Hornlike and TypeDecl rules. It resolves all names, replacing occurrences of each name with its renamed equivalent. This is supposed to lay the groundwork for a principled transpilation pipeline, avoiding redoing work for each transpiler, such as resolving names, making sure variables are in scope, etc... In the future, we want to implement a type checker on top of a RnRule. However, that's currently only a dream and there are no attempts of doing any kind of typechecking at the moment. The simala transpiler solely operates on the renamed rules. This simplifies the implementation a lot, demonstrating how other transpilers may also benefit from the rename phase. The simala backend can currently only handle Hornlike rules and ignores any kind of TypeDecl rules, as simala is dynamically typed and typechecking should occur in a dedicated rule phase, not ad-hoc in the transpiler. Both components are somewhat experimental and are expected to have bugs and missing features.
- Loading branch information
Showing
64 changed files
with
4,494 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module LS.Log ( | ||
-- * Logger Type and utility functions | ||
Tracer (..), | ||
traceWith, | ||
cmap, | ||
module CoFunctor, | ||
|
||
-- * Experimental logger backends | ||
prettyTracer, | ||
) | ||
where | ||
|
||
import Data.Functor.Contravariant as CoFunctor | ||
import Prettyprinter | ||
import Prettyprinter.Render.Text (renderStrict) | ||
import System.IO (stderr) | ||
import qualified Data.Text.IO as Text | ||
|
||
newtype Tracer m a = Tracer {runTracer :: a -> m ()} | ||
|
||
instance Contravariant (Tracer m) where | ||
contramap f (Tracer m) = Tracer (m . f) | ||
|
||
instance (Applicative m) => Semigroup (Tracer m a) where | ||
tracer1 <> tracer2 = Tracer $ \a -> runTracer tracer1 a *> runTracer tracer2 a | ||
|
||
instance (Applicative m) => Monoid (Tracer m a) where | ||
mempty = Tracer $ \_ -> pure () | ||
|
||
traceWith :: Tracer m a -> a -> m () | ||
traceWith tracer msg = runTracer tracer msg | ||
|
||
-- | Shorter name for 'contramap' specialised to | ||
cmap :: forall a' a m. (a' -> a) -> Tracer m a -> Tracer m a' | ||
cmap = contramap | ||
|
||
prettyTracer :: (Pretty a) => Tracer IO a | ||
prettyTracer = | ||
Tracer $ | ||
Text.hPutStrLn stderr | ||
. renderStrict | ||
. layoutPretty defaultLayoutOptions | ||
. pretty |
Oops, something went wrong.