From 00147d39a3030b9f316ea3e43883aa10c97a5f83 Mon Sep 17 00:00:00 2001 From: Landon Curt Noll Date: Tue, 7 Mar 2023 23:32:34 -0800 Subject: [PATCH] remove orig code for 2012/tromp Made 64 bit mode default. --- 2012/tromp/.gitignore | 2 + 2012/tromp/Makefile | 298 +++++++++++++++++++++++++++++----------- 2012/tromp/README.md | 64 ++++----- 2012/tromp/tromp.orig.c | 27 ---- 4 files changed, 249 insertions(+), 142 deletions(-) delete mode 100644 2012/tromp/tromp.orig.c diff --git a/2012/tromp/.gitignore b/2012/tromp/.gitignore index 48d35ef74..7666c55b6 100644 --- a/2012/tromp/.gitignore +++ b/2012/tromp/.gitignore @@ -1 +1,3 @@ tromp +tromp32 +tromp64 diff --git a/2012/tromp/Makefile b/2012/tromp/Makefile index 1e52debf9..624a119fb 100644 --- a/2012/tromp/Makefile +++ b/2012/tromp/Makefile @@ -1,96 +1,163 @@ #!/usr/bin/env make # -# 2012 makefile +# IOCCC 2012 winning entry - tromp + +################################################################################ # -# This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis -# is licensed under: +# Regarding individual entries: +# +# IOCCC winning entry code may not work on your system. Even with standards, +# conditions and build environments change, especially when it comes to more +# extreme code such you might find in an IOCCC winner. Moreover, what was +# allowed and liked in one IOCCC contest may no longer be liked/allowed in +# later IOCCC years. +# +# Corrections on winning author and fixing typos in remarks are VERY WELCOME. +# +# GitHub pull requests are welcome: +# +# If you have a patch that might make running an entry work in modern Unix-like +# environments, please create a GitHub pull request for the IOCCC judges to +# consider. +# +# Suggestions and corrections regarding Makefiles, winning author information, +# fixing typos in remarks, and code patches are welcome via opening a GitHub +# issue or better yet, by creating a GitHub pull request for the IOCCC judges +# to consider. To form a GitHub issue or GitHub pull, please visit: +# +# https://github.com/ioccc-src/winner +# +################################################################################ + +# This work by Landon Curt Noll and Leonid A. Broukhis is licensed under: # # Creative Commons Attribution-ShareAlike 3.0 Unported License. # # See: http://creativecommons.org/licenses/by-sa/3.0/ -################ -# tool locations -################ +############################# +# shell used by this Makefile +############################# # SHELL= bash -CP= cp -CPP= cpp -GUNZIP= gunzip -LD= ld -MAKE= make -RM= rm -SED= sed -TAR= tar -TRUE= true + +####################### +# common tool locations +####################### +# +include ../../var.mk # Set X11_LIBDIR to the directory where the X11 library resides # -X11_LIBDIR= /usr/X11R6/lib +#X11_LIBDIR= /usr/X11R6/lib +#X11_LIBDIR= /usr/X11/lib +X11_LIBDIR= /opt/X11/lib # Set X11_INCLUDEDIR to the directory where the X11 include files reside # -X11_INCDIR= /usr/X11R6/include +#X11_INCDIR= /usr/X11R6/include +#X11_INCDIR= /usr/X11/include +X11_INCDIR= /opt/X11/include -# Compiler warnings +# Common C compiler warnings to silence # -#CWARN= -CWARN= -Wall -W -#CWARN= -Wall -W -pedantic +#CSILENCE= +CSILENCE= -Wno-bitwise-op-parentheses -Wno-conditional-type-mismatch -Wno-error \ + -Wno-implicit-function-declaration -Wno-incompatible-pointer-types \ + -Wno-int-conversion -Wno-main -Wno-return-type -Wno-unused-parameter -# compiler standard +# Common C compiler warning flags +# +#CWARN= ${CSILENCE} +#CWARN= -Wall ${CSILENCE} +CWARN= -Wall -Wextra ${CSILENCE} +#CWARN= -Wall -Wextra -pedantic ${CSILENCE} + +# Compiler standard # #CSTD= #CSTD= -ansi -CSTD= -std=c99 +CSTD= -std=gnu90 -# compiler bit architecture +# Compiler bit architecture # # Some entries require 32-bitness: # ARCH= -m32 # -# Some entries require 64-bitess: +# Some entries require 64-bitness: # ARCH= -m64 # # By default we assume nothing: # ARCH= -# optimization +# Defines that are needed to compile +# +#CDEFINE= +CDEFINE= -DA=500000 + +# Include files that are needed to compile +# +CINCLUDE= +#CINCLUDE= -include stdlib.h +#CINCLUDE= -include stdio.h +#CINCLUDE= -include stdlib.h -include stdio.h +#CINCLUDE= -I ${X11_INCDIR} +#CINCLUDE= -I ${HOMEBREW_PREFIX}/include/SDL2 + +# Optimization # # Most compiles will safely use -O2. Some can use only -O1 or -O. # A few compilers have broken optimizers or this entry make break # under those buggy optimizers and thus you may not want anything. +# Reasonable compilers will allow for -O3. # #OPT= #OPT= -O #OPT= -O1 -OPT= -O2 -#OPT= -O3 +#OPT= -O2 +OPT= -O3 + +# Default flags for ANSI C compilation +# +CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT} # Libraries needed to build # LIBS= +#LIBS= -lm +#LIBS= -L ${X11_LIBDIR} -lX11 +#LIBS= -L ${HOMEBREW_PREFIX}/lib -lSDL2 -# default flags for ANSI C compilation -# -CFLAGS= ${CWARN} ${CSTD} ${ARCH} ${OPT} ${LIBS} - -# ANSI compiler -# -# Set CC to the name of your ANSI compiler. -# -# Some entries seem to need gcc. If you have gcc, set -# both CC and MAY_NEED_GCC to gcc. -# -# If you do not have gcc, set CC to the name of your ANSI compiler, and -# set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just : -# to disable such programs. +# C compiler to use # CC= cc #CC=clang -MAY_NEED_GCC= gcc +#CC=gcc + +# Compiler add-ons or replacements for clang only +# +ifeq ($(CC),clang) +# +CSILENCE+= -Wno-comma -Wno-implicit-int-conversion -Wno-missing-prototypes \ + -Wno-missing-variable-declarations -Wno-pedantic \ + -Wno-poison-system-directories -Wno-shadow -Wno-shorten-64-to-32 \ + -Wno-strict-prototypes +# +CWARN+= -Weverything +# +endif + +# Specific add-ons or replacements for gcc only +# +ifeq ($(CC),gcc) +# +#CSILENCE+= +# +#CWARN+= +# +endif ############################## @@ -98,28 +165,41 @@ MAY_NEED_GCC= gcc ############################## # ENTRY= tromp +PROG= ${ENTRY} +# +OBJ= ${PROG}.o DATA= how13 primes.blc uni.blc uni8.Blc bf.Blc hw.bf deflate.Blc inflate.Blc \ parse.Blc symbolic.Blc primes.pl -ALT_OBJ= -ALT_ENTRY= +TARGET= ${PROG} ${PROG}64 +# +ALT_OBJ= ${ENTRY}32.o +ALT_TARGET= ${ENTRY}32 ################# # build the entry ################# # -all: ${ENTRY} ${ENTRY}64 ${DATA} +all: data ${TARGET} @${TRUE} -${ENTRY}: ${ENTRY}.c - ${CC} ${CFLAGS} -m32 -DInt=int -DX=4 -DA=500000 $< -o $@ +.PHONY: all alt data everything clean clobber install \ + love haste waste maker easter_egg sandwich \ + supernova deep_magic magic charon pluto -${ENTRY}64: ${ENTRY}.c - ${CC} ${CFLAGS} -m64 -DInt=long -DX=8 -DA=500000 $< -o $@ +${PROG}: ${PROG}.c + ${CC} ${CFLAGS} -m64 -DInt=long -DX=8 $< -o $@ + +${PROG}64: ${PROG} + ${RM} -f $@ + ${CP} -v $< $@ + +${PROG}32: ${PROG}.c + ${CC} ${CFLAGS} -m32 -DInt=int -DX=4 $< -o $@ # alternative executable # -alt: ${ALT_ENTRY} +alt: data ${ALT_TARGET} @${TRUE} # data files @@ -127,33 +207,51 @@ alt: ${ALT_ENTRY} data: ${DATA} @${TRUE} +# both all and alt +# +everything: all alt + ############### # utility rules ############### # -everything: all alt - clean: - ${RM} -f ${ENTRY}.o ${ENTRY}64.o ${ALT_OBJ} + ${RM} -f ${OBJ} ${ALT_OBJ} + @-if [ -f indent.c ]; then \ + echo ${RM} -f indent.c; \ + ${RM} -f indent.c; \ + fi clobber: clean - ${RM} -f ${ENTRY} ${ENTRY}64 ${ALT_ENTRY} - -nuke: clobber - @${TRUE} - -dist_clean: nuke - @${TRUE} + ${RM} -f ${TARGET} ${ALT_TARGET} + @-if [ -e sandwich ]; then \ + ${RM} -f sandwich; \ + echo 'ate sandwich'; \ + fi install: - @echo "Surely you're joking Mr. Feynman!" + @echo "Dr. Spock says that is not logical!" @${TRUE} -# backwards compatibility +# you may be able to misunderstand the source by reading indent.c # -build: all - @${TRUE} +indent.c: ${PROG}.c + @if which "${GINDENT}" >/dev/null 2>&1; then \ + echo ${RM} -f $@; \ + ${RM} -f $@; \ + echo "${GINDENT} < $< > $@"; \ + ${GINDENT} < $< > $@; \ + elif which "${INDENT}" >/dev/null 2>&1; then \ + echo ${RM} -f $@; \ + ${RM} -f $@; \ + echo "${INDENT} < $< > $@"; \ + ${INDENT} < $< > $@; \ + else \ + echo "no intent tool found, ident $< yourself, sorry"; \ + echo "exit 1"; \ + exit 1; \ + fi ################## @@ -169,39 +267,73 @@ haste: @${TRUE} waste: - @echo 'waste' + @echo 'haste' + @${TRUE} + +maker: + @echo 'Participate in a maker faire' @${TRUE} easter_egg: - @echo you expected to mis-understand this $${RANDOM} magic - @echo chongo '' "/\\oo/\\" - @echo Readers shall be disallowed from not being unable to partly misunderstand this partocular final echo. + @echo "you expected to often misunderstand this $${RANDOM} magic" + @echo "chongo '' /\\oo/\\" + @echo "Eggy" -# Understand the history of "I Am the Walrus" and -# and in particular John Lennon's remarks on that -# song and you might be confused about these next -# rules in a different way. :-) -# -supernova: nuke - @-if [ -r .code_anal ]; then \ - ${RM} -f .code_anal_v3; \ +sandwich: easter_egg + @if [ `id -u` -eq 0 ]; then \ + echo 'Okay.'; \ + echo "$${RANDOM}`date +%s`$${RANDOM}" > $@; \ else \ - echo "You are not expected to understand this"; \ + echo 'What? Make it yourself.'; \ + exit 1; \ fi + +# Understand the history of the Homebrew Computer Club +# as well as the West Coast Computer Faire and +# you might be confused different. :-) +# +supernova: sandwich + @-if [ -r .code_anal ]; then \ + ${RM} -f .code_anal_v6; \ + else \ + echo "planet deniers, like some members of the IAU, are so cute when they try to defend their logic"; \ + fi + @echo "A $@ helps ${MAKE} the elements that help form planets" @${TRUE} -deep_magic: +deep_magic: supernova @-if [ -r .code_anal ]; then \ - ccode_analysis --deep_magic 1c2c85c7a02c55d1add91967eca491d53c101dc1 --FNV1a_hash 256-bit "${ENTRY}"; \ + ccode_analysis --deep_magic 7889066cdbdf09b0408021754586e895be641cc9be29e7eafd3ca65359541f17 \ + --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \ else \ - echo "Understand different"; \ + echo "Wrong! Do it again!"; \ + sleep 2; \ + echo "Wrong! Do it again!"; \ + sleep 2; \ + echo "Wrong! Do it again!"; \ fi @${TRUE} magic: deep_magic @-if [ -r .code_anal ]; then \ - ccode_analysis --mode 21701 --level 23209 --FNV1a_hash 256-bit "${ENTRY}"; \ + ccode_analysis --level 20003 --mode 5717175 --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \ else \ - echo "These aren't the droids you're looking for Mr. Spock!"; \ + echo "If you don't eat yer meat, you can't have any pudding!"; \ + echo "How can you have any pudding if you don't eat yer meat?!"; \ fi @${TRUE} + +# The IOCCC resident astronomer states +# +charon: magic + @echo "$@ is a dwarf planet" + @echo "dwarf is a type of planet" + @echo "therefore IAU, $@ is a planet" + +pluto: charon + ${MAKE} charon + @echo "$@ is a dwarf planet" + @echo "dwarf is a type of planet" + @echo "therefore, $@ is a planet" + @echo "having lots of planets is good feature because supernovae can help ${MAKE} a lot of them" + diff --git a/2012/tromp/README.md b/2012/tromp/README.md index 8d77b2718..2a34d5f87 100644 --- a/2012/tromp/README.md +++ b/2012/tromp/README.md @@ -1,22 +1,21 @@ # Most functional -John Tromp - - +John Tromp + + +## To build: -## Judges' comments: -### To build: + make all # On a 64-bit machine (default) -On a 32-bit machine: + make tromp32 # On a 32-bit machine - make tromp +### To run -On a 64-bit machine: + ./tromp [-b] + + NOTE: Substitute ./tromp32 for ./tromp everywhere below if on a 32-bit machine - make tromp64 - # And mentally substitute ./tromp64 for ./tromp everywhere below - ### To run: cat ascii-prog.blc data | ./tromp -b @@ -34,6 +33,7 @@ The judges dare to say that the data files this entry is processing are more obfuscated than the entry itself. ## Author's comments: + This program celebrates the close connection between obfuscation and conciseness, by implementing the most concise language known, Binary Lambda Calculus (BLC). @@ -84,14 +84,14 @@ Voila: a half byte cat: echo " Hello, world" | ./tromp Hello, world - + Since the least significant 4 bits of the first byte are just arbitrary padding that is ignored by the program, any character from ASCII 32 (space) through 47 (/) will do, e.g.: echo "*Hello, world" | ./tromp Hello, world - + Bad programs ============ @@ -109,7 +109,7 @@ causing the interpreter to crash when looking into a null-pointer environment: echo ">Hello, world" | ./tromp Segmentation fault - + Since these properties can be checked when creating BLC programs, the interpreter doesn't bother checking for it. @@ -177,7 +177,7 @@ Even shorter than the self-interpreter is this prime number sieve in 167 bits (u The n'th bit in the output indicates whether n is prime: cat primes.blc | ./tromp -b | head -c 70 - 0011010100010100010100010000010100000100010100010000010000010100000100 + 0011010100010100010100010000010100000100010100010000010000010100000100 For those who prefer to digest their primes in decimal, there is oddindices.Blc, which will print the indices of all odd characters (with lsb = 1) @@ -196,13 +196,13 @@ Program hilbert.Blc, at 143 bytes, is a very twisty "one-liner" (shown in hexade ef f615ff9 46 84 058117e 05 cb fe bc bf ee86cb9 4681600 5c0bfac bfbf71a - 85 e0 5c f4 + 85 e0 5c f4 14d5fe0 8180b048d0800e078 016445f fe 5f f7 ffffe5fff2fc 02f7ad97f5bf ff ff bf ff ca af ff 7817ffa df76695 4680601 57f7e16 - 05 c1 + 05 c1 3fe80b2 2c18581 bfe5c10 42ff805 de ec 06 c2 c0 c0 60 8191a00167fb cbcfdf65f7c0 a20 @@ -210,42 +210,42 @@ Program hilbert.Blc, at 143 bytes, is a very twisty "one-liner" (shown in hexade It expects n arbitrary characters of input, and draws a space filling Hilbert curve of order n: (cat hilbert.Blc; echo -n "1") | ./tromp - _ + _ | | (cat hilbert.Blc; echo -n "12") | ./tromp - _ _ + _ _ | |_| | |_ _| - _| |_ + _| |_ (cat hilbert.Blc; echo -n "123") | ./tromp - _ _ _ _ + _ _ _ _ | |_| | | |_| | |_ _| |_ _| - _| |_____| |_ + _| |_____| |_ | ___ ___ | |_| _| |_ |_| - _ |_ _| _ + _ |_ _| _ | |___| |___| | (cat hilbert.Blc; echo -n "1234") | ./tromp - _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ | |_| | | |_| | | |_| | | |_| | |_ _| |_ _| |_ _| |_ _| - _| |_____| |_ _| |_____| |_ + _| |_____| |_ _| |_____| |_ | ___ ___ | | ___ ___ | |_| _| |_ |_| |_| _| |_ |_| - _ |_ _| _ _ |_ _| _ + _ |_ _| _ _ |_ _| _ | |___| |___| |_| |___| |___| | |_ ___ ___ ___ ___ _| - _| |_ |_| _| |_ |_| _| |_ + _| |_ |_| _| |_ |_| _| |_ | _ | _ |_ _| _ | _ | |_| |_| | |___| |___| | |_| |_| - _ _ | ___ ___ | _ _ + _ _ | ___ ___ | _ _ | |_| | |_| _| |_ |_| | |_| | |_ _| _ |_ _| _ |_ _| - _| |___| |___| |___| |___| |_ + _| |___| |___| |___| |___| |_ A BrainFuck interpreter ======================= @@ -253,7 +253,7 @@ A BrainFuck interpreter The smallest known BF interpreter is written in... you guessed it, BLC, coming in at 112 bytes (including 3 bits of padding): - od -t x4 bf.Blc + od -t x4 bf.Blc 0000000 01a15144 02d55584 223070b7 00f032ff 0000020 7f85f9bf 956fe15e c0ee7d7f 006854e5 0000040 fbfd5558 fd5745e0 b6f0fbeb 07d62ff0 @@ -299,7 +299,7 @@ So we could assemble an input reversing program as and change it to BLC8 with cat deflate.Blc reverse.blc | ./tromp > rev.Blc - wc rev.Blc + wc rev.Blc 0 1 9 rev.Blc and then try it out with: @@ -309,7 +309,7 @@ and then try it out with: ^D !dlrow ,olleH -Symbolic Lambda Calculus reduction +Symbolic Lambda Calculus reduction ================================== BLC8 program symbolic.Blc shows individual reduction steps on symbolic lambda terms. diff --git a/2012/tromp/tromp.orig.c b/2012/tromp/tromp.orig.c deleted file mode 100644 index 58705cb72..000000000 --- a/2012/tromp/tromp.orig.c +++ /dev/null @@ -1,27 +0,0 @@ - Int L[A],m,b,*D=A, - *c,*a=L,C,*U=L,u;s - (Int*m){return!*U? - *m=g()?U++,!g()?m[ - 1]=s(++U),2:3:1,s( - U):g()?U+=2:s(U[1] - ++),U-m;}v(){for(D - =a;u--;a=*a);C=a[3 - ];++1[a=a[2]];d(D) - ;}char *B,I,O,*S = - "-,&,,/.--/,:-,'/" - ".-,-,,/.-,*,//..," - ;d(Int*l){--l[1]||d(l - [d(*l),*l=B,B=l,2]);}g( - ){b=b--?b:m|read(0,&I,1)- - 1;return~I>>b&1;}x(){for(k( - 0,6),U[-5]=96;b;*U++=g())k(0, - 9);}k(l,u){for(;l<=u;U-L-A?*U++ - =S[l++]^46:exit(5));}main(e){for( - k(10,33),a[4]-=m =e-2&7,a[23]=s(U), - b=0;;e?e-1?e-2?c ?D=c,c=*D,*D=a,a=D - :exit(L[C+1]):(D =B?B:calloc(4,X))? - B=*D,*D=c,c=D,D[ 3]=++C+u, D[2]=a,a - [++D[1] ]++:exit (6):v():C -->22?g( - ),1<++b &&x(),k( 7*!b,9),* U++=b&&g - ():(C=u+m&1?O=O+ O|C&1,9:write(m||( -O=C+28),&O,1)+1) )e=L[C++],u=L[C];}