Cleaned files, output file name match name of text file
This commit is contained in:
parent
d2a1ca97d7
commit
2f8550d0e5
14 changed files with 43 additions and 219 deletions
BIN
Grammar.pdf
BIN
Grammar.pdf
Binary file not shown.
32
Justfile
32
Justfile
|
|
@ -6,7 +6,7 @@ build:
|
||||||
# clean the generated directories
|
# clean the generated directories
|
||||||
clean:
|
clean:
|
||||||
rm -r src/Grammar
|
rm -r src/Grammar
|
||||||
rm language
|
rm churf
|
||||||
rm -r dist-newstyle/
|
rm -r dist-newstyle/
|
||||||
|
|
||||||
# run all tests
|
# run all tests
|
||||||
|
|
@ -14,46 +14,46 @@ test:
|
||||||
cabal test
|
cabal test
|
||||||
|
|
||||||
debug FILE:
|
debug FILE:
|
||||||
cabal run language -- -d {{FILE}}
|
cabal run churf -- -d {{FILE}}
|
||||||
|
|
||||||
hm FILE:
|
hm FILE:
|
||||||
cabal run language -- -t hm {{FILE}}
|
cabal run churf -- -t hm {{FILE}}
|
||||||
|
|
||||||
bi FILE:
|
bi FILE:
|
||||||
cabal run language -- -t bi {{FILE}}
|
cabal run churf -- -t bi {{FILE}}
|
||||||
|
|
||||||
hml FILE:
|
hml FILE:
|
||||||
cabal run language -- -l -t hm {{FILE}}
|
cabal run churf -- -l -t hm {{FILE}}
|
||||||
|
|
||||||
bil FILE:
|
bil FILE:
|
||||||
cabal run language -- -l -t bi {{FILE}}
|
cabal run churf -- -l -t bi {{FILE}}
|
||||||
|
|
||||||
hmd FILE:
|
hmd FILE:
|
||||||
cabal run language -- -d -t hm {{FILE}}
|
cabal run churf -- -d -t hm {{FILE}}
|
||||||
|
|
||||||
bid FILE:
|
bid FILE:
|
||||||
cabal run language -- -d -t bi {{FILE}}
|
cabal run churf -- -d -t bi {{FILE}}
|
||||||
|
|
||||||
hmdm FILE:
|
hmdm FILE:
|
||||||
cabal run language -- -d -t hm -m {{FILE}}
|
cabal run churf -- -d -t hm -m {{FILE}}
|
||||||
|
|
||||||
bidm FILE:
|
bidm FILE:
|
||||||
cabal run language -- -d -t bi -m {{FILE}}
|
cabal run churf -- -d -t bi -m {{FILE}}
|
||||||
|
|
||||||
hmp FILE:
|
hmp FILE:
|
||||||
cabal run language -- -t hm -p {{FILE}}
|
cabal run churf -- -t hm -p {{FILE}}
|
||||||
|
|
||||||
bip FILE:
|
bip FILE:
|
||||||
cabal run language -- -t bi -p {{FILE}}
|
cabal run churf -- -t bi -p {{FILE}}
|
||||||
|
|
||||||
hmdp FILE:
|
hmdp FILE:
|
||||||
cabal run language -- -t hm -d -p {{FILE}}
|
cabal run churf -- -t hm -d -p {{FILE}}
|
||||||
|
|
||||||
bidp FILE:
|
bidp FILE:
|
||||||
cabal run language -- -t bi -d -p {{FILE}}
|
cabal run churf -- -t bi -d -p {{FILE}}
|
||||||
|
|
||||||
quicksort:
|
quicksort:
|
||||||
cabal run language -- -t bi sample-programs/working/quicksort.crf
|
cabal run churf -- -t bi sample-programs/working/quicksort.crf
|
||||||
|
|
||||||
lc:
|
lc:
|
||||||
cabal run language -- -t bi sample-programs/working/lambda_calculus-2.crf
|
cabal run churf -- -t bi sample-programs/working/lambda_calculus-2.crf
|
||||||
|
|
|
||||||
2
Makefile
2
Makefile
|
|
@ -29,7 +29,7 @@ pdf : Grammar.pdf
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
rm -r src/Grammar
|
rm -r src/Grammar
|
||||||
rm language
|
rm churf
|
||||||
rm -rf dist-newstyles
|
rm -rf dist-newstyles
|
||||||
rm Grammar.aux Grammar.fdb_latexmk Grammar.fls Grammar.log Grammar.synctex.gz Grammar.tex
|
rm Grammar.aux Grammar.fdb_latexmk Grammar.fls Grammar.log Grammar.synctex.gz Grammar.tex
|
||||||
|
|
||||||
|
|
|
||||||
21
benchmark.py
21
benchmark.py
|
|
@ -1,21 +0,0 @@
|
||||||
#!/bin/env/python3
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import time
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
args = sys.argv
|
|
||||||
if len(args) == 1:
|
|
||||||
print ("first arg is number of loops second is exe")
|
|
||||||
else:
|
|
||||||
total = 0
|
|
||||||
iter = int(args[1])
|
|
||||||
for i in range(iter):
|
|
||||||
time_pre = time.time()
|
|
||||||
os.system("./" + args[2] + "> /dev/null")
|
|
||||||
time_post = time.time()
|
|
||||||
calc = time_post - time_pre
|
|
||||||
total += calc
|
|
||||||
|
|
||||||
print ("File: " + args[2] + ", " + str(iter) + " runs gave average: " + str(total / iter) + "s")
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
# Full optimization Churf
|
|
||||||
File: output/hello_world, 100 runs gave average: 0.025261127948760988s
|
|
||||||
|
|
||||||
# O2 Haskell
|
|
||||||
File: ./Bench, 100 runs gave average: 0.05629507303237915s
|
|
||||||
|
|
||||||
# 03 Haskell
|
|
||||||
File: ./Bench, 100 runs gave average: 0.05490849256515503s
|
|
||||||
File: ./Bench, 100 runs gave average: 0.05323728561401367s
|
|
||||||
1
churf
Symbolic link
1
churf
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
/home/sebastian/.cabal/store/ghc-9.4.4/churf-0.1.0.0-e-churf-6264c247f03a157a1144a9887dd5a43d0d1c799ad268c2cb352a8a1a6c014e8e/bin/churf
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
cabal-version: 3.4
|
cabal-version: 3.4
|
||||||
|
|
||||||
name: language
|
name: churf
|
||||||
|
|
||||||
version: 0.1.0.0
|
version: 0.1.0.0
|
||||||
license: MIT
|
license: MIT
|
||||||
|
|
@ -18,7 +18,7 @@ extra-source-files:
|
||||||
common warnings
|
common warnings
|
||||||
ghc-options: -w
|
ghc-options: -w
|
||||||
|
|
||||||
executable language
|
executable churf
|
||||||
import: warnings
|
import: warnings
|
||||||
|
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
|
|
@ -72,10 +72,11 @@ executable language
|
||||||
, QuickCheck
|
, QuickCheck
|
||||||
, directory
|
, directory
|
||||||
, process
|
, process
|
||||||
|
, filepath
|
||||||
|
|
||||||
default-language: GHC2021
|
default-language: GHC2021
|
||||||
|
|
||||||
Test-suite language-testsuite
|
Test-suite churf-testsuite
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
indent-wheres: false
|
|
||||||
27
pipeline.txt
27
pipeline.txt
|
|
@ -1,27 +0,0 @@
|
||||||
|
|
||||||
Parser
|
|
||||||
|
|
|
||||||
ReportForall Report unnecessary foralls. Hm: report rank>2 foralls
|
|
||||||
|
|
|
||||||
AnnotateForall Annotate all unbound type variables with foralls
|
|
||||||
|
|
|
||||||
Renamer Rename type variables and term variables
|
|
||||||
|
|
|
||||||
/ \
|
|
||||||
/ \
|
|
||||||
TypeCheckHm TypeCheckBi
|
|
||||||
\ /
|
|
||||||
\ /
|
|
||||||
|
|
|
||||||
ReportTEVar Report type existential variables and change type AST
|
|
||||||
|
|
|
||||||
RemoveForall RemoveForall and change type AST
|
|
||||||
|
|
|
||||||
Monomorpher
|
|
||||||
|
|
|
||||||
Desugar
|
|
||||||
|
|
|
||||||
CodeGen
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
121
spec.txt
121
spec.txt
|
|
@ -1,121 +0,0 @@
|
||||||
---------------------------------------------------------------------------
|
|
||||||
-- * Parser
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
data Program = Program [Def]
|
|
||||||
|
|
||||||
data Def = DSig Ident Type | DBind Bind
|
|
||||||
|
|
||||||
data Bind = Bind Ident [Ident] Exp
|
|
||||||
|
|
||||||
data Exp
|
|
||||||
= EId Ident
|
|
||||||
| ELit Lit
|
|
||||||
| EAnn Exp Type
|
|
||||||
| ELet Ident Exp Exp
|
|
||||||
| EApp Exp Exp
|
|
||||||
| EAdd Exp Exp
|
|
||||||
| EAbs Ident Exp
|
|
||||||
|
|
||||||
data Lit = LInt Integer
|
|
||||||
| LChar Character
|
|
||||||
|
|
||||||
data Type
|
|
||||||
= TLit Ident -- τ
|
|
||||||
| TVar TVar -- α
|
|
||||||
| TFun Type Type -- A → A
|
|
||||||
| TAll TVar Type -- ∀α. A
|
|
||||||
| TEVar TEVar -- ά (internal)
|
|
||||||
|
|
||||||
data TVar = MkTVar Ident
|
|
||||||
data TEVar = MkTEVar Ident
|
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
-- * Type checker
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
-- • Def and DSig are removed in favor on just Bind
|
|
||||||
-- • Typed expressions
|
|
||||||
-- • TEVar is removed (NOT IMPLEMENTED)
|
|
||||||
|
|
||||||
newtype Program = Program [Bind]
|
|
||||||
|
|
||||||
data Bind = Bind Id [Id] ExpT
|
|
||||||
|
|
||||||
data Exp
|
|
||||||
= EId Ident
|
|
||||||
| ELit Lit
|
|
||||||
| ELet Bind ExpT
|
|
||||||
| EApp ExpT ExpT
|
|
||||||
| EAdd ExpT ExpT
|
|
||||||
| EAbs Ident ExpT
|
|
||||||
|
|
||||||
type Id = (Ident, Type)
|
|
||||||
type ExpT = (Exp, Type)
|
|
||||||
|
|
||||||
|
|
||||||
data Lit = LInt Integer
|
|
||||||
| LChar Character
|
|
||||||
|
|
||||||
data Type
|
|
||||||
= TLit Ident -- τ
|
|
||||||
| TVar TVar -- α
|
|
||||||
| TFun Type Type -- A → A
|
|
||||||
| TAll TVar Type -- ∀α. A
|
|
||||||
|
|
||||||
data TVar = MkTVar Ident
|
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
-- * Lambda lifter
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
-- • EAbs are removed (NOT IMPLEMENTED)
|
|
||||||
-- • ELet only allow constant expressions (NOT IMPLEMENTED)
|
|
||||||
|
|
||||||
newtype Program = Program [Bind]
|
|
||||||
|
|
||||||
data Bind = Bind Id [Id] ExpT
|
|
||||||
|
|
||||||
data Exp
|
|
||||||
= EId Ident
|
|
||||||
| ELit Lit
|
|
||||||
| ELet Ident ExpT ExpT
|
|
||||||
| EApp ExpT ExpT
|
|
||||||
| EAdd ExpT ExpT
|
|
||||||
|
|
||||||
type Id = (Ident, Type)
|
|
||||||
type ExpT = (Exp, Type)
|
|
||||||
|
|
||||||
data Lit = LInt Integer
|
|
||||||
| LChar Character
|
|
||||||
|
|
||||||
data Type
|
|
||||||
= TLit Ident -- τ
|
|
||||||
| TVar TVar -- α
|
|
||||||
| TFun Type Type -- A → A
|
|
||||||
| TAll TVar Type -- ∀α. A
|
|
||||||
|
|
||||||
data TVar = MkTVar Ident
|
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
-- * Monomorpher
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
-- • Polymorphic types are removed (NOT IMPLEMENTED)
|
|
||||||
|
|
||||||
newtype Program = Program [Bind]
|
|
||||||
|
|
||||||
data Bind = Bind Id [Id] ExpT
|
|
||||||
|
|
||||||
data Exp
|
|
||||||
= EId Ident
|
|
||||||
| ELit Lit
|
|
||||||
| ELet Ident ExpT ExpT
|
|
||||||
| EApp ExpT ExpT
|
|
||||||
| EAdd ExpT ExpT
|
|
||||||
|
|
||||||
type Id = (Ident, Type)
|
|
||||||
type ExpT = (Exp, Type)
|
|
||||||
|
|
||||||
data Lit = LInt Integer
|
|
||||||
| LChar Character
|
|
||||||
|
|
||||||
data Type = Type Ident
|
|
||||||
|
|
@ -7,8 +7,8 @@ import System.Process.Extra (readCreateProcess, shell)
|
||||||
optimize :: String -> IO String
|
optimize :: String -> IO String
|
||||||
optimize = readCreateProcess (shell "opt --O3 --tailcallopt -S")
|
optimize = readCreateProcess (shell "opt --O3 --tailcallopt -S")
|
||||||
|
|
||||||
compileClang :: Bool -> String -> IO String
|
compileClang :: String -> Bool -> String -> IO String
|
||||||
compileClang False =
|
compileClang name False =
|
||||||
readCreateProcess . shell $
|
readCreateProcess . shell $
|
||||||
unwords
|
unwords
|
||||||
[ "clang++" -- , "-Lsrc/GC/lib/", "-l:libgcoll.a"
|
[ "clang++" -- , "-Lsrc/GC/lib/", "-l:libgcoll.a"
|
||||||
|
|
@ -16,10 +16,10 @@ compileClang False =
|
||||||
, "-x"
|
, "-x"
|
||||||
, "ir" -- , "-Lsrc/GC/lib -l:gcoll.a"
|
, "ir" -- , "-Lsrc/GC/lib -l:gcoll.a"
|
||||||
, "-o"
|
, "-o"
|
||||||
, "output/hello_world"
|
, "output/" <> name
|
||||||
, "-"
|
, "-"
|
||||||
]
|
]
|
||||||
compileClang True =
|
compileClang name True =
|
||||||
readCreateProcess . shell $
|
readCreateProcess . shell $
|
||||||
unwords
|
unwords
|
||||||
[ "clang++" -- , "-Lsrc/GC/lib/", "-l:libgcoll.a"
|
[ "clang++" -- , "-Lsrc/GC/lib/", "-l:libgcoll.a"
|
||||||
|
|
@ -36,9 +36,9 @@ compileClang True =
|
||||||
, "-x"
|
, "-x"
|
||||||
, "ir" -- , "-Lsrc/GC/lib -l:gcoll.a"
|
, "ir" -- , "-Lsrc/GC/lib -l:gcoll.a"
|
||||||
, "-o"
|
, "-o"
|
||||||
, "output/hello_world"
|
, "output/" <> name
|
||||||
, "-"
|
, "-"
|
||||||
]
|
]
|
||||||
|
|
||||||
compile :: String -> Bool -> IO String
|
compile :: String -> String -> Bool -> IO String
|
||||||
compile s addGc = optimize s >>= compileClang addGc
|
compile name s addGc = optimize s >>= compileClang name addGc
|
||||||
|
|
|
||||||
25
src/Main.hs
25
src/Main.hs
|
|
@ -8,6 +8,7 @@ import Compiler (compile)
|
||||||
import Control.Monad (when, (<=<))
|
import Control.Monad (when, (<=<))
|
||||||
import Data.List.Extra (isSuffixOf)
|
import Data.List.Extra (isSuffixOf)
|
||||||
import Data.Maybe (fromJust, isNothing)
|
import Data.Maybe (fromJust, isNothing)
|
||||||
|
import Data.Tuple.Extra (uncurry3)
|
||||||
import Desugar.Desugar (desugar)
|
import Desugar.Desugar (desugar)
|
||||||
-- import Expander (expand)
|
-- import Expander (expand)
|
||||||
import GHC.IO.Handle.Text (hPutStrLn)
|
import GHC.IO.Handle.Text (hPutStrLn)
|
||||||
|
|
@ -32,27 +33,30 @@ import System.Environment (getArgs)
|
||||||
import System.Exit (ExitCode (ExitFailure),
|
import System.Exit (ExitCode (ExitFailure),
|
||||||
exitFailure, exitSuccess,
|
exitFailure, exitSuccess,
|
||||||
exitWith)
|
exitWith)
|
||||||
|
import System.FilePath.Posix (takeFileName, dropExtensions)
|
||||||
import System.IO (stderr)
|
import System.IO (stderr)
|
||||||
import System.Process (spawnCommand, waitForProcess)
|
import System.Process (spawnCommand, waitForProcess)
|
||||||
import TypeChecker.TypeChecker (TypeChecker (Bi, Hm), typecheck)
|
import TypeChecker.TypeChecker (TypeChecker (Bi, Hm), typecheck)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = getArgs >>= parseArgs >>= uncurry main'
|
main = getArgs >>= parseArgs >>= uncurry3 main'
|
||||||
|
|
||||||
parseArgs :: [String] -> IO (Options, String)
|
parseArgs :: [String] -> IO (Options, String, String)
|
||||||
parseArgs argv = case getOpt RequireOrder flags argv of
|
parseArgs argv = case getOpt RequireOrder flags argv of
|
||||||
(os, f : _, [])
|
(os, f : xs, [])
|
||||||
| opts.help || isNothing opts.typechecker -> do
|
| opts.help || isNothing opts.typechecker -> do
|
||||||
hPutStrLn stderr (usageInfo header flags)
|
hPutStrLn stderr (usageInfo header flags)
|
||||||
exitSuccess
|
exitSuccess
|
||||||
| otherwise -> pure (opts, f)
|
| otherwise -> do
|
||||||
|
let name = dropExtensions $ takeFileName f
|
||||||
|
pure (opts, name, f)
|
||||||
where
|
where
|
||||||
opts = foldr ($) initOpts os
|
opts = foldr ($) initOpts os
|
||||||
(_, _, errs) -> do
|
(_, _, errs) -> do
|
||||||
hPutStrLn stderr (concat errs ++ usageInfo header flags)
|
hPutStrLn stderr (concat errs ++ usageInfo header flags)
|
||||||
exitWith (ExitFailure 1)
|
exitWith (ExitFailure 1)
|
||||||
where
|
where
|
||||||
header = "Usage: language [--help] [-l|--log-intermediate] [-d|--debug] [-m|--disable-gc] [-t|--type-checker bi/hm] [-p|--disable-prelude] <FILE> \n"
|
header = "Usage: churf [--help] [-l|--log-intermediate] [-d|--debug] [-m|--disable-gc] [-t|--type-checker bi/hm] [-p|--disable-prelude] <FILE> \n"
|
||||||
|
|
||||||
flags :: [OptDescr (Options -> Options)]
|
flags :: [OptDescr (Options -> Options)]
|
||||||
flags =
|
flags =
|
||||||
|
|
@ -108,8 +112,8 @@ data Options = Options
|
||||||
, logIL :: Bool
|
, logIL :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
main' :: Options -> String -> IO ()
|
main' :: Options -> String -> String -> IO ()
|
||||||
main' opts s =
|
main' opts name s =
|
||||||
let
|
let
|
||||||
log :: (Print a, Show a) => a -> IO ()
|
log :: (Print a, Show a) => a -> IO ()
|
||||||
log = printToErr . if opts.debug then show else printTree
|
log = printToErr . if opts.debug then show else printTree
|
||||||
|
|
@ -149,7 +153,6 @@ main' opts s =
|
||||||
|
|
||||||
|
|
||||||
generatedCode <- fromErr $ generateCode monomorphized (gc opts)
|
generatedCode <- fromErr $ generateCode monomorphized (gc opts)
|
||||||
-- generatedCode <- fromErr $ generateCode monomorphized False
|
|
||||||
|
|
||||||
check <- doesPathExist "output"
|
check <- doesPathExist "output"
|
||||||
when check (removeDirectoryRecursive "output")
|
when check (removeDirectoryRecursive "output")
|
||||||
|
|
@ -159,13 +162,11 @@ main' opts s =
|
||||||
when opts.debug $ do
|
when opts.debug $ do
|
||||||
printToErr "\n -- Compiler --"
|
printToErr "\n -- Compiler --"
|
||||||
writeFile "output/llvm.ll" generatedCode
|
writeFile "output/llvm.ll" generatedCode
|
||||||
--debugDotViz
|
|
||||||
|
|
||||||
compile generatedCode (gc opts)
|
compile name generatedCode (gc opts)
|
||||||
-- compile generatedCode False
|
|
||||||
printToErr "Compilation done!"
|
printToErr "Compilation done!"
|
||||||
printToErr "\n-- Program output --"
|
printToErr "\n-- Program output --"
|
||||||
print =<< spawnWait "./output/hello_world"
|
print =<< spawnWait ("./output/" <> name)
|
||||||
|
|
||||||
exitSuccess
|
exitSuccess
|
||||||
|
|
||||||
|
|
|
||||||
1
test.crf
Normal file
1
test.crf
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
main = 5
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
main = let f x = x in f 123
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue