diff --git a/2012/tromp/README.md b/2012/tromp/README.md index cdc78d1c9..713377405 100644 --- a/2012/tromp/README.md +++ b/2012/tromp/README.md @@ -7,6 +7,18 @@ make tromp32 # On a 32-bit machine ``` +### Bugs and (Mis)features: + +The current status of this entry is: + +``` +STATUS: INABIAF - please **DO NOT** fix +``` + +For more detailed information see [2012 tromp in bugs.md](/bugs.md#2012-tromp). + + + ## To use: ```sh @@ -27,9 +39,7 @@ cat binary-prog.Blc data | ./tromp ### Try: ```sh -(cat hilbert.Blc; echo -n 1234) | ./tromp -(cat oddindices.Blc; echo; cat primes.blc | ./tromp -b) | ./tromp -cat primes.blc | ./tromp -b | ./primes.pl +./try.sh ``` @@ -73,11 +83,11 @@ with [De Bruijn notation](https://en.wikipedia.org/wiki/De_Bruijn_notation) `\ \ In the closely related [BLC8](https://tromp.github.io/cl/Binary_lambda_calculus.html#BLC8:_byte_sized_I.2FO) -language, IO is byte oriented, translating between a stream of bytes and a list +language, I/O is byte oriented, translating between a stream of bytes and a list of length-8 lists of [booleans](https://en.wikipedia.org/wiki/Boolean_algebra). The submission implements the universal machine in the most concise manner conceivable. -It lacks `#defines` and `#includes`, and compiles to a (stripped) executable of +It lacks `#define`s and `#include`s, and compiles to a (stripped) executable of under 6K in size. Without arguments, it runs in byte mode, using standard input and output. @@ -95,13 +105,14 @@ The program uses the following exit codes: The size of the term space is fixed at compile time with `-DA`. + ### A half byte `cat` The shortest (closed) lambda calculus term is `\x x (\ 1` in [De Bruijn notation](https://en.wikipedia.org/wiki/De_Bruijn_notation)) which is the identity function. When its encoding `0010` is fed into the universal machine, -it will simply copy the input to the output. (well, not that simply, since each -byte is smashed to bits and rebuilt from scratch) Voila: a half byte cat: +it will simply copy the input to the output (well, not that simply, since each +byte is smashed to bits and rebuilt from scratch). Voila: a half byte cat: ```sh $ echo " Hello, world" | ./tromp @@ -118,7 +129,6 @@ Hello, world ``` - ### Bad programs If the input doesn't start with a valid program, that is, @@ -129,14 +139,13 @@ it will crash in some way. E.g. the following might dump core: echo -n "U" | ./tromp ``` -Furthermore, the interpreter requires the initial encoded lambda term to be closed, -that is, variable `n` can only appear within at least `n` enclosing lambdas. -For instance the term `\ 5` is not closed, causing the interpreter to crash when -looking into a null-pointer environment: +Furthermore, the interpreter requires the initial encoded lambda term to be +closed, that is, variable `n` can only appear within at least `n` enclosing +lambdas. For instance, here the term `\ 5` is not closed, causing the +interpreter to crash when looking into a null-pointer environment: ```sh echo ">Hello, world" | ./tromp - ``` will likely dump core. @@ -199,7 +208,8 @@ Ni hao ### A prime number sieve -Even shorter than the self-interpreter is this prime number sieve in 167 bits (under 21 bytes): +Even shorter than the self-interpreter is this prime number sieve in 167 bits +(under 21 bytes): ``` 000100011001100101000110100 @@ -329,11 +339,13 @@ Hello World! Curiously, the interpreter `bf.Blc` is the exact same size as `hw.bf`. + ### A BLC assembler Writing BLC programs can be made slightly less painful with this parser that translates single-letter-variable lambda calculus into BLC: + ```sh $ echo "\f\x f (f (f x))" > three $ cat parse.Blc three | ./tromp @@ -356,7 +368,7 @@ cat parse.Blc reverse | ./tromp > reverse.blc and change it to BLC8 with -``` +```sh $ cat deflate.Blc reverse.blc | ./tromp > rev.Blc $ wc rev.Blc 0 1 9 rev.Blc @@ -438,6 +450,7 @@ out all multiples of the first prime, 2. Since my computer reaches swap hell before line 40, we can't see the next bit arriving, at least not in this symbolic reduction. + ### Performance Performance is quite decent, and amazingly good for such a tiny implementation, @@ -476,9 +489,10 @@ How does the program reach exit code 0? And how do any of those BLC programs work? + ### Portability -The program freely (without casting) converts between int and `int *`, causing +The program freely (without casting) converts between `int` and `int *`, causing many warnings; ``` @@ -496,22 +510,27 @@ many warnings; Avoiding these would make the program substantially longer, and detract from its single minded focus on conciseness. -It implicitly declares functions `read()`, `write()`, `exit()` and `calloc()`, the latter two incompatibly. -32 bit and 64 bit executables are separate [Makefile](Makefile) targets, involving a change -from `int` to `long` and from a hardcoded sizeof of 4 to 8. +It implicitly declares functions `read(2)`, `write(2)`, `exit(3)` and +`calloc(3)`, the latter two incompatibly. 32 bit and 64 bit executables are +separate [Makefile](Makefile) targets, involving a change from `int` to `long` +and from a hardcoded sizeof of 4 to 8. + +The program has been tested to work correctly on Linux/Solaris/MacOSX both in 32 +and 64 bits. -The program has been tested to work correctly on Linux/Solaris/MacOSX both in 32 and 64 bits. ### How the program works See the file [how.md](how.md). + ### Acknowledgements Christopher Hendrie, Bertram Felgenhauer, Alex Stangl, Seong-hoon Kang, and [Yusuke Endoh](/winners.html#Yusuke_Endoh) have contributed ideas and suggestions for improvement. + ### References Binary Lambda Calculus - diff --git a/2012/tromp/how.md b/2012/tromp/how.md index ead070e9b..5ab2bc82a 100644 --- a/2012/tromp/how.md +++ b/2012/tromp/how.md @@ -10,7 +10,7 @@ continuations (see the 3rd reference for details). The term space holds [lambda calculus](https://en.wikipedia.org/wiki/Lambda_calculus) terms in the following -format. 0 denotes some form of IO; the only four occurrences are at: +format. 0 denotes some form of I/O; the only four occurrences are at: ``` C=13: recognizes end of a byte @@ -19,10 +19,10 @@ format. 0 denotes some form of IO; the only four occurrences are at: C=end: input list, expanded lazily ``` -`1` denotes a variable, with next entry its de [Bruijn +`1` denotes a variable, with the next entry its [de Bruijn index](https://en.wikipedia.org/wiki/De_Bruijn_index). -`2` denotes application with next entry the size of the term being applied. +`2` denotes application with the next entry the size of the term being applied. `3` denotes lambda abstraction. @@ -31,11 +31,11 @@ A closure consists of the following items: 0. pointer to the next closure (as part of an environment), or next record on free list. -1. reference count -2. pointer to environment -3. lambda term (index in term space) +1. reference count. +2. pointer to environment. +3. lambda term (index in term space). -Here's what each variable do: +Here's what each variable does: ``` L Lambda term space diff --git a/2012/tromp/try.sh b/2012/tromp/try.sh new file mode 100755 index 000000000..1b404686b --- /dev/null +++ b/2012/tromp/try.sh @@ -0,0 +1,122 @@ +#!/usr/bin/env bash +# +# try.sh - demonstrate IOCCC winner 2012/tromp +# + +# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it +# this way allows us to have the user specify a different compiler in an easy +# way. +if [[ -z "$CC" ]]; then + CC="cc" +fi + +make CC="$CC" all >/dev/null || exit 1 + +# clear screen after compilation so that only the entry is shown +clear + +# ^-- SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"? +# shellcheck disable=SC2140 +echo "$ (cat hilbert.Blc; echo -n "1") | ./tromp" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +(cat hilbert.Blc; echo -n "1") | ./tromp +echo 1>&2 + +# ^-- SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"? +# shellcheck disable=SC2140 +echo "$ (cat hilbert.Blc; echo -n "12") | ./tromp" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +(cat hilbert.Blc; echo -n "12") | ./tromp +echo 1>&2 + +# ^-- SC2140 (warning): Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"? +# shellcheck disable=SC2140 +echo "$ (cat hilbert.Blc; echo -n "123") | ./tromp" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 + +# There's no such thing as a useless cat so we silence: +# +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# +# shellcheck disable=SC2002 +(cat hilbert.Blc; echo -n "123") | ./tromp +echo 1>&2 + +echo "$ (cat hilbert.Blc; echo -n 1234) | ./tromp" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +# There's no such thing as a useless cat so we silence: +# +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# +# shellcheck disable=SC2002 + +(cat hilbert.Blc; echo -n 1234) | ./tromp +echo 1>&2 + +echo "$ echo " Hello, world" | ./tromp" +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo " Hello, world" | ./tromp +echo 1>&2 + +echo "$ echo "*Hello, world" | ./tromp" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +echo "*Hello, world" | ./tromp +echo 1>&2 + +echo "$ (cat uni8.Blc; echo " Ni hao") | ./tromp" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +# There's no such thing as a useless cat so we silence: +# +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# +# shellcheck disable=SC2002 +(cat uni8.Blc; echo " Ni hao") | ./tromp +echo 1>&2 + +echo "$ cat primes.blc | ./tromp -b | head -c 70" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +# There's no such thing as a useless cat so we silence: +# +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# +# shellcheck disable=SC2002 +cat primes.blc | ./tromp -b | head -c 70 +echo 1>&2 + +echo "$ (cat oddindices.Blc; echo -n " "; cat primes.blc | ./tromp -b) | ./tromp | head -c 70" 1>&2 +echo 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +# There's no such thing as a useless cat so we silence: +# +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# +# shellcheck disable=SC2002 +(cat oddindices.Blc; echo -n " "; cat primes.blc | ./tromp -b) | ./tromp | head -c 70 +echo 1>&2 + +echo "$ cat hw.bf" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +cat hw.bf +echo 1>&2 +echo "$ cat bf.Blc hw.bf | ./tromp" 1>&2 +read -r -n 1 -p "Press any key to continue: " +echo 1>&2 +# There's no such thing as a useless cat so we silence: +# +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. +# +# shellcheck disable=SC2002 +cat bf.Blc hw.bf | ./tromp + +echo 1>&2 +echo "We also recommend that you check the author's remarks for more examples." 1>&2 diff --git a/bugs.md b/bugs.md index 72745a60d..b9fb5e81c 100644 --- a/bugs.md +++ b/bugs.md @@ -2769,6 +2769,33 @@ musical element of a line is only 2 characters! The manual referred to is [here](2012/deckmyn/deckmyn.md). +## 2012 tromp + +### STATUS: INABIAF - please **DO NOT** fix +### Source code: [2012/tromp/tromp.c](2012/tromp/tromp.c) +### Information: [2012/tromp/README.md](2012/tromp/README.md) + +The author stated: + +``` +If the input doesn't start with a valid program, that is, +if the interpreter reaches end-of-file during program parsing, +it will crash in some way. E.g. the following might dump core: + + echo -n "U" | ./tromp + +Furthermore, the interpreter requires the initial encoded lambda term to be closed, +that is, variable n can only appear within at least 'n' enclosing lambdas. +For instance, here the term '\ 5' is not closed, causing the interpreter to crash when +looking into a null-pointer environment: + + echo ">Hello, world" | ./tromp + +will likely dump core. + +``` + + ## 2012 vik ### STATUS: INABIAF - please **DO NOT** fix diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 7e43c26e2..61f124cd8 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -3391,6 +3391,11 @@ show different languages and numbers. Cody added the [try.sh](2012/konno/try.sh) script. +## [2012/tromp](2012/tromp/tromp.c) ([README.md](2012/tromp/README.md)) + +Cody added the [try.sh](2012/tromp/try.sh) script. + + ## [2012/vik](2012/vik/vik.c) ([README.md](2012/vik/README.md])) Based on the author's description it should be able to get this entry to work