fix README.md for 2019/lynn

This commit is contained in:
Landon Curt Noll committed 2023-03-25 04:28:02 -07:00
1 parent f62166438b
commit 9920198ffa
1 file changed
+51 -27
+51 -27
View File
@@ -1,27 +1,36 @@
# Most functional compiler # Most functional compiler
Ben Lynn Ben Lynn
<https://crypto.stanford.edu/~blynn/> <https://crypto.stanford.edu/~blynn/>
Twitter: @bmxlynn Twitter: @bmxlynn
# To build:
## Judges' comments: ```sh
### To use: make
```
make ### To run:
```sh
./prog
```
### Try: ### Try:
(./prog < fib.hs; cat prog.c) > fib.c ```sh
cc fib.c -o fib (./prog < fib.hs; cat prog.c) > fib.c
./fib cc fib.c -o fib
./fib
```
### Selected Judges Remarks: ## Judges' comments:
A fully functional compiler. The example prints out the 30th Fibonacci number. A fully functional compiler. The example prints out the 30th Fibonacci number.
## Author's comments: ## Author's comments:
# Remarks #
### Remarks
A Haskell compiler. Supports a subset of Haskell more than large enough to A Haskell compiler. Supports a subset of Haskell more than large enough to
self-host. Like GHC with custom language extensions: self-host. Like GHC with custom language extensions:
@@ -40,24 +49,30 @@ self-host. Like GHC with custom language extensions:
* `SyntaxForTheMasses`: See below. * `SyntaxForTheMasses`: See below.
## Demos ## ### Demos
Build the compiler: Build the compiler:
$ $(CC) -o prog prog.c ```sh
cc -o prog prog.c
```
### Fibonacci numbers ### Fibonacci numbers
Test the compiler on `fib.hs`: Test the compiler on `fib.hs`:
$ (./prog < fib.hs ; cat prog.c) > fib.c ```sh
(./prog < fib.hs ; cat prog.c) > fib.c
```
Compiling the output produces a binary that prints the 30th Fibonacci number. Compiling the output produces a binary that prints the 30th Fibonacci number.
The file `ghcfib.hs` includes `fib.hs` with some glue code, and shows GHC The file `ghcfib.hs` includes `fib.hs` with some glue code, and shows GHC
also accepts our subset of Haskell: also accepts our subset of Haskell:
$ ghc ghcfib.hs ```sh
ghc ghcfib.hs
```
### Self-hosting compiler ### Self-hosting compiler
@@ -66,7 +81,9 @@ instead provide `hint.hs`, the output of a certain stage of the compiler when
run on itself. This intermediate output is hopefully difficult to understand, run on itself. This intermediate output is hopefully difficult to understand,
yet is accepted by our compiler: yet is accepted by our compiler:
$ (./prog < hint.hs ; cat prog.c) > hint.c ```sh
(./prog < hint.hs ; cat prog.c) > hint.c
```
The output program behaves like the compiler itself. The output program behaves like the compiler itself.
@@ -83,24 +100,32 @@ languages"](https://www.cs.dartmouth.edu/~doug/nfa.pdf). We exercise it by
showing the first entries of the length-ordered list of all strings consisting showing the first entries of the length-ordered list of all strings consisting
of the characters a and b that contain an even number of a's. of the characters a and b that contain an even number of a's.
$ (./prog < lol.hs ; cat prog.c) > lol.c ```sh
(./prog < lol.hs ; cat prog.c) > lol.c
```
A GHC wrapper is provided: A GHC wrapper is provided:
$ ghc ghclol.hs ```sh
ghc ghclol.hs
```
### Strongly-connected components ### Strongly-connected components
See `scc.hs` (and its GHC wrapper `ghcscc.hs`) for an elegant way to print the See `scc.hs` (and its GHC wrapper `ghcscc.hs`) for an elegant way to print the
strongly-connected components of a graph in reverse topological order. strongly-connected components of a graph in reverse topological order.
$ (./prog < scc.hs ; cat prog.c) > scc.c ```sh
(./prog < scc.hs ; cat prog.c) > scc.c
```
It expects the input to be in a similar format as a previous entry It expects the input to be in a similar format as a previous entry
(2018 vokes). Indeed, obtain the 2018 winners, and run: (2018 vokes). Indeed, obtain the 2018 winners, and run:
$ ./scc < 2018/vokes/example-1.txt ```sh
$ ./scc < 2018/vokes/example-2.txt ./scc < 2018/vokes/example-1.txt
./scc < 2018/vokes/example-2.txt
```
The output should agree, though our program omits line numbers and does not The output should agree, though our program omits line numbers and does not
sort entries within a line. (Also, our program only treats spaces as sort entries within a line. (Also, our program only treats spaces as
@@ -185,7 +210,7 @@ or rather, a compiler that accepts a subset of Haskell sufficiently large to
self-host. You might say I wrote a tool for this contest, then ran it on itself self-host. You might say I wrote a tool for this contest, then ran it on itself
to make an entry for it. to make an entry for it.
## Obfuscation techniques ## ### Obfuscation techniques
Even with Kiselyov's algorithm and some term rewriting, the compiler only fit Even with Kiselyov's algorithm and some term rewriting, the compiler only fit
after compression, which naturally obfuscates the code. More tricks were needed after compression, which naturally obfuscates the code. More tricks were needed
@@ -239,7 +264,7 @@ year](http://okmij.org/ftp/tagless-final/ski.pdf).
parser combinators, lambda calculus, bracket abstraction, denotational parser combinators, lambda calculus, bracket abstraction, denotational
semantics, etc. semantics, etc.
## Warnings ## ### Warnings
On my system, it compiles cleanly with `-Wall` with older standards, e.g. On my system, it compiles cleanly with `-Wall` with older standards, e.g.
`-std=c89`, but less cleanly if `-pedantic` is also supplied. `-std=c89`, but less cleanly if `-pedantic` is also supplied.
@@ -247,16 +272,15 @@ On my system, it compiles cleanly with `-Wall` with older standards, e.g.
Compiling the compiler output with `-Wall` triggers a warning about a Compiling the compiler output with `-Wall` triggers a warning about a
strange-looking comment. strange-looking comment.
## Behind-the-scenes commentary ## ### Behind-the-scenes commentary
[My website reveals how this compiler [My website reveals how this compiler
works.](https://crypto.stanford.edu/~blynn/compiler/ioccc.html) works.](https://crypto.stanford.edu/~blynn/compiler/ioccc.html)
-------------------------------------------------------------------------------- ## Copyright:
<!--
(c) Copyright 1984-2019, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved (c) Copyright 1984-2019, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc]. This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
[judges]: http://www.ioccc.org/judges.html [judges]: http://www.ioccc.org/judges.html
[cc]: http://creativecommons.org/licenses/by-sa/3.0/ [cc]: http://creativecommons.org/licenses/by-sa/3.0/
-->