ref: 121e692078d17da589d60cc9051c49704fb9c833
parent: 1425fe4bc7537b25d58804a9de016c9c56f0273e
author: Lennart Augustsson <lennart@augustsson.net>
date: Sun Sep 17 03:36:02 EDT 2023
A little Makefile cleanup.
--- a/Makefile
+++ b/Makefile
@@ -16,22 +16,31 @@
MHS=mhs
COMB=comb/
EVAL=$(BIN)/eval
-.PHONY: all alltest everytest boottest bootboottest bootcombtest $(MHS)test test alltest time example bootstraptest
+.PHONY: all alltest everytest runtest bootboottest bootcombtest $(MHS)test test alltest time example bootstraptest
all: $(EVAL) $(BIN)/$(MHS)
-alltest: test boottest
+everytest: runtest example exampleboot examplecomb bootboottest bootcombtest
-everytest: alltest example exampleboot examplecomb bootboottest bootcombtest
-
+###
+### Build evaluator (runtime system)
+###
# On MINGW you might need the additional flags -Wl,--stack,50000000 to increase stack space.
$(EVAL): src/runtime/eval.c
@mkdir -p bin
$(GCC) -Wall -O3 src/runtime/eval.c -o $(EVAL)
+###
+### Build the compiler with ghc, using standard libraries (Prelude, Data.List, etc)
+###
$(BIN)/$(MHS): src/*.hs src/*/*.hs $(TOOLS)/convertX.sh
$(GHCE) -isrc -Wall -O src/MicroHs/Main.hs -main-is MicroHs.Main -o $(BIN)/$(MHS)
+###
+### Build the compiler with ghc, using MicroHs libraries (Prelude, Data.List, etc)
+###
+# Due to a ghc bug we need to list all the commands.
+# The bug is that OPTIONS_GHC does not accept the -package flag.
$(BIN)/boot$(MHS): $(ALLSRC) $(TOOLS)/convertY.sh
rm -rf $(BOOTDIR)
$(GHCB) -c ghc/Primitives.hs
@@ -79,10 +88,6 @@
$(GHC) $(PROF) -hide-all-packages -package time -o $(BIN)/boot$(MHS) $(BOOTDIR)/*.o $(BOOTDIR)/*/*.o $(BOOTDIR)/*/*/*/*.o
# $(GHC) $(PROF) -hide-all-packages -package containers -o $(BIN)/boot$(MHS) $(BOOTDIR)/*.o $(BOOTDIR)/*/*.o $(BOOTDIR)/*/*/*/*.o
-# Test Haskell version with local libraries
-boottest: $(BIN)/boot$(MHS)
- $(BIN)/boot$(MHS) -ilib Example
-
# 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
@@ -95,15 +100,23 @@
$(EVAL) +RTS -v -r$(COMB)$(MHS).comb -RTS -ilib -isrc -omain-comb.comb MicroHs.Main
cmp main-$(MHS).comb main-comb.comb
-# Test normal Haskell version
-test: $(EVAL) $(BIN)/$(MHS) tests/*.hs
+###
+### Run test examples with ghc-compiled compiler
+###
+runtest: $(EVAL) $(BIN)/$(MHS) tests/*.hs
cd tests; make test
+###
+### Run test examples with MicroHs compiler
+###
+runtestcomb: $(EVAL) $(COMB)$(MHS).comb
+ cd tests; make MHS='../$(EVAL) +RTS -r../$(COMB)$(MHS).comb -RTS -i../lib'
+
+###
+### Build combinator file for the compiler, using ghc-compiled compiler
+###
$(COMB)$(MHS).comb: $(BIN)/$(MHS) $(ALLSRC)
$(BIN)/$(MHS) -ilib -isrc -o$(COMB)$(MHS).comb MicroHs.Main
-
-$(MHS)comp: $(EVAL) $(COMB)$(MHS).comb
- $(EVAL) +RTS -v -r$(COMB)$(MHS).comb -RTS $(ARG)
time: $(EVAL) $(BIN)/$(MHS) tests/*.hs
cd tests; make time
--- a/comb/mhs.comb
+++ b/comb/mhs.comb
@@ -1,3 +1,3 @@
v3.3
824
-(($A :0 ((_626 _579) (($B ((($S' ($C ((($C' ($S' _626)) (($B ($C _2)) _564)) (($B ($B (_626 _654))) ((($C' ($C' $C)) ((($C' ($S' ($C' $C))) ((($C' ($C' ($C' $C))) ((($C' ($C' ($C' ($C' $S')))) (($B ($B ($B ($B $C)))) ((($C' ($C' ($C' $B))) (($B ($B ($B ($C' $S)))) ((($C' ($C' ($C' ($C' $C)))) ((($C' ($C' ($C' ($C' ($C' $S'))))) (($B ($B ($B ($B ($B $C))))) ((($C' ($C' ($C' ($C' ($C' $C))))) ((($C' ($C' ($C' $B))) (($B ($B ($B ($C' ($C' $S'))))) ((($C' ($C' ($C' ($C' ($C' $C'))))) ((($C' ($C' ($C' ($S' ($C' $C'))))) (($B ($B ($B ($B $B')))) ((($S' $B) ($B' ($B' (($B ($S' $B)) (($B ($B _627)) ((($C' $B) (($B _721) (($B _644) ((($C' _759) _8) 0)))) (($B (_721 _647)) (($B (_660 "top level defns: ")) _608)))))))) ((($S' $B) ($B' (($B ($C' $B)) (($B $B') (($B ($B _627)) ((($C' $B) (($B _721) (($B _644) ((($C' _759) _8) 1)))) (_643 ($T (($B ($B (_721 _647))) ((($C' $B) (($B _660) ((($C' _660) _569) " = "))) _396)))))))))) ((($C' $B) ((($S' $C') (($B $C') (($B $C') _9))) ((($S' $B) (($B ($C' ($C' _627))) ((($C' $B) ($B' (($B _721) (($B _649) _11)))) (($B _660) ((($C' _660) (($B (_660 _1)) _608)) (($O 10) $K)))))) (($B ($B (_626 _654))) ((($C' $B) ($B' (($B _721) (($B _644) ((($C' _759) _8) 0))))) (($B ($B (_721 _647))) ((($C' ($C' _660)) (($B ($B (_660 "final pass "))) (($B ($B (_621 6))) (($B ($B _608)) _753)))) "ms"))))))) _3))))) (($B (($C' $C) (($B ($C _665)) _396))) (($C _678) (_695 0))))) (($B ($C $B)) (($B ($B ($C $B))) (($B ($B $BK)) ((($C' ($C' ($C' ($C' _660)))) (($B ($C' ($C' _660))) ((($C' ($C' ($C' _660))) (($B (($C' $B) (($B _660) ((($C' _660) (($B (_660 "(($A :")) _608)) (($O 32) $K))))) ($B _396))) ") "))) (($O 41) $K)))))))) $T)) (($B $Y) ((($C' ($C' $S)) ((($C' ($C' $S)) ((($C' $B) $P) ((($S' ($C' $B)) ($B _372)) $I))) ($BK $K))) $K))))) (($B (($S' _721) (($B _718) (($B (_721 _768)) (($B (_660 "main: findIdent: ")) _569))))) (($C' _598) _566)))) _605))) (($B ($B _602)) ((($C' $B) (($B _662) (($B $T) (($B ($C $B)) (($B ($B $BK)) ((($C' ($C' ($C' $O))) ($B (($C' $P) _566))) $K)))))) (($C _678) (_695 0))))))) ($T $A))) ($T $K))) $I)) (($B (_721 _371)) (($B (_721 _564)) (($B (_660 (($O 95) $K))) _608)))))))) (($S (($S ((($S' _7) (($B _677) (_664 (_619 "-v")))) ((_694 _619) "-r"))) (($B (_658 (($O 46) $K))) (($B _720) (_663 ((_682 _744) "-i")))))) (($B (_721 _689)) ((($C' _660) (($B _720) (_663 ((_682 _744) "-o")))) (($O "out.comb") $K))))) (($B (($S (($C ((($C' _755) _677) 1)) (_768 "Usage: uhs [-v] [-r] [-iPATH] [-oFILE] ModuleName"))) _689)) (_664 ((_722 _764) ((_722 (_619 (($O 45) $K))) (_675 1))))))) (_685 ((_722 _764) (_619 "--")))))) (($A :1 "v3.3\10&") (($A :2 ((($S' ($S' _626)) _16) (($B ($B ($B (_626 _654)))) ((($C' ($C' $B)) (($B ($B ($C' (($S' _627) (($B (_721 _645)) (($B (_721 (_676 1000000))) _192)))))) (($B ($B ($B ($B (_626 _654))))) ((($C' $B) (($B ($C' $B)) (($B ($B ($C' _627))) ((($C' $B) ($B' (($B _721) (($B _644) ((($C' _759) _8) 0))))) (($B ($B (_721 _647))) ((($C' ($C' _660)) (($B ($B (_660 "combinator conversion "))) (($B ($B (_621 6))) (($B ($B _608)) _753)))) "ms")))))) (($B ($B _628)) (($B $P) (($C _572) (_564 "main")))))))) (_662 ($T ((($C' ($C' $O)) ((($C' $B) $P) _399)) $K))))))) (($A :3 ($T (($C ((($C' $C') (($B ($S' ($B (_626 _579)))) (($B ($B ($B (($C' _580) ((($C' _748) (($B _677) (_685 ((_722 _764) (_619 "--"))))) 1))))) (($B ($B ($B (_721 _6)))) ($C $C))))) (($B ($B $Y)) (($B ($B ($B _555))) (($C' ($C' _662)) (($B ($B $T)) ((($C' ($C' ($C' ($C' $O)))) (($B ($B (($C' $B) $P))) ($B _4))) $K))))))) (($B (($S' _721) (($B _718) (($B (_721 _768)) (($B (_660 "not found ")) _569))))) ($C _556))))) (($A :4 ((($C' $C) ((($S' $C) ((($C' ($C' $S')) (($S $P) ((($S' ($C' $B)) (($B ($B _6)) _4)) _4))) ($BK $K))) ((($C' ($S' $C)) ((($C' ($C' $C)) (($B (($C' $C) (($B ($P _6)) $K))) ((($C' $B) _4) _398))) (($B (_721 (_718 (_768 "primlookup")))) (($C (_700 _619)) _5)))) $K))) (_768 "trans: impossible"))) (($A :5 (($O (($P (($O 66) $K)) $B)) (($O (($P (($O 79) $K)) $O)) (($O (($P (($O 75) $K)) $K)) (($O (($P "C'") $C')) (($O (($P (($O 67) $K)) $C)) (($O (($P (($O 65) $K)) $A)) (($O (($P "
\ No newline at end of file
+(($A :0 ((_626 _579) (($B ((($S' ($C ((($C' ($S' _626)) (($B ($C _2)) _564)) (($B ($B (_626 _654))) ((($C' ($C' $C)) ((($C' ($S' ($C' $C))) ((($C' ($C' ($C' $C))) ((($C' ($C' ($C' ($C' $S')))) (($B ($B ($B ($B $C)))) ((($C' ($C' ($C' $B))) (($B ($B ($B ($C' $S)))) ((($C' ($C' ($C' ($C' $C)))) ((($C' ($C' ($C' ($C' ($C' $S'))))) (($B ($B ($B ($B ($B $C))))) ((($C' ($C' ($C' ($C' ($C' $C))))) ((($C' ($C' ($C' $B))) (($B ($B ($B ($C' ($C' $S'))))) ((($C' ($C' ($C' ($C' ($C' $C'))))) ((($C' ($C' ($C' ($S' ($C' $C'))))) (($B ($B ($B ($B $B')))) ((($S' $B) ($B' ($B' (($B ($S' $B)) (($B ($B _627)) ((($C' $B) (($B _721) (($B _644) ((($C' _759) _8) 0)))) (($B (_721 _647)) (($B (_660 "top level defns: ")) _608)))))))) ((($S' $B) ($B' (($B ($C' $B)) (($B $B') (($B ($B _627)) ((($C' $B) (($B _721) (($B _644) ((($C' _759) _8) 1)))) (_643 ($T (($B ($B (_721 _647))) ((($C' $B) (($B _660) ((($C' _660) _569) " = "))) _396)))))))))) ((($C' $B) ((($S' $C') (($B $C') (($B $C') _9))) ((($S' $B) (($B ($C' ($C' _627))) ((($C' $B) ($B' (($B _721) (($B _649) _11)))) (($B _660) ((($C' _660) (($B (_660 _1)) _608)) (($O 10) $K)))))) (($B ($B (_626 _654))) ((($C' $B) ($B' (($B _721) (($B _644) ((($C' _759) _8) 0))))) (($B ($B (_721 _647))) ((($C' ($C' _660)) (($B ($B (_660 "final pass "))) (($B ($B (_621 6))) (($B ($B _608)) _753)))) "ms"))))))) _3))))) (($B (($C' $C) (($B ($C _665)) _396))) (($C _678) (_695 0))))) (($B ($C $B)) (($B ($B ($C $B))) (($B ($B $BK)) ((($C' ($C' ($C' ($C' _660)))) (($B ($C' ($C' _660))) ((($C' ($C' ($C' _660))) (($B (($C' $B) (($B _660) ((($C' _660) (($B (_660 "(($A :")) _608)) (($O 32) $K))))) ($B _396))) ") "))) (($O 41) $K)))))))) $T)) (($B $Y) ((($C' ($C' $S)) ((($C' ($C' $S)) ((($C' $B) $P) ((($S' ($C' $B)) ($B _372)) $I))) ($BK $K))) $K))))) (($B (($S' _721) (($B _718) (($B (_721 _768)) (($B (_660 "main: findIdent: ")) _569))))) (($C' _598) _566)))) _605))) (($B ($B _602)) ((($C' $B) (($B _662) (($B $T) (($B ($C $B)) (($B ($B $BK)) ((($C' ($C' ($C' $O))) ($B (($C' $P) _566))) $K)))))) (($C _678) (_695 0))))))) ($T $A))) ($T $K))) $I)) (($B (_721 _371)) (($B (_721 _564)) (($B (_660 (($O 95) $K))) _608)))))))) (($S (($S ((($S' _7) (($B _677) (_664 (_619 "-v")))) ((_694 _619) "-r"))) (($B (_658 (($O 46) $K))) (($B _720) (_663 ((_682 _744) "-i")))))) (($B (_721 _689)) ((($C' _660) (($B _720) (_663 ((_682 _744) "-o")))) (($O "out.comb") $K))))) (($B (($S (($C ((($C' _755) _677) 1)) (_768 "Usage: mhs [-v] [-r] [-iPATH] [-oFILE] ModuleName"))) _689)) (_664 ((_722 _764) ((_722 (_619 (($O 45) $K))) (_675 1))))))) (_685 ((_722 _764) (_619 "--")))))) (($A :1 "v3.3\10&") (($A :2 ((($S' ($S' _626)) _16) (($B ($B ($B (_626 _654)))) ((($C' ($C' $B)) (($B ($B ($C' (($S' _627) (($B (_721 _645)) (($B (_721 (_676 1000000))) _192)))))) (($B ($B ($B ($B (_626 _654))))) ((($C' $B) (($B ($C' $B)) (($B ($B ($C' _627))) ((($C' $B) ($B' (($B _721) (($B _644) ((($C' _759) _8) 0))))) (($B ($B (_721 _647))) ((($C' ($C' _660)) (($B ($B (_660 "combinator conversion "))) (($B ($B (_621 6))) (($B ($B _608)) _753)))) "ms")))))) (($B ($B _628)) (($B $P) (($C _572) (_564 "main")))))))) (_662 ($T ((($C' ($C' $O)) ((($C' $B) $P) _399)) $K))))))) (($A :3 ($T (($C ((($C' $C') (($B ($S' ($B (_626 _579)))) (($B ($B ($B (($C' _580) ((($C' _748) (($B _677) (_685 ((_722 _764) (_619 "--"))))) 1))))) (($B ($B ($B (_721 _6)))) ($C $C))))) (($B ($B $Y)) (($B ($B ($B _555))) (($C' ($C' _662)) (($B ($B $T)) ((($C' ($C' ($C' ($C' $O)))) (($B ($B (($C' $B) $P))) ($B _4))) $K))))))) (($B (($S' _721) (($B _718) (($B (_721 _768)) (($B (_660 "not found ")) _569))))) ($C _556))))) (($A :4 ((($C' $C) ((($S' $C) ((($C' ($C' $S')) (($S $P) ((($S' ($C' $B)) (($B ($B _6)) _4)) _4))) ($BK $K))) ((($C' ($S' $C)) ((($C' ($C' $C)) (($B (($C' $C) (($B ($P _6)) $K))) ((($C' $B) _4) _398))) (($B (_721 (_718 (_768 "primlookup")))) (($C (_700 _619)) _5)))) $K))) (_768 "trans: impossible"))) (($A :5 (($O (($P (($O 66) $K)) $B)) (($O (($P (($O 79) $K)) $O)) (($O (($P (($O 75) $K)) $K)) (($O (($P "C'") $C')) (($O (($P (($O 67) $K)) $C)) (($O (($P (($O 65) $K)) $A)) (($O (($P "
\ No newline at end of file
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -5,18 +5,18 @@
test:
$(MHS) IOTest && (echo q | $(EVAL) a bb ccc | sed 's/^.ms/1ms/' > IOTest.out) && diff IOTest.ref IOTest.out
$(MHS) StringTest && $(EVAL) > StringTest.out && diff StringTest.ref StringTest.out
- $(MHS) ListTest && $(EVAL) > ListTest.out && diff ListTest.ref ListTest.out
- $(MHS) Fac && $(EVAL) > Fac.out && diff Fac.ref Fac.out
- $(MHS) Misc && $(EVAL) > Misc.out && diff Misc.ref Misc.out
- $(MHS) Case && $(EVAL) > Case.out && diff Case.ref Case.out
- $(MHS) Arith && $(EVAL) > Arith.out && diff Arith.ref Arith.out
- $(MHS) Guard && $(EVAL) > Guard.out && diff Guard.ref Guard.out
- $(MHS) Newtype && $(EVAL) > Newtype.out && diff Newtype.ref Newtype.out
- $(MHS) LitMatch && $(EVAL) > LitMatch.out && diff LitMatch.ref LitMatch.out
- $(MHS) Word && $(EVAL) > Word.out && diff Word.ref Word.out
- $(MHS) Enum && $(EVAL) > Enum.out && diff Enum.ref Enum.out
- $(MHS) Foreign && $(EVAL) > Foreign.out && diff Foreign.ref Foreign.out
- $(MHS) MutRec && $(EVAL) > MutRec.out && diff MutRec.ref MutRec.out
+ $(MHS) ListTest && $(EVAL) > ListTest.out && diff ListTest.ref ListTest.out
+ $(MHS) Fac && $(EVAL) > Fac.out && diff Fac.ref Fac.out
+ $(MHS) Misc && $(EVAL) > Misc.out && diff Misc.ref Misc.out
+ $(MHS) Case && $(EVAL) > Case.out && diff Case.ref Case.out
+ $(MHS) Arith && $(EVAL) > Arith.out && diff Arith.ref Arith.out
+ $(MHS) Guard && $(EVAL) > Guard.out && diff Guard.ref Guard.out
+ $(MHS) Newtype && $(EVAL) > Newtype.out && diff Newtype.ref Newtype.out
+ $(MHS) LitMatch && $(EVAL) > LitMatch.out && diff LitMatch.ref LitMatch.out
+ $(MHS) Word && $(EVAL) > Word.out && diff Word.ref Word.out
+ $(MHS) Enum && $(EVAL) > Enum.out && diff Enum.ref Enum.out
+ $(MHS) Foreign && $(EVAL) > Foreign.out && diff Foreign.ref Foreign.out
+ $(MHS) MutRec && $(EVAL) > MutRec.out && diff MutRec.ref MutRec.out
time:
@echo Expect about 10s runtime
--- a/tests/Nfib.hs
+++ b/tests/Nfib.hs
@@ -1,11 +1,13 @@
-module Nfib(module Nfib) where
+module Nfib(main) where
import Prelude
+nfib :: Int -> Int
nfib n =
case n < 2 of
False -> nfib (n - 1) + nfib (n - 2) + 1
True -> 1
+main :: IO ()
main = print (nfib 38)
-- Typical nfib/s is 10M
--
⑨