publicUU-ComputerScience/uhc

Subversion checkout URL

You can clone with HTTPS or Subversion.

• 2 commits
• 21 files changed
• 1 contributor
Mar 17, 2009
Creating a new branch from trunk (revision 1517).
This branch will be used to merge the existing dotnet branch into the trunk.
The reason for this new branch is because the dotnet branch is completely broken, since previous merges somehow missed things...
465995c
Mar 19, 2009
Added CLR backend. 00efc41
21  EHC/configure
 @@ -672,6 +672,7 @@ javacCmd 672 672  jarCmd 673 673  JAVAC_CMD 674 674  JAR_CMD 675 +ENABLE_CLR 675 676  ranlibCmd 676 677  RANLIB_CMD 677 678  arCmd @@ -1336,6 +1337,7 @@ Optional Features: 1336 1337  --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) 1337 1338  --enable-FEATURE[=ARG] include FEATURE [ARG=yes] 1338 1339  --enable-java include java code generation 1340 + --enable-clr include clr code generation 1339 1341   1340 1342  Optional Packages: 1341 1343  --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -2153,6 +2155,16 @@ echo "$as_me: error: 2153 2155   2154 2156  fi 2155 2157   2158 +# Check whether --enable-clr was given. 2159 +if test "${enable_clr+set}" = set; then 2160 + enableval=$enable_clr; enableClr=yes 2161 +else 2162 + enableClr=no 2163 +fi 2164 + 2165 +ENABLE_CLR=$enableClr 2166 + 2167 + 2156 2168  ### ar, ranlib, libtool 2157 2169   2158 2170  # Extract the first word of "ranlib", so it can be a program name with args. @@ -2573,6 +2585,10 @@ HADDOCK_VERSION=$haddockVersion 2573 2585   2574 2586  # GHC version dependencies: packages passed as option, cabal packages 2575 2587  cabal_base_lib_depends="base haskell98 mtl fgl directory old-time" 2588 +if test x$enableClr = "xyes" 2589 +then 2590 + cabal_base_lib_depends="$cabal_base_lib_depends language-cil" 2591 +fi 2576 2592  cabal_extra_lib_depends="" 2577 2593  optCabalAllowUndecidableInstances=UndecidableInstances 2578 2594  optStandardGHCPackages="" @@ -7432,6 +7448,7 @@ javacCmd!$javacCmd$ac_delim 7432 7448  jarCmd!$jarCmd$ac_delim 7433 7449  JAVAC_CMD!$JAVAC_CMD$ac_delim 7434 7450  JAR_CMD!$JAR_CMD$ac_delim 7451 +ENABLE_CLR!$ENABLE_CLR$ac_delim 7435 7452  ranlibCmd!$ranlibCmd$ac_delim 7436 7453  RANLIB_CMD!$RANLIB_CMD$ac_delim 7437 7454  arCmd!$arCmd$ac_delim @@ -7471,7 +7488,6 @@ cppCmd!$cppCmd$ac_delim 7471 7488  CPP_CMD!$CPP_CMD$ac_delim 7472 7489  llvmAs!$llvmAs$ac_delim 7473 7490  LLVM_AS_CMD!$LLVM_AS_CMD$ac_delim 7474 -llvmOpt!$llvmOpt$ac_delim 7475 7491  _ACEOF 7476 7492   7477 7493  if test sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X = 97; then @@ -7513,6 +7529,7 @@ _ACEOF 7513 7529  ac_delim='%!_!# ' 7514 7530  for ac_last_try in false false false false false :; do 7515 7531  cat >conf$$subs.sed <<_ACEOF 7532 +llvmOpt!$llvmOpt$ac_delim 7516 7533  LLVM_OPT_CMD!$LLVM_OPT_CMD$ac_delim 7517 7534  llvmLlc!$llvmLlc$ac_delim 7518 7535  LLVM_LLC_CMD!$LLVM_LLC_CMD$ac_delim @@ -7554,7 +7571,7 @@ LIBOBJS!$LIBOBJS$ac_delim 7554 7571  LTLIBOBJS!$LTLIBOBJS$ac_delim 7555 7572  _ACEOF 7556 7573   7557 - if test sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X = 39; then 7574 + if test sed -n "s/.*ac_delim\/X/p" conf$$subs.sed | grep -c X = 40; then 7558 7575  break 7559 7576  elif$ac_last_try; then 7560 7577  { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 7  EHC/configure.ac  @@ -98,6 +98,9 @@ then 98 98  AC_SUBST(JAR_CMD,$jarCmd) 99 99  fi 100 100   101 +AC_ARG_ENABLE(clr, AS_HELP_STRING([--enable-clr],[include clr code generation]), [enableClr=yes], [enableClr=no]) 102 +AC_SUBST(ENABLE_CLR,$enableClr) 103 + 101 104  ### ar, ranlib, libtool 102 105  REQUIRED_PROG_FOR_EH(ranlibCmd,ranlib) 103 106  # See remarks about cpp @@ -247,6 +250,10 @@ AC_SUBST(HADDOCK_VERSION,$haddockVersion) 247 250   248 251  # GHC version dependencies: packages passed as option, cabal packages 249 252  cabal_base_lib_depends="base haskell98 mtl fgl directory old-time" 253 +if test x$enableClr = "xyes" 254 +then 255 + cabal_base_lib_depends="$cabal_base_lib_depends language-cil" 256 +fi 250 257  cabal_extra_lib_depends="" 251 258  optCabalAllowUndecidableInstances=UndecidableInstances 252 259  optStandardGHCPackages=""
BIN  EHC/extlibs/cil/language-cil-0.1.0.tar.gz
Binary file not shown
4  EHC/mk/config.mk.in
 @@ -65,3 +65,7 @@ ifeq (@ENABLE_JAVA@,yes) 65 65  ENABLE_JAVA := yes 66 66  endif 67 67   68 +ifeq (@ENABLE_CLR@,yes) 69 +ENABLE_CLR := yes 70 +endif 71 +
9  EHC/src/ehc/Base/Opts.chs
 @@ -331,6 +331,12 @@ ehcOptEmitLLVM :: EHCOpts -> Bool 331 331  ehcOptEmitLLVM = targetIsLLVM . ehcOptTarget 332 332  %%] 333 333   334 +%%[(8 codegen clr) export(ehcOptEmitCLR) 335 +-- generate CIL, as .il assembly file 336 +ehcOptEmitCLR :: EHCOpts -> Bool 337 +ehcOptEmitCLR = targetIsCLR . ehcOptTarget 338 +%%] 339 + 334 340  %%[(8 codegen) export(ehcOptEmitCore) 335 341  -- generate Core 336 342  ehcOptEmitCore :: EHCOpts -> Bool @@ -663,6 +669,9 @@ ehcCmdLineOpts 663 669  -> o { ehcOptTarget = Target_FullProgAnal_Grin_LLVM 664 670  }  665 671  %%]] 672 +%%[[(8 codegen clr) 673 + Just "clr" -> o { ehcOptTarget = Target_FullProgAnal_Grin_CLR } 674 +%%]] 666 675  %%[[(99 hmtyinfer) 667 676  Just "dt" -> o { ehcOptEmitDerivTree = DerivTreeWay_Final } 668 677  %%]]
27  EHC/src/ehc/Base/Target.chs
 @@ -33,7 +33,7 @@ Target___ 33 33  - C 34 34  - LLVM 35 35  - JVM 36 - - DOTNET 36 + - CLR 37 37  - Jazy, Java lazy interpreter 38 38   39 39  Combinations are all hardcoded to make explicit that only particular combinations are allowed. @@ -53,9 +53,11 @@ data Target 53 53  | Target_FullProgAnal_Grin_C -- full program analysis on grin, generating C 54 54  | Target_FullProgAnal_Grin_LLVM -- full program analysis on grin, generating LLVM 55 55  | Target_FullProgAnal_Grin_JVM -- full program analysis on grin, generating for Java VM 56 - | Target_FullProgAnal_Grin_DOTNET -- full program analysis on grin, generating for .net 57 56  | Target_Interpreter_Grin_C -- no full program analysis, grin interpreter, generating C 58 57  %%]] 58 +%%[[(8 codegen clr) 59 + | Target_FullProgAnal_Grin_CLR -- full program analysis on grin, generating for Common Language Runtime (.NET / Mono) 60 +%%]] 59 61  deriving (Eq,Ord) 60 62  %%] 61 63   @@ -76,9 +78,11 @@ instance Show Target where 76 78  show Target_FullProgAnal_Grin_C = "C" 77 79  show Target_FullProgAnal_Grin_LLVM = "llvm" 78 80  show Target_FullProgAnal_Grin_JVM = "jvm" 79 - show Target_FullProgAnal_Grin_DOTNET = "dotnet" 80 81  show Target_Interpreter_Grin_C = "bc" 81 82  %%]] 83 +%%[[(8 codegen clr) 84 + show Target_FullProgAnal_Grin_CLR = "clr" 85 +%%]] 82 86  %%] 83 87   84 88  Default target @@ -114,6 +118,9 @@ supportedTargetMp :: Map.Map String Target 114 118  , mk Target_FullProgAnal_Grin_C [FFIWay_CCall] 115 119  ] 116 120  %%]] 121 +%%[[(8 codegen clr) 122 + ++ [ mk Target_FullProgAnal_Grin_CLR [FFIWay_CCall] ] 123 +%%]] 117 124  ] 118 125  mk t ffis = (t,TargetInfo (FFIWay_Prim : ffis))  119 126   @@ -138,7 +145,9 @@ targetIsFullProgAnal t 138 145  Target_FullProgAnal_Grin_C -> True 139 146  Target_FullProgAnal_Grin_LLVM -> True 140 147  Target_FullProgAnal_Grin_JVM -> True 141 - Target_FullProgAnal_Grin_DOTNET -> True 148 +%%]] 149 +%%[[(8 codegen clr) 150 + Target_FullProgAnal_Grin_CLR -> True 142 151  %%]] 143 152  _ -> False 144 153  %%] @@ -223,6 +232,16 @@ targetIsLLVM t 223 232  _ -> False 224 233  %%] 225 234   235 +%%[(8 codegen) export(targetIsCLR) 236 +targetIsCLR :: Target -> Bool 237 +targetIsCLR t 238 + = case t of 239 +%%[[(8 codegen clr) 240 + Target_FullProgAnal_Grin_CLR -> True 241 +%%]] 242 + _ -> False 243 +%%] 244 + 226 245  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 227 246  %%% Possible FFI interface routes 228 247  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44  EHC/src/ehc/EHC/GrinCompilerDriver.chs
 @@ -97,6 +97,10 @@ 97 97  %%] 98 98  %%[(8 codegen grin) import({%{EH}LLVM.Pretty(prettyLLVMModule)}) 99 99  %%] 100 +%%[(8 codegen clr) hs import(Language.Cil (Assembly (..), cil)) 101 +%%] 102 +%%[(8 codegen clr) import({%{EH}GrinCode.ToCil(grin2cil)}) 103 +%%] 100 104   101 105  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 102 106  %%% Compilerdriver entry point @@ -183,6 +187,13 @@ doCompileGrin input opts 183 187  ; caWriteLLVM 184 188  } 185 189  ) 190 +%%[[(8 codegen clr) 191 + ; when (ehcOptEmitCLR options)  192 + (do { caGrin2Cil 193 + ; caWriteCil "" 194 + } 195 + ) 196 +%%]] 186 197  ; caWriteSilly "" "c" prettyC ehcOptEmitC 187 198  -- ; caWriteSilly "" "s" prettyS ehcOptEmitC 188 199  } @@ -196,6 +207,11 @@ initState opts 196 207  = GRINCompileState { gcsGrin = undefined 197 208  , gcsSilly = undefined 198 209  , gcsLLVM = undefined 210 +%%] 211 +%%[(8 codegen clr) 212 + , gcsCil = undefined 213 +%%] 214 +%%[(8 codegen grin) -1.doCompileGrin 199 215  , gcsHptMap = undefined 200 216  , gcsPath = emptyFPath 201 217  , gcsOpts = opts @@ -259,6 +275,18 @@ caSilly2LLVM = do 259 275  } 260 276  %%] 261 277   278 +%%[(8 codegen clr) 279 +caGrin2Cil :: CompileAction () 280 +caGrin2Cil = do 281 + { code <- gets gcsGrin 282 + ; hptMap <- gets gcsHptMap 283 + ; opts <- gets gcsOpts 284 + ; let cilAst = grin2cil hptMap code opts 285 + ; modify (gcsUpdateCil cilAst) 286 + } 287 + 288 +%%] 289 + 262 290  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 263 291  %%% Low level compiler actions: output 264 292  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -279,7 +307,15 @@ caWriteLLVM :: CompileAction() 279 307  caWriteLLVM = 280 308  do { llvm <- gets gcsLLVM 281 309  ; caWriteFile "" "ll" (const prettyLLVMModule) llvm 282 - }  310 + } 311 + 312 +%%[[(8 codegen clr) 313 +caWriteCil :: String -> CompileAction() 314 +caWriteCil extra = 315 + do { cilAst <- gets gcsCil 316 + ; caWriteFile extra "il" (const (\c -> text (cil c ""))) cilAst 317 + } 318 +%%]] 283 319   284 320  caWriteGrin :: String -> CompileAction () 285 321  caWriteGrin extra @@ -327,6 +363,9 @@ data GRINCompileState = GRINCompileState 327 363  { gcsGrin :: GrModule 328 364  , gcsSilly :: SilModule 329 365  , gcsLLVM :: LLVMModule 366 +%%[[(8 codegen clr) 367 + , gcsCil :: Assembly 368 +%%]] 330 369  , gcsHptMap :: HptMap 331 370  , gcsPath :: FPath 332 371  , gcsOpts :: EHCOpts @@ -335,6 +374,9 @@ data GRINCompileState = GRINCompileState 335 374  gcsUpdateGrin x s = s { gcsGrin = x } 336 375  gcsUpdateSilly x s = s { gcsSilly = x } 337 376  gcsUpdateLLVM x s = s { gcsLLVM = x } 377 +%%[[(8 codegen clr) 378 +gcsUpdateCil x s = s { gcsCil = x } 379 +%%]] 338 380  gcsUpdateHptMap x s = s { gcsHptMap = x } 339 381   340 382  gcsGetCodeHpt
6  EHC/src/ehc/GrinCode/Common.chs
 @@ -17,7 +17,7 @@ 17 17  %% Special names %% 18 18  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 19 19   20 -%%[(8 codegen grin) export(wildcardNm, wildcardNr, mainNr, getNr, throwTag, hsnMainFullProg) 20 +%%[(8 codegen grin) export(wildcardNm, wildcardNr, mainNr, getNr, throwTag, hsnMainFullProg, conName) 21 21   22 22  wildcardNm = HNm "_" 23 23  wildcardNr = HNmNr 0 (OrigLocal wildcardNm) @@ -185,7 +185,7 @@ type Limitations = [Limitation] 185 185  %% Abstract interpretation result %% 186 186  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 187 187   188 -%%[(8 codegen grin) export(HptMap, getBaseEnvList, getEnvVar, absFetch, addEnvElems, getEnvSize, getTags, getNodes, isBottom, showHptMap, isPAppTag, isFinalTag, isApplyTag, filterTaggedNodes, getApplyNodeVars) 188 +%%[(8 codegen grin) export(HptMap, getBaseEnvList, getEnvVar, getHeapLoc, absFetch, addEnvElems, getEnvSize, getTags, getNodes, isBottom, showHptMap, isPAppTag, isFinalTag, isApplyTag, filterTaggedNodes, getApplyNodeVars) 189 189   190 190  type HptMap = ( Array Int AbstractValue -- env 191 191  , Array Int AbstractValue -- heap @@ -231,7 +231,7 @@ absFetch a (HNmNr i _) = case getEnvVar a i of 231 231  AbsBottom -> AbsNodes Map.empty 232 232  AbsError s -> error $"analysis error absFetch: " ++ show a ++ s 233 233  AbsBasic -> error$ "variable " ++ show i ++ " is a basic value" 234 - AbsNodes _ -> error $"variable " ++ show i ++ "is a node variable" 234 + AbsNodes _ -> error$ "variable " ++ show i ++ " is a node variable" 235 235  absFetch a x = error ("absFetch tried on " ++ show x) 236 236   237 237  getTags av = case av of
1  EHC/src/ehc/files-ag-s.dep
 @@ -54,6 +54,7 @@ GrinCode/Pretty.cag 54 54  GrinCode/FreeVars.cag 55 55  GrinCode/PointsToAnalysis.cag 56 56  GrinCode/ToGrinByteCode.cag 57 +GrinCode/ToCil.cag 57 58  GrinCode/ToSilly.cag 58 59  GrinCode/Trf/ForceEval.cag 59 60  GrinCode/Trf/AliasElim.cag
1  EHC/src/ehc/files1.mk
 @@ -55,6 +55,7 @@ EHC_HS_MAIN_DRV_HS := $(patsubst$(SRC_EHC_PREFIX)%.chs,$(EHC_BLD_VARIANT_A 55 55  EHC_HS_UTIL_SRC_CHS :=$(patsubst %,$(SRC_EHC_PREFIX)%.chs,\ 56 56  Substitutable Gam VarMp Deriving Module Config BuiltinPrims NameAspect DerivationTree CHR Pred \ 57 57 $(addprefix CHR/,Key Constraint Solve) \ 58 + $(addprefix Cil/,Common TyTag) \ 58 59 $(addprefix Pred/,ToCHR CHR Evidence EvidenceToCore Heuristics CommonCHR RedGraph) \ 59 60  $(addprefix Base/,Opts Target BasicAnnot Common Builtin Builtin2 HsName Debug Trie CfgPP ForceEval LaTeX HtmlCommon Binary) \ 60 61 $(addprefix Scanner/,Common Machine Scanner Token TokenParser) \
2  EHC/src/ehc/variant.mk
 @@ -6,7 +6,7 @@ 6 6  # aspects, EHC_ASPECTS to be configured at top level, for now here 7 7  ########################################################################################### 8 8   9 -EHC_ASPECTS := $(if$(ASPECTS),$(ASPECTS),base hmtyinfer codegen grin noHmTyRuler$(if $(ENABLE_JAVA),java jazy,)) 9 +EHC_ASPECTS :=$(if $(ASPECTS),$(ASPECTS),base hmtyinfer codegen grin noHmTyRuler $(if$(ENABLE_JAVA),java jazy,) $(if$(ENABLE_CLR),clr,)) 10 10  EHC_ASPECTS_SUFFIX := $(if$(ASPECTS),-$(subst$(space),-,$(ASPECTS)),) 11 11  EHC_ASPECTS_SUFFIX2 :=$(subst -,,$(EHC_ASPECTS_SUFFIX)) 12 12   9  EHC/test/clr/1-add/Test.hs  ... ... @@ -0,0 +1,9 @@ 1 +module Main where 2 + 3 +foreign import ccall "primAddInt" (+) :: Int -> Int -> Int 4 + 5 +inc :: Int -> Int 6 +inc x = x + 1 7 + 8 +main = inc 41 9 + 16  EHC/test/clr/2-datatypes/Test.hs  ... ... @@ -0,0 +1,16 @@ 1 +module Main where 2 + 3 +data MyData = 4 + One Int 5 + | Two Int Int 6 + | Three Int Int Int 7 + | Four Int Int Int Int 8 + 9 +first :: MyData -> Int 10 +first (One i) = i 11 +first (Two i _) = i 12 +first (Three i _ _) = i 13 +first (Four i _ _ _) = i 14 + 15 +main = first (Two 7 3) 16 + 20  EHC/test/clr/3-functioncalls/Test.hs  ... ... @@ -0,0 +1,20 @@ 1 +module Main where 2 + 3 +foreign import ccall "primAddInt" (+) :: Int -> Int -> Int 4 + 5 +inc :: Int -> Int 6 +inc x = x + 1 7 + 8 +data List = 9 + Nil 10 + | Cons Int List 11 + 12 +length :: List -> Int 13 +length Nil = 0 14 +length (Cons x xs) = inc (length xs) 15 + 16 +five :: List 17 +five = Cons 1 (Cons 2 (Cons 3 (Cons 4 (Cons 5 Nil)))) 18 + 19 +main = length five 20 + 22  EHC/test/clr/4-tailcall/Test.hs  ... ... @@ -0,0 +1,22 @@ 1 +module Main where 2 + 3 +foreign import ccall primAddInt :: Int -> Int -> Int 4 + 5 +inc :: Int -> Int 6 +inc x = primAddInt x 1 7 + 8 +data List = 9 + Nil 10 + | Cons Int List 11 + 12 +length :: List -> Int 13 +length = length' 0 14 + where 15 + length' x Nil = x 16 + length' x (Cons y ys) = length' (inc x) ys 17 + 18 +five :: List 19 +five = Cons 1 (Cons 2 (Cons 3 (Cons 4 (Cons 5 Nil)))) 20 + 21 +main = length five 22 + 13  EHC/test/clr/5-actualthunks/Test.hs  ... ... @@ -0,0 +1,13 @@ 1 +module Main where 2 + 3 +foreign import ccall primAddInt :: Int -> Int -> Int 4 + 5 +inc :: Int -> Int 6 +inc x = primAddInt x 1 7 + 8 +add = primAddInt 9 + 10 +f x = add x x 11 + 12 +main = f (inc 41) 13 + 25  EHC/test/clr/6-datatypethunks/Test.hs  ... ... @@ -0,0 +1,25 @@ 1 +module Main where 2 + 3 +foreign import ccall "primAddInt" (+) :: Int -> Int -> Int 4 + 5 +data Maybe = 6 + Nothing 7 + | Just Int 8 + 9 +double :: Int -> Int 10 +double x = x + x 11 + 12 +doubleJust :: Maybe -> Int 13 +doubleJust (Just x) = double x 14 +doubleJust Nothing = 42 15 + 16 +pick :: Maybe -> Maybe -> Maybe 17 +pick Nothing m = m 18 +pick m Nothing = m 19 +pick m _ = m 20 + 21 +split :: Maybe -> Maybe 22 +split m = pick m m  23 + 24 +main = doubleJust (split (Just 3)) 25 + 15  EHC/test/clr/7-papps/Test.hs  ... ... @@ -0,0 +1,15 @@ 1 +module Main where 2 + 3 +foreign import ccall primAddInt :: Int -> Int -> Int 4 + 5 +inc :: Int -> Int 6 +inc x = primAddInt x 1 7 + 8 +add = primAddInt 9 + 10 +f x y z = add z x 11 + 12 +g x = f 3 x 13 + 14 +main = g (inc 41) 4 15 + 37  EHC/test/clr/8-fib/Test.hs  ... ... @@ -0,0 +1,37 @@ 1 +module Main where 2 + 3 +data Bool = False | True 4 + 5 +data ''[]'' a = a : [a] | ''[]'' 6 + 7 +foreign import ccall "primAddInt" (+) :: Int -> Int -> Int 8 +foreign import ccall "primSubInt" (-) :: Int -> Int -> Int 9 +foreign import ccall "primEqInt" (==) :: Int -> Int -> Bool 10 + 11 +infixr 6 : 12 + 13 +zipWith :: (Int -> Int -> Int) -> [Int] -> [Int] -> [Int] 14 +zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys 15 +zipWith _ _ _ = [] 16 + 17 +sum :: [Int] -> Int 18 +sum [] = 0 19 +sum (x:xs) = x + sum xs 20 + 21 +tail :: [Int] -> [Int] 22 +tail [] = [] 23 +tail (x:xs) = xs 24 + 25 +take :: Int -> [Int] -> [Int] 26 +take _ [] = [] 27 +take n (x:xs) = if n == 0 28 + then [] 29 + else x : take (n-1) xs 30 + 31 +length [] = 0 32 +length (_:xs) = 1 + length xs 33 + 34 +fibs = 0 : 1 : zipWith (+) fibs (tail fibs) 35 + 36 +main = sum (take 5 fibs) 37 + 17  EHC/test/clr/9-parity/Test.hs  ... ... @@ -0,0 +1,17 @@ 1 +module Main where 2 + 3 +data Bool = False | True 4 + 5 +foreign import ccall "primSubInt" (-) :: Int -> Int -> Int 6 +foreign import ccall "primEqInt" (==) :: Int -> Int -> Bool 7 + 8 +even :: Int -> Bool 9 +even x | x == 0 = True 10 + | True = odd (x - 1) 11 + 12 +odd :: Int -> Bool 13 +odd x | x == 0 = False 14 + | True = even (x - 1) 15 + 16 +main = even 100000000 17 + 89  EHC/text/InternalDocEhcTechnical.cltex  @@ -4,6 +4,7 @@ 4 4  %%@InternalDocEhcTechnical.GrinCode 5 5  %%@InternalDocEhcTechnical.Silly 6 6  %%@InternalDocEhcTechnical.JVMClass 7 +%%@InternalDocEhcTechnical.CLR 7 8  %%] 8 9   9 10   @@ -253,3 +254,91 @@ The following transformations are performed on the Silly program: 253 254  %%] 254 255   255 256   257 +%%[CLR 258 + 259 +\section{CLR backend} 260 + 261 +The CLR backend is a highly experimental backend for the EHC developed during the Advanced Compiler Construction seminar in early 2009. 262 + 263 +\subsection{Overview} 264 + 265 +\subsubsection{Common Language Runtime} 266 + 267 +The Common Language Runtime (CLR) is a runtime system, developed by Microsoft as .NET, that runs managed code. It exposes facilities such as a common type system, memory management and just in time compilation. Currently the three most promiment implementations are: 268 + 269 +\begin{itemize} 270 + \item .NET on the Windows desktop 271 + \item Mono under Linux/OSX machines 272 + \item Silverlight for running in the browser on Windows and OSX 273 +\end{itemize} 274 + 275 +\subsubsection{EHC backend} 276 +The experimental backend adds a new target to generate assembly files for the CLR. Using the flag \verb"-tclr", the compiler can be directed to generate \verb".il" files that contain Common Intermediate Langauge (aka MSIL) assembly code. 277 + 278 +These \verb".il" files can be assembled into \verb".exe" files using \verb"ilasm.exe" under Windows (available in \verb"%WINDOWS%\Microsoft.NET\Framework\v2.0.50727\") and \verb"ilasm2" under Linux/OSX (available through Mono). 279 + 280 +Here is a running scenario: 281 +\begin{verbatim} 282 +$ cat > Test.hs 283 +const x y = x 284 +main = const 8 15 285 +^C 286 +$EHC/install/8/bin/ehc -tclr Test.hs 287 +$ ilasm2 Test.il 288 +\$ mono Test.exe 289 +Int 8 290 +\end{verbatim} 291 + 292 +\paragraph{Note:} This chapter describes some technical aspects of the implementation, but it doesn't describe the underlying ideas. 293 + 294 +Ideally, a new separate document will be written detailing the underlining concepts of the CLR backend. However, such a document doesn't yet exist, for now there are just the slides and a video from the authors from the \href{http://tom.lokhorst.eu/ehc/clr/}{final presentation} of the Advanced Compiler Construction seminar. 295 + 296 + 297 +\subsection{Architecture} 298 + 299 +Currently, the CLR backend only works in variant 8 of the EHC. Work is being done to get variant 100 to comipile. 300 + 301 +\subsubsection{language-cil} 302 +The CLR backend makes use of an external library called language-cil. This library exposes an AST, build functions and pretty printers for the Common Intermediate Language (CIL). 303 + 304 +This library will need to be installed before compiling the EHC. 305 + 306 +At some point in the future language-cil will be uploaded to Hackage, however currently it lives just in source control: \href{https://svn.cs.uu.nl:12443/repos/language-cil/tags/0.1.0/}{https://svn.cs.uu.nl:12443/repos/language-cil/tags/0.1.0/} 307 + 308 +\subsubsection{/src/ehc/Cil/Common.chs} 309 +%%@EHCilCommon.doesWhat 310 + 311 +\subsubsection{/src/ehc/Cil/TyTag.chs} 312 +%%@EHCilTyTag.doesWhat 313 + 314 +\subsubsection{/src/ehc/GrinCode/ToCil.chs} 315 +%%@EHGrinCodeToCil.doesWhat 316 + 317 +\subsection{Tests} 318 + 319 +In the directory \verb"/test/clr" are some CLR test cases, some of which don't compile anymore, see open issues. 320 + 321 +\subsection{Open issues} 322 + 323 +Some open bugs which haven't been resolved yet: 324 + 325 +\begin{itemize} 326 + \item \verb"/tests/5-tailcalls" Fails due to the fact that one tail call to many is generated. 327 + \item \verb"/tests/8-fibs" Fails. App TyTag isn't implemented yet (Con, Fun and PApp are). 328 +\end{itemize} 329 + 330 +\subsection{Todo} 331 + 332 +\begin{itemize} 333 + \item Add clr aspect 334 + \item Document conceptual ideas behind architectural choices. 335 + \item Remove \verb"ReferenceObject" indirection. 336 + \item Better support for primitive types, \verb"GrPatLam.EnumAnnot" is hardcoded to booleans. 337 + \item Become more stack-oriented (move to Silly?). 338 + \item Make use of stack allocated objects (Value types). 339 + \item Use more unboxed types, adding two integers shouldn't have to create 6 heap objects. 340 + \item Use generic types instead of using container types for primitives. 341 +\end{itemize} 342 + 343 +%%] 344 +

No commit comments for this range

Something went wrong with that request. Please try again.