ref: 22e2124f4322b1b153824b1cd48831005a3e26cf
parent: 086e4cbf583554432cd110a7ada092c0a81318dc
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Wed Sep 27 10:48:17 EDT 2023
Add target to install compiler.
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+# installtion prefix
+PREFIX=/usr/local
BIN=bin
BOOTDIR=ghc-boot
OUTDIR=ghc-out
@@ -15,7 +17,7 @@
ALLSRC=src/*/*.hs lib/*.hs lib/*/*.hs ghc/*.hs ghc/*/*.hs
MHS=mhs
COMB=comb/
-EVAL=$(BIN)/eval
+EVAL=$(BIN)/mhseval
.PHONY: all alltest everytest runtest bootboottest bootcombtest $(MHS)test test alltest time example bootstraptest
all: $(EVAL) $(BIN)/$(MHS)
@@ -176,3 +178,21 @@
@echo Build stage 2 with output from stage 1
$(EVAL) +RTS -rtmp/mhs.comb.1 -RTS -ilib -isrc -otmp/mhs.comb.2 MicroHs.Main
cmp tmp/mhs.comb.1 tmp/mhs.comb.2 && echo Success
+
+# installs linraries the the following binaries:
+# bin/mhseval - the evaluator that can read a combinator file and run it
+# bin/mhsc - a compiler that produces a proper binary
+# bin/mhs - a compiler/repl that can compile to combinators
+install: $(EVAL)
+ mkdir -p $(PREFIX)/bin
+ cp $(EVAL) $(PREFIX)/bin
+ (echo "prefix=$(PREFIX)"; cat Tools/mhsc.sh) > $(PREFIX)/bin/mhsc
+ chmod +x $(PREFIX)/bin/mhsc
+ mkdir -p $(PREFIX)/lib/mhs/Tools
+ mkdir -p $(PREFIX)/lib/mhs/comb
+ mkdir -p $(PREFIX)/lib/mhs/src/runtime
+ cp Tools/* $(PREFIX)/lib/mhs/Tools
+ cp comb/mhs.comb $(PREFIX)/lib/mhs/comb
+ cp src/runtime/eval.c $(PREFIX)/lib/mhs/src/runtime
+ cp -r lib $(PREFIX)/lib/mhs
+ $(PREFIX)/bin/mhsc -v -isrc -o$(PREFIX)/bin/mhs MicroHs.Main
--- a/TODO
+++ b/TODO
@@ -11,9 +11,3 @@
* use pointer stack during GC instead of recursion.
* implement Data.Integer
* add pretty printing library
-* add a Makefile 'install' target
- - install libraries too
- - somehow get the path of libraries into the binary
-* change BFILE to have methods
-* add a compressor/decompressor for the combinator file
-* add a shell script to make a binary with (compressed) combinators included
--- a/Tools/Addcombs.hs
+++ b/Tools/Addcombs.hs
@@ -14,9 +14,13 @@
main :: IO ()
main = do
+{-args <- getArgs
let fn = case args of { [a] -> a; _ -> error "Usage: Addcombs file" }file <- readFile fn
+-}
+ hSetBinaryMode stdin True
+ file <- hGetContents stdin
let size = length file
chunks = chunkify 20 file
putStrLn $ "struct { BFILE mets; size_t b_size; size_t b_pos; uint8_t b_buffer[]; } combs =\n { { getb_buf, ungetb_buf, closeb_buf }, "--- a/Tools/Compress.hs
+++ b/Tools/Compress.hs
@@ -1,6 +1,6 @@
module Compress(main) where
import Prelude
-import Data.NMap as M
+import Data.Map as M
import Data.Char
import System.IO
--import Debug.Trace
@@ -52,4 +52,4 @@
f <- hGetContents stdin
let bs = compress initTable f []
hSetBinaryMode stdout True
- putStr $ map chr $ toBytes bs
+ putStr $ 'Z' : (map chr $ toBytes bs)
--- /dev/null
+++ b/Tools/mhsc.sh
@@ -1,0 +1,48 @@
+# Compile a file to combinators, then tack it on to the C evaluator
+# and compile the whole thing.
+# Assume everything has been installed in $prefix.
+# Depends on
+# $prefix/bin/mhseval
+# $prefix/lib/mhs/Tools/Compress.hs
+# $prefix/lib/mhs/Tools/Addcomb.hs
+# $prefix/lib/mhs/comb/mhs.comb
+# $prefix/lib/mhs/src/runtime/eval.c
+# $prefix/lib/mhs/lib/...
+cc=gcc
+here=`dirname $0`
+prefix="${prefix:=.}"+prefixmhs="$prefix/lib/mhs"
+
+compflags=""
+output=""
+while [ `expr substr "X$1" 1 2` = "X-" ]; do
+ if [ `expr substr "$1" 1 2` = "-o" ]; then
+ output="$1"
+ else
+ compflags="$compflags $1"
+ fi
+ shift
+done
+input="$1"
+if [ -z "$input" ]; then
+ echo "Usage: $0 [FLAGS] MODULE"
+ exit 1
+fi
+
+lib="-i$prefixmhs/lib"
+
+compile="$prefix/bin/mhseval +RTS -r$prefixmhs/comb/mhs.comb -RTS"
+compress="$compile -r $lib -i$prefixmhs/Tools Compress"
+addcomb="$compile -r $lib -i$prefixmhs/Tools Addcombs"
+
+tmpcomb=`mktemp -t comb.XXXXXX`
+tmpeval=`mktemp -t eval.XXXXXX.c`
+
+trap "rm -f $tmpcomb $tmpeval" EXIT
+
+ex=""
+$ex $compile $lib $compflags -o$tmpcomb "$input"
+$ex cp $prefixmhs/src/runtime/eval.c $tmpeval
+$ex $compress < $tmpcomb | $addcomb >> $tmpeval
+$ex $cc -O3 $tmpeval $output
+$ex rm -f $tmpcomb $tmpeval
--- a/lib/Data/Map.hs
+++ b/lib/Data/Map.hs
@@ -3,7 +3,7 @@
-- Similar to Data.Map
-- Based on https://ufal.mff.cuni.cz/~straka/papers/2011-bbtree.pdf
--
-module Data.NMap(
+module Data.Map(
Map,
insertBy, insertByWith, fromListByWith, fromListBy, lookupBy, empty, elems, size, toList, deleteBy,
) where
--
⑨