remove orig code for 2012/tromp

Made 64 bit mode default.
This commit is contained in:
Landon Curt Noll committed 2023-03-07 23:32:34 -08:00
1 parent 7191df9a4d
commit 00147d39a3
4 files changed
+249 -142

No files matched your search

+2
View File
@@ -1 +1,3 @@
tromp tromp
tromp32
tromp64
+215 -83
View File
@@ -1,96 +1,163 @@
#!/usr/bin/env make #!/usr/bin/env make
# #
# 2012 makefile # IOCCC 2012 winning entry - tromp
################################################################################
# #
# This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis # Regarding individual entries:
# is licensed under: #
# 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. # Creative Commons Attribution-ShareAlike 3.0 Unported License.
# #
# See: http://creativecommons.org/licenses/by-sa/3.0/ # See: http://creativecommons.org/licenses/by-sa/3.0/
################ #############################
# tool locations # shell used by this Makefile
################ #############################
# #
SHELL= bash SHELL= bash
CP= cp
CPP= cpp #######################
GUNZIP= gunzip # common tool locations
LD= ld #######################
MAKE= make #
RM= rm include ../../var.mk
SED= sed
TAR= tar
TRUE= true
# Set X11_LIBDIR to the directory where the X11 library resides # 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 # 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= #CSILENCE=
CWARN= -Wall -W CSILENCE= -Wno-bitwise-op-parentheses -Wno-conditional-type-mismatch -Wno-error \
#CWARN= -Wall -W -pedantic -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=
#CSTD= -ansi #CSTD= -ansi
CSTD= -std=c99 CSTD= -std=gnu90
# compiler bit architecture # Compiler bit architecture
# #
# Some entries require 32-bitness: # Some entries require 32-bitness:
# ARCH= -m32 # ARCH= -m32
# #
# Some entries require 64-bitess: # Some entries require 64-bitness:
# ARCH= -m64 # ARCH= -m64
# #
# By default we assume nothing: # By default we assume nothing:
# #
ARCH= 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. # Most compiles will safely use -O2. Some can use only -O1 or -O.
# A few compilers have broken optimizers or this entry make break # A few compilers have broken optimizers or this entry make break
# under those buggy optimizers and thus you may not want anything. # under those buggy optimizers and thus you may not want anything.
# Reasonable compilers will allow for -O3.
# #
#OPT= #OPT=
#OPT= -O #OPT= -O
#OPT= -O1 #OPT= -O1
OPT= -O2 #OPT= -O2
#OPT= -O3 OPT= -O3
# Default flags for ANSI C compilation
#
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
# Libraries needed to build # Libraries needed to build
# #
LIBS= LIBS=
#LIBS= -lm
#LIBS= -L ${X11_LIBDIR} -lX11
#LIBS= -L ${HOMEBREW_PREFIX}/lib -lSDL2
# default flags for ANSI C compilation # C compiler to use
#
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.
# #
CC= cc CC= cc
#CC=clang #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 ENTRY= tromp
PROG= ${ENTRY}
#
OBJ= ${PROG}.o
DATA= how13 primes.blc uni.blc uni8.Blc bf.Blc hw.bf deflate.Blc inflate.Blc \ DATA= how13 primes.blc uni.blc uni8.Blc bf.Blc hw.bf deflate.Blc inflate.Blc \
parse.Blc symbolic.Blc primes.pl parse.Blc symbolic.Blc primes.pl
ALT_OBJ= TARGET= ${PROG} ${PROG}64
ALT_ENTRY= #
ALT_OBJ= ${ENTRY}32.o
ALT_TARGET= ${ENTRY}32
################# #################
# build the entry # build the entry
################# #################
# #
all: ${ENTRY} ${ENTRY}64 ${DATA} all: data ${TARGET}
@${TRUE} @${TRUE}
${ENTRY}: ${ENTRY}.c .PHONY: all alt data everything clean clobber install \
${CC} ${CFLAGS} -m32 -DInt=int -DX=4 -DA=500000 $< -o $@ love haste waste maker easter_egg sandwich \
supernova deep_magic magic charon pluto
${ENTRY}64: ${ENTRY}.c ${PROG}: ${PROG}.c
${CC} ${CFLAGS} -m64 -DInt=long -DX=8 -DA=500000 $< -o $@ ${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 # alternative executable
# #
alt: ${ALT_ENTRY} alt: data ${ALT_TARGET}
@${TRUE} @${TRUE}
# data files # data files
@@ -127,33 +207,51 @@ alt: ${ALT_ENTRY}
data: ${DATA} data: ${DATA}
@${TRUE} @${TRUE}
# both all and alt
#
everything: all alt
############### ###############
# utility rules # utility rules
############### ###############
# #
everything: all alt
clean: 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 clobber: clean
${RM} -f ${ENTRY} ${ENTRY}64 ${ALT_ENTRY} ${RM} -f ${TARGET} ${ALT_TARGET}
@-if [ -e sandwich ]; then \
nuke: clobber ${RM} -f sandwich; \
@${TRUE} echo 'ate sandwich'; \
fi
dist_clean: nuke
@${TRUE}
install: install:
@echo "Surely you're joking Mr. Feynman!" @echo "Dr. Spock says that is not logical!"
@${TRUE} @${TRUE}
# backwards compatibility # you may be able to misunderstand the source by reading indent.c
# #
build: all indent.c: ${PROG}.c
@${TRUE} @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} @${TRUE}
waste: waste:
@echo 'waste' @echo 'haste'
@${TRUE}
maker:
@echo 'Participate in a maker faire'
@${TRUE} @${TRUE}
easter_egg: easter_egg:
@echo you expected to mis-understand this $${RANDOM} magic @echo "you expected to often misunderstand this $${RANDOM} magic"
@echo chongo '<was here>' "/\\oo/\\" @echo "chongo '<was here>' /\\oo/\\"
@echo Readers shall be disallowed from not being unable to partly misunderstand this partocular final echo. @echo "Eggy"
# Understand the history of "I Am the Walrus" and sandwich: easter_egg
# and in particular John Lennon's remarks on that @if [ `id -u` -eq 0 ]; then \
# song and you might be confused about these next echo 'Okay.'; \
# rules in a different way. :-) echo "$${RANDOM}`date +%s`$${RANDOM}" > $@; \
#
supernova: nuke
@-if [ -r .code_anal ]; then \
${RM} -f .code_anal_v3; \
else \ else \
echo "You are not expected to understand this"; \ echo 'What? Make it yourself.'; \
exit 1; \
fi 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} @${TRUE}
deep_magic: deep_magic: supernova
@-if [ -r .code_anal ]; then \ @-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 \ else \
echo "Understand different"; \ echo "Wrong! Do it again!"; \
sleep 2; \
echo "Wrong! Do it again!"; \
sleep 2; \
echo "Wrong! Do it again!"; \
fi fi
@${TRUE} @${TRUE}
magic: deep_magic magic: deep_magic
@-if [ -r .code_anal ]; then \ @-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 \ 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 fi
@${TRUE} @${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"
+32 -32
View File
@@ -1,22 +1,21 @@
# Most functional # Most functional
John Tromp John Tromp
<john.tromp@gmail.com> <john.tromp@gmail.com>
<http://tromp.github.io/> <http://tromp.github.io/>
## To build:
## Judges' comments: make all # On a 64-bit machine (default)
### To build:
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: ### To run:
cat ascii-prog.blc data | ./tromp -b 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. are more obfuscated than the entry itself.
## Author's comments: ## Author's comments:
This program celebrates the close connection between obfuscation and conciseness, This program celebrates the close connection between obfuscation and conciseness,
by implementing the most concise language known, Binary Lambda Calculus (BLC). by implementing the most concise language known, Binary Lambda Calculus (BLC).
@@ -84,14 +84,14 @@ Voila: a half byte cat:
echo " Hello, world" | ./tromp echo " Hello, world" | ./tromp
Hello, world Hello, world
Since the least significant 4 bits of the first byte are just arbitrary padding Since the least significant 4 bits of the first byte are just arbitrary padding
that is ignored by the program, that is ignored by the program,
any character from ASCII 32 (space) through 47 (/) will do, e.g.: any character from ASCII 32 (space) through 47 (/) will do, e.g.:
echo "*Hello, world" | ./tromp echo "*Hello, world" | ./tromp
Hello, world Hello, world
Bad programs Bad programs
============ ============
@@ -109,7 +109,7 @@ causing the interpreter to crash when looking into a null-pointer environment:
echo ">Hello, world" | ./tromp echo ">Hello, world" | ./tromp
Segmentation fault Segmentation fault
Since these properties can be checked when creating BLC programs, Since these properties can be checked when creating BLC programs,
the interpreter doesn't bother checking for it. 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: The n'th bit in the output indicates whether n is prime:
cat primes.blc | ./tromp -b | head -c 70 cat primes.blc | ./tromp -b | head -c 70
0011010100010100010100010000010100000100010100010000010000010100000100 0011010100010100010100010000010100000100010100010000010000010100000100
For those who prefer to digest their primes in decimal, there is oddindices.Blc, 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) 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 ef f615ff9 46 84 058117e 05
cb fe bc bf cb fe bc bf
ee86cb9 4681600 5c0bfac bfbf71a ee86cb9 4681600 5c0bfac bfbf71a
85 e0 5c f4 85 e0 5c f4
14d5fe0 8180b048d0800e078 016445f 14d5fe0 8180b048d0800e078 016445f
fe 5f fe 5f
f7 ffffe5fff2fc 02f7ad97f5bf ff f7 ffffe5fff2fc 02f7ad97f5bf ff
ff bf ff ca af ff ff bf ff ca af ff
7817ffa df76695 4680601 57f7e16 7817ffa df76695 4680601 57f7e16
05 c1 05 c1
3fe80b2 2c18581 bfe5c10 42ff805 3fe80b2 2c18581 bfe5c10 42ff805
de ec 06 c2 c0 c0 de ec 06 c2 c0 c0
60 8191a00167fb cbcfdf65f7c0 a20 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: 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 "1") | ./tromp
_ _
| | | |
(cat hilbert.Blc; echo -n "12") | ./tromp (cat hilbert.Blc; echo -n "12") | ./tromp
_ _ _ _
| |_| | | |_| |
|_ _| |_ _|
_| |_ _| |_
(cat hilbert.Blc; echo -n "123") | ./tromp (cat hilbert.Blc; echo -n "123") | ./tromp
_ _ _ _ _ _ _ _
| |_| | | |_| | | |_| | | |_| |
|_ _| |_ _| |_ _| |_ _|
_| |_____| |_ _| |_____| |_
| ___ ___ | | ___ ___ |
|_| _| |_ |_| |_| _| |_ |_|
_ |_ _| _ _ |_ _| _
| |___| |___| | | |___| |___| |
(cat hilbert.Blc; echo -n "1234") | ./tromp (cat hilbert.Blc; echo -n "1234") | ./tromp
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| |_| | | |_| | | |_| | | |_| | | |_| | | |_| | | |_| | | |_| |
|_ _| |_ _| |_ _| |_ _| |_ _| |_ _| |_ _| |_ _|
_| |_____| |_ _| |_____| |_ _| |_____| |_ _| |_____| |_
| ___ ___ | | ___ ___ | | ___ ___ | | ___ ___ |
|_| _| |_ |_| |_| _| |_ |_| |_| _| |_ |_| |_| _| |_ |_|
_ |_ _| _ _ |_ _| _ _ |_ _| _ _ |_ _| _
| |___| |___| |_| |___| |___| | | |___| |___| |_| |___| |___| |
|_ ___ ___ ___ ___ _| |_ ___ ___ ___ ___ _|
_| |_ |_| _| |_ |_| _| |_ _| |_ |_| _| |_ |_| _| |_
| _ | _ |_ _| _ | _ | | _ | _ |_ _| _ | _ |
|_| |_| | |___| |___| | |_| |_| |_| |_| | |___| |___| | |_| |_|
_ _ | ___ ___ | _ _ _ _ | ___ ___ | _ _
| |_| | |_| _| |_ |_| | |_| | | |_| | |_| _| |_ |_| | |_| |
|_ _| _ |_ _| _ |_ _| |_ _| _ |_ _| _ |_ _|
_| |___| |___| |___| |___| |_ _| |___| |___| |___| |___| |_
A BrainFuck interpreter A BrainFuck interpreter
======================= =======================
@@ -253,7 +253,7 @@ A BrainFuck interpreter
The smallest known BF interpreter is written in... you guessed it, BLC, The smallest known BF interpreter is written in... you guessed it, BLC,
coming in at 112 bytes (including 3 bits of padding): 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 0000000 01a15144 02d55584 223070b7 00f032ff
0000020 7f85f9bf 956fe15e c0ee7d7f 006854e5 0000020 7f85f9bf 956fe15e c0ee7d7f 006854e5
0000040 fbfd5558 fd5745e0 b6f0fbeb 07d62ff0 0000040 fbfd5558 fd5745e0 b6f0fbeb 07d62ff0
@@ -299,7 +299,7 @@ So we could assemble an input reversing program as
and change it to BLC8 with and change it to BLC8 with
cat deflate.Blc reverse.blc | ./tromp > rev.Blc cat deflate.Blc reverse.blc | ./tromp > rev.Blc
wc rev.Blc wc rev.Blc
0 1 9 rev.Blc 0 1 9 rev.Blc
and then try it out with: and then try it out with:
@@ -309,7 +309,7 @@ and then try it out with:
^D ^D
!dlrow ,olleH !dlrow ,olleH
Symbolic Lambda Calculus reduction Symbolic Lambda Calculus reduction
================================== ==================================
BLC8 program symbolic.Blc shows individual reduction steps on symbolic lambda terms. BLC8 program symbolic.Blc shows individual reduction steps on symbolic lambda terms.
-27
View File
@@ -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];}