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

Embedded codegens and refactoring #3577

Closed
wants to merge 20 commits into from
Closed
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ install:
# causing cabal's default configuration (jobs: $ncpus)
# to run into the GHC #9221 bug which can result in longer build-times.
- $SED -i -r 's/(^jobs:).*/\1 2/' $HOME/.cabal/config
- cabal install -f FFI --only-dependencies --enable-tests --dry -v > installplan.txt
- cabal install --constraint="idris-core +FFI" --only-dependencies --enable-tests --dry -v > installplan.txt
- $SED -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt
# check whether current requested install-plan matches cached package-db snapshot
- if diff -u installplan.txt $HOME/.cabsnap/installplan.txt;
Expand All @@ -92,7 +92,7 @@ install:
echo "cabal build-cache MISS";
rm -rf $HOME/.cabsnap;
mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin;
cabal install -f FFI --only-dependencies --enable-tests;
cabal install --constraint="idris-core +FFI" --only-dependencies --enable-tests;
fi
# snapshot package-db on cache miss
- if [ ! -d $HOME/.cabsnap ];
Expand All @@ -112,7 +112,7 @@ before_script:
script:
###
- echo 'Configure...' && echo -en 'travis_fold:start:script.configure\\r'
- cabal configure -f FFI -f CI --enable-tests
- cabal configure --constraint="idris-core +FFI" -f CI --constraint="idris-core +CI" --constraint="idris-codegen-c +CI" --constraint="idris-codegen-javascript +CI" --enable-tests
- echo -en 'travis_fold:end:script.configure\\r'
###
- echo 'Build...' && echo -en 'travis_fold:start:script.build\\r'
Expand Down
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
ARGS=
TEST-JOBS=
TEST-ARGS=
PACKAGES=. ./core ./codegen/idris-codegen-c ./codegen/idris-codegen-javascript

include config.mk
-include custom.mk

ifdef CI
CABALFLAGS += -f CI
CABALFLAGS += -f CI --constraint="idris-core +CI" --constraint="idris-codegen-c +CI" --constraint="idris-codegen-javascript +CI"
ifndef APPVEYOR
TEST-ARGS += --color always
endif
endif

install:
$(CABAL) install $(CABALFLAGS)
$(CABAL) install $(CABALFLAGS) $(PACKAGES)

pinstall: CABALFLAGS += --enable-executable-profiling
pinstall: dist/setup-config
$(CABAL) install $(CABALFLAGS)
$(CABAL) install $(CABALFLAGS) $(PACKAGES)

build: dist/setup-config
$(CABAL) build $(CABALFLAGS)
$(CABAL) build $(CABALFLAGS) $(PACKAGES)

test: doc test_c

Expand All @@ -46,10 +47,10 @@ lib_clean:
$(MAKE) -C libs IDRIS=../../dist/build/idris/idris RTS=../../dist/build/rts/libidris_rts clean

relib: lib_clean
$(CABAL) install $(CABALFLAGS)
$(CABAL) install $(CABALFLAGS) $(PACKAGES)

linecount:
wc -l src/Idris/*.hs src/Idris/Elab/*.hs src/Idris/Core/*.hs src/IRTS/*.hs src/Pkg/*.hs src/Util/*.hs
wc -l core/src/Idris/*.hs core/src/Idris/Elab/*.hs core/src/Idris/Core/*.hs core/src/IRTS/*.hs core/src/Pkg/*.hs core/src/Util/*.hs

#Note: this doesn't yet link to Hackage properly
doc: dist/setup-config
Expand All @@ -73,7 +74,7 @@ user_doc_pdf:
$(MAKE) -C docs latexpdf

fast:
$(CABAL) install $(CABALFLAGS) --ghc-option=-O0
$(CABAL) install $(CABALFLAGS) --ghc-option=-O0 $(PACKAGES)

dist/setup-config:
$(CABAL) configure $(CABALFLAGS)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ More information about building Idris from source has been detailed in the [Inst

## Code Generation

Idris has support for external code generators. Supplied with the distribution
is a C code generator to compile executables, and a JavaScript code generator
with support for node.js and browser JavaScript.
Idris has support for external and embedded code generators. Supplied with the
distribution is a C code generator to compile executables, and a JavaScript code
generator with support for node.js and browser JavaScript, both of them embedded.

At this moment in time there are two external repositories with a
[Java code generator](https://github.com/idris-hackers/idris-java) and an
Expand Down
79 changes: 5 additions & 74 deletions Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,17 @@ make verbosity =
#ifdef mingw32_HOST_OS
windres verbosity = P.runProgramInvocation verbosity . P.simpleProgramInvocation "windres"
#endif

-- -----------------------------------------------------------------------------
-- Flags

usesGMP :: S.ConfigFlags -> Bool
usesGMP flags =
case lookup (FlagName "gmp") (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> False

execOnly :: S.ConfigFlags -> Bool
execOnly flags =
case lookup (FlagName "execonly") (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> False

isRelease :: S.ConfigFlags -> Bool
isRelease flags =
case lookup (FlagName "release") (S.configConfigurationsFlags flags) of
Just True -> True
Just False -> False
Nothing -> False

isFreestanding :: S.ConfigFlags -> Bool
isFreestanding flags =
case lookup (FlagName "freestanding") (S.configConfigurationsFlags flags) of
Expand All @@ -96,27 +83,6 @@ idrisClean _ flags _ _ = cleanStdLib
-- -----------------------------------------------------------------------------
-- Configure

gitHash :: IO String
gitHash = do h <- Control.Exception.catch (readProcess "git" ["rev-parse", "--short", "HEAD"] "")
(\e -> let e' = (e :: SomeException) in return "PRE")
return $ takeWhile (/= '\n') h

-- Put the Git hash into a module for use in the program
-- For release builds, just put the empty string in the module
generateVersionModule verbosity dir release = do
hash <- gitHash
let versionModulePath = dir </> "Version_idris" Px.<.> "hs"
putStrLn $ "Generating " ++ versionModulePath ++
if release then " for release" else " for prerelease " ++ hash
createDirectoryIfMissingVerbose verbosity True dir
rewriteFile versionModulePath (versionModuleContents hash)

where versionModuleContents h = "module Version_idris where\n\n" ++
"gitHash :: String\n" ++
if release
then "gitHash = \"\"\n"
else "gitHash = \"git:" ++ h ++ "\"\n"

-- Generate a module that contains the lib path for a freestanding Idris
generateTargetModule verbosity dir targetDir = do
let absPath = isAbsolute targetDir
Expand All @@ -134,10 +100,6 @@ generateTargetModule verbosity dir targetDir = do
" expath <- getExecutablePath\n" ++
" execDir <- return $ dropFileName expath\n" ++
" return $ execDir ++ \"" ++ td ++ "\"\n"
++ "getDataFileName :: FilePath -> IO FilePath\n"
++ "getDataFileName name = do\n"
++ " dir <- getDataDir\n"
++ " return (dir ++ \"/\" ++ name)"

-- a module that has info about existence and location of a bundled toolchain
generateToolchainModule verbosity srcDir toolDir = do
Expand All @@ -152,8 +114,6 @@ generateToolchainModule verbosity srcDir toolDir = do
rewriteFile toolPath (commonContent ++ toolContent)

idrisConfigure _ flags _ local = do
configureRTS
generateVersionModule verbosity (autogenModulesDir local) (isRelease (configFlags local))
if isFreestanding $ configFlags local
then do
toolDir <- lookupEnv "IDRIS_TOOLCHAIN_DIR"
Expand All @@ -167,18 +127,10 @@ idrisConfigure _ flags _ local = do
generateToolchainModule verbosity (autogenModulesDir local) Nothing
where
verbosity = S.fromFlag $ S.configVerbosity flags
version = pkgVersion . package $ localPkgDescr local

-- This is a hack. I don't know how to tell cabal that a data file needs
-- installing but shouldn't be in the distribution. And it won't make the
-- distribution if it's not there, so instead I just delete
-- the file after configure.
configureRTS = make verbosity ["-C", "rts", "clean"]

idrisPreSDist args flags = do
let dir = S.fromFlag (S.sDistDirectory flags)
let verb = S.fromFlag (S.sDistVerbosity flags)
generateVersionModule verb "src" True
generateTargetModule verb "src" "./libs"
generateToolchainModule verb "src" Nothing
preSDist simpleUserHooks args flags
Expand All @@ -195,24 +147,16 @@ idrisSDist sdist pkgDesc bi hooks flags = do
gitFiles = liftM lines (readProcess "git" ["ls-files"] "")

idrisPostSDist args flags desc lbi = do
Control.Exception.catch (do let file = "src" </> "Version_idris" Px.<.> "hs"
let targetFile = "src" </> "Target_idris" Px.<.> "hs"
Control.Exception.catch (do let targetFile = "src" </> "Target_idris" Px.<.> "hs"
putStrLn $ "Removing generated modules:\n "
++ file ++ "\n" ++ targetFile
removeFile file
++ targetFile
removeFile targetFile)
(\e -> let e' = (e :: SomeException) in return ())
postSDist simpleUserHooks args flags desc lbi

-- -----------------------------------------------------------------------------
-- Build

getVersion :: Args -> S.BuildFlags -> IO HookedBuildInfo
getVersion args flags = do
hash <- gitHash
let buildinfo = (emptyBuildInfo { cppOptions = ["-DVERSION="++hash] }) :: BuildInfo
return (Just buildinfo, [])

idrisPreBuild args flags = do
#ifdef mingw32_HOST_OS
createDirectoryIfMissingVerbose verbosity True dir
Expand All @@ -225,9 +169,8 @@ idrisPreBuild args flags = do
return (Nothing, [])
#endif

idrisBuild _ flags _ local = unless (execOnly (configFlags local)) $ do
buildStdLib
buildRTS
idrisBuild _ flags _ local = do
unless (execOnly (configFlags local)) buildStdLib
where
verbosity = S.fromFlag $ S.buildVerbosity flags

Expand All @@ -237,18 +180,11 @@ idrisBuild _ flags _ local = unless (execOnly (configFlags local)) $ do
where
makeBuild dir = make verbosity [ "-C", dir, "build" , "IDRIS=" ++ idrisCmd local]

buildRTS = make verbosity (["-C", "rts", "build"] ++
gmpflag (usesGMP (configFlags local)))

gmpflag False = []
gmpflag True = ["GMP=-DIDRIS_GMP"]

-- -----------------------------------------------------------------------------
-- Copy/Install

idrisInstall verbosity copy pkg local = unless (execOnly (configFlags local)) $ do
installStdLib
installRTS
installManPage
where
target = datadir $ L.absoluteInstallDirs pkg local copy
Expand All @@ -258,11 +194,6 @@ idrisInstall verbosity copy pkg local = unless (execOnly (configFlags local)) $
putStrLn $ "Installing libraries in " ++ target'
makeInstall "libs" target'

installRTS = do
let target' = target </> "rts"
putStrLn $ "Installing run time system in " ++ target'
makeInstall "rts" target'

installManPage = do
let mandest = mandir (L.absoluteInstallDirs pkg local copy) ++ "/man1"
notice verbosity $ unwords ["Copying man page to", mandest]
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ environment:
MSYSTEM: MINGW64
MSYS2_PATH_TYPE: inherit
build_script:
- ps: c:\msys64\usr\bin\bash -l -c "cd $env:current_posix && cabal install -fffi -j4 --enable-tests"
- ps: c:\msys64\usr\bin\bash -l -c "cd $env:current_posix && cabal install --constraint=\"idris-core +FFI\" -j4 --enable-tests"
test_script:
- ps: c:\msys64\usr\bin\bash -l -c "cd $env:current_posix && make test_c"
32 changes: 32 additions & 0 deletions codegen/idris-codegen-c/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Copyright (c) 2011 Edwin Brady
School of Computer Science, University of St Andrews
All rights reserved.

This code is derived from software written by Edwin Brady
(eb@cs.st-andrews.ac.uk).

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. None of the names of the copyright holders may be used to endorse
or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*** End of disclaimer. ***
51 changes: 0 additions & 51 deletions codegen/idris-codegen-c/Main.hs

This file was deleted.

Loading