Skip to content

Commit

Permalink
Eval files and macros in the context of the current project, rather t…
Browse files Browse the repository at this point in the history
…han in a separate ad-hoc directory

This allows us to more easily implement module system support, since we
don't have to worry about bringing everything into scope in our ad-hoc
environment.
  • Loading branch information
jgrosso committed Nov 7, 2018
1 parent b17e165 commit a4b62ae
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 167 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ axelTemp
resources/autogenerated/*
resources/new-project-template/**/*.hs
AUTOGENERATED*
AutogeneratedAxel*.hs

flycheck_*.hs

ctags
TAGS
TAGS
4 changes: 2 additions & 2 deletions axel.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 01937382699276a02f31dac43a069626cd750821b38768ce5e6092998a14e176
-- hash: a43890f8651c0db1bdd3ed7a038c1ed4123378c8941a4002427d31a46f0dbb1c

name: axel
version: 0.0.8
version: 0.0.9
synopsis: The Axel programming language.
description: Haskell's semantics, plus Lisp's macros. Meet Axel – a purely functional, extensible, and powerful programming language.
category: Language, Lisp, Macros, Transpiler
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: axel
version: '0.0.8'
version: '0.0.9'
category: Language, Lisp, Macros, Transpiler
author: Joshua Grosso
maintainer: [email protected]
Expand Down
2 changes: 1 addition & 1 deletion resources/macros/MacroDefinitionAndEnvironmentHeader.hs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module MacroDefinitionAndEnvironment where
module AutogeneratedAxelMacroDefinitionAndEnvironment where
4 changes: 2 additions & 2 deletions resources/macros/Scaffold.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Scaffold where

import Axel.Parse.AST
import qualified MacroDefinitionAndEnvironment as MacroDefinitionAndEnvironment
import qualified AutogeneratedAxelMacroDefinitionAndEnvironment

main :: IO ()
main = do
result <-
MacroDefinitionAndEnvironment.%%%MACRO_NAME%%% %%%ARGUMENTS%%%
AutogeneratedAxelMacroDefinitionAndEnvironment.%%%MACRO_NAME%%% %%%ARGUMENTS%%%
putStrLn $ unlines $ map toAxel result
9 changes: 1 addition & 8 deletions src/Axel/Eff/Resource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ module Axel.Eff.Resource where
import Axel.Eff.FileSystem as FS (FileSystem, readFile)

import Control.Monad ((>=>))
import Control.Monad.Freer
( type (~>)
, Eff
, LastMember
, Member
, Members
, interpretM
)
import Control.Monad.Freer (type (~>), Eff, LastMember, Members, interpretM)
import Control.Monad.Freer.TH (makeEffect)

import Paths_axel (getDataFileName)
Expand Down
23 changes: 8 additions & 15 deletions src/Axel/Haskell/File.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import Axel.AST (ToHaskell(toHaskell))
import Axel.Eff.Console (putStrLn)
import qualified Axel.Eff.Console as Effs (Console)
import qualified Axel.Eff.FileSystem as Effs (FileSystem)
import qualified Axel.Eff.FileSystem as FS
( readFile
, withTemporaryDirectory
, writeFile
)
import qualified Axel.Eff.FileSystem as FS (readFile, removeFile, writeFile)
import Axel.Eff.Process (StreamSpecification(InheritStreams))
import qualified Axel.Eff.Process as Effs (Process)
import Axel.Eff.Resource (readResource)
Expand All @@ -32,7 +28,6 @@ import Axel.Normalize (normalizeStatement)
import Axel.Parse (Expression(Symbol), parseSource)
import Axel.Utils.Recursion (Recursive(bottomUpFmap))

import Control.Lens.Operators ((.~))
import Control.Monad (void)
import Control.Monad.Freer (Eff, Members)
import qualified Control.Monad.Freer.Error as Effs (Error)
Expand All @@ -41,8 +36,7 @@ import Data.Maybe (fromMaybe)
import Data.Semigroup ((<>))
import qualified Data.Text as T (isSuffixOf, pack)

import System.FilePath ((</>), stripExtension, takeFileName)
import System.FilePath.Lens (directory)
import System.FilePath (stripExtension, takeFileName)

convertList :: Expression -> Expression
convertList =
Expand Down Expand Up @@ -101,10 +95,9 @@ evalFile ::
-> Eff effs ()
evalFile path = do
putStrLn ("Building " <> takeFileName path <> "...")
FS.withTemporaryDirectory $ \tempDirectoryPath -> do
let astDefinitionPath = tempDirectoryPath </> "Axel.hs"
readResource Res.astDefinition >>= FS.writeFile astDefinitionPath
let newPath = directory .~ tempDirectoryPath $ axelPathToHaskellPath path
transpileFile path newPath
putStrLn ("Running " <> takeFileName path <> "...")
void $ interpretFile @'InheritStreams newPath
let astDefinitionPath = "AutogeneratedAxelAST.hs"
readResource Res.astDefinition >>= FS.writeFile astDefinitionPath
let newPath = axelPathToHaskellPath path
putStrLn ("Running " <> takeFileName path <> "...")
void $ interpretFile @'InheritStreams newPath
FS.removeFile astDefinitionPath
46 changes: 18 additions & 28 deletions src/Axel/Macros.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

Expand All @@ -22,12 +21,7 @@ import Axel.AST
)
import Axel.Denormalize (denormalizeStatement)
import qualified Axel.Eff.FileSystem as Effs (FileSystem)
import qualified Axel.Eff.FileSystem as FS
( createDirectoryIfMissing
, withCurrentDirectory
, withTemporaryDirectory
, writeFile
)
import qualified Axel.Eff.FileSystem as FS (removeFile, writeFile)
import Axel.Eff.Process (StreamSpecification(CreateStreams))
import qualified Axel.Eff.Process as Effs (Process)
import Axel.Eff.Resource (readResource)
Expand Down Expand Up @@ -76,7 +70,6 @@ import Data.Semigroup ((<>))
import qualified Data.Text as T (isSuffixOf, pack, replace, singleton, unpack)

import System.Exit (ExitCode(ExitFailure))
import System.FilePath ((</>))

hygenisizeMacroName :: String -> String
hygenisizeMacroName oldName =
Expand Down Expand Up @@ -262,23 +255,20 @@ evalMacro ::
-> String
-> String
-> Eff effs String
evalMacro astDefinition scaffold macroDefinitionAndEnvironment =
FS.withTemporaryDirectory $ \directoryName ->
FS.withCurrentDirectory directoryName $ do
let astDirectoryPath = "Axel" </> "Parse"
let macroDefinitionAndEnvironmentFileName =
"MacroDefinitionAndEnvironment.hs"
let scaffoldFileName = "Scaffold.hs"
FS.createDirectoryIfMissing True astDirectoryPath
FS.writeFile (astDirectoryPath </> "AST.hs") astDefinition
FS.writeFile
macroDefinitionAndEnvironmentFileName
macroDefinitionAndEnvironment
FS.writeFile scaffoldFileName scaffold
interpretFile @'CreateStreams scaffoldFileName "" >>= \case
(ExitFailure _, _, stderr) ->
throwError $
MacroError
("Temporary directory: " <> directoryName <> "\n\n" <> "Error:\n" <>
stderr)
(_, stdout, _) -> pure stdout
evalMacro astDefinition scaffold macroDefinitionAndEnvironment = do
let macroDefinitionAndEnvironmentFileName =
"AutogeneratedAxelMacroDefinitionAndEnvironment.hs"
let scaffoldFileName = "AutogeneratedAxelScaffold.hs"
let astDefinitionFileName = "AutogeneratedAxelASTDefinition.hs"
FS.writeFile astDefinitionFileName astDefinition
FS.writeFile
macroDefinitionAndEnvironmentFileName
macroDefinitionAndEnvironment
FS.writeFile scaffoldFileName scaffold
interpretFile @'CreateStreams scaffoldFileName "" >>= \case
(ExitFailure _, _, stderr) -> throwError $ MacroError ("Error:\n" <> stderr)
(_, stdout, _) -> do
FS.removeFile astDefinitionFileName
FS.removeFile macroDefinitionAndEnvironmentFileName
FS.removeFile scaffoldFileName
pure stdout
109 changes: 0 additions & 109 deletions src/Axel/Parse/AST.axel

This file was deleted.

0 comments on commit a4b62ae

Please sign in to comment.