shithub: MicroHs

Download patch

ref: b29c281fb78c5fec611a49f8e0b791d3e9c48264
parent: 0b9fc139e6268d7a8b9374592847903959d6c927
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Fri Sep 22 07:25:26 EDT 2023

Improve and document compilation process.

--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,10 @@
 	$(GHC) $(PROF) -hide-all-packages -package time -o $(BIN)/boot$(MHS) $(BOOTDIR)/*.o $(BOOTDIR)/*/*.o $(BOOTDIR)/*/*/*.o $(BOOTDIR)/*/*/*/*.o
 #	$(GHC) $(PROF) -hide-all-packages -package containers -o $(BIN)/boot$(MHS) $(BOOTDIR)/*.o $(BOOTDIR)/*/*.o $(BOOTDIR)/*/*/*/*.o
 
+# Self compile using comb/mhs.comb
+$(COMB)$(MHS)-new.comb: $(EVAL)
+	$(EVAL) +RTS -r$(COMB)$(MHS).comb -RTS -ilib -isrc -o$(COMB)$(MHS)-new.comb MicroHs.Main
+
 # Compare version compiled with normal GHC libraries and $(MHS) libraries
 bootboottest:	$(BIN)/$(MHS) $(BIN)/boot$(MHS)
 	$(BIN)/$(MHS)     -ilib -isrc -omain-$(MHS).comb  MicroHs.Main
--- a/README.md
+++ b/README.md
@@ -4,6 +4,17 @@
 
 The compiler can compile itself.
 
+## Compiling MicroHs
+There are three different ways to compile MicroHs
+* Using GHC with standard `Prelude` and libraries. `Makefile` target `bin/mhs`
+* Using GHC, but with `Prelude` and libraries from MicroHs. `Makefile` target `bin/bootmhs`
+* Using mhs, with the supplied `comb/mhs.comb`. `Makefile` target `comb/mhs-new.comb`
+These differenty ways need slightly different imports etc.  To accomodate this
+each source file is preprocessed for the first two targets.
+When compiling with GHC and standard libraries the strings `--X` and `--W` are removed from the source file.
+When compiling with GHC and MicroHs libraries the strings `--Y` and `--W` are removed from the source file.
+This way anything special needed with GHC is just treated as comments by mhs.
+
 ## Language
 The language is a subset of Haskell.  There is only simple Hindley-Milner polymorphism,
 no type classes (yet).
--- a/Tools/convertX.sh
+++ b/Tools/convertX.sh
@@ -1,2 +1,2 @@
 #!/bin/sh
-( echo "{-# LINE 1 \"$1\" #-}" ; sed -e 's/--X//' $2 ) > $3
+( echo "{-# LINE 1 \"$1\" #-}" ; sed -e 's/--[XW]//' $2 ) > $3
--- a/Tools/convertY.sh
+++ b/Tools/convertY.sh
@@ -1,2 +1,2 @@
 #!/bin/sh
-( echo "{-# LINE 1 \"$1\" #-}" ; sed -e 's/--Y//' $2 ) > $3
+( echo "{-# LINE 1 \"$1\" #-}" ; sed -e 's/--[YW]//' $2 ) > $3
--- a/src/MicroHs/Exp.hs
+++ b/src/MicroHs/Exp.hs
@@ -29,8 +29,7 @@
   | Lit Lit
   --Xderiving (Show, Eq)
 
---Xinstance NFData Exp where rnf (Var i) = rnf i; rnf (App f a) = rnf f `seq` rnf a; rnf (Lam i e) = rnf i `seq` rnf e; rnf (Lit l) = rnf l
---Yinstance NFData Exp where rnf (Var i) = rnf i; rnf (App f a) = rnf f `seq` rnf a; rnf (Lam i e) = rnf i `seq` rnf e; rnf (Lit l) = rnf l
+--Winstance NFData Exp where rnf (Var i) = rnf i; rnf (App f a) = rnf f `seq` rnf a; rnf (Lam i e) = rnf i `seq` rnf e; rnf (Lit l) = rnf l
 
 eqExp :: Exp -> Exp -> Bool
 eqExp (Var i1) (Var i2) = eqIdent i1 i2
--- a/src/MicroHs/Expr.hs
+++ b/src/MicroHs/Expr.hs
@@ -136,8 +136,7 @@
   | LPrim String
   | LForImp String
   --Xderiving (Show, Eq)
---Xinstance NFData Lit where rnf (LInt i) = rnf i; rnf (LChar c) = rnf c; rnf (LStr s) = rnf s; rnf (LPrim s) = rnf s; rnf (LForImp s) = rnf s
---Yinstance NFData Lit where rnf (LInt i) = rnf i; rnf (LChar c) = rnf c; rnf (LStr s) = rnf s; rnf (LPrim s) = rnf s; rnf (LForImp s) = rnf s
+--Winstance NFData Lit where rnf (LInt i) = rnf i; rnf (LChar c) = rnf c; rnf (LStr s) = rnf s; rnf (LPrim s) = rnf s; rnf (LForImp s) = rnf s
 
 eqLit :: Lit -> Lit -> Bool
 eqLit (LInt x)  (LInt  y) = x == y
--- a/src/MicroHs/Ident.hs
+++ b/src/MicroHs/Ident.hs
@@ -26,8 +26,7 @@
 
 data Ident = Ident SLoc String
   --Xderiving (Show, Eq)
---Xinstance NFData Ident where rnf (Ident _ s) = rnf s
---Yinstance NFData Ident where rnf (Ident _ s) = rnf s
+--Winstance NFData Ident where rnf (Ident _ s) = rnf s
 
 noSLoc :: SLoc
 noSLoc = SLoc "" 0 0
--- a/src/MicroHs/Translate.hs
+++ b/src/MicroHs/Translate.hs
@@ -10,8 +10,7 @@
 --Ximport GHC.Types
 import Unsafe.Coerce
 --Ximport Compat
---Ximport PrimTable
---Yimport PrimTable
+--Wimport PrimTable
 
 import MicroHs.Expr
 import MicroHs.Exp
--