Try fixing 2011/richards + update README.md
This does not work with macOS but I'm not sure if this has to do with
macOS or the fact it's the Apple silicon chip. The fact it works in
linux makes it harder to figure out what the problem is. Still I tried
to change the protection of the mmap() call. Different values can
actually make it crash in linux as well but this does work. Of course
the fact it works with linux doesn't mean much since it already did work
with linux. This is a work in progress. Doing
make CC=clang CSILENCE= CWARN="-Wall -Wextra -Weverything" clobber all
can give a lot of interesting warnings that might or might not be
relevant including one about alignment. In bugs.md I cited where it
appears to crash.
Format fixed the README.md.
This commit is contained in:
1 parent
7af99c8c9e
commit
d0ac8c8213
4 files changed
+44
-14
No files matched your search
@@ -61,7 +61,7 @@ CDEFINE=
|
||||
|
||||
# Include files that are needed to compile
|
||||
#
|
||||
CINCLUDE=
|
||||
CINCLUDE= -include stdlib.h -include string.h -include stdio.h -include ctype.h
|
||||
|
||||
# Optimization
|
||||
#
|
||||
|
||||
+15
-12
@@ -1,7 +1,7 @@
|
||||
# Most surprisingly portable
|
||||
|
||||
Gregor Richards
|
||||
<Richards@codu.org>
|
||||
Gregor Richards
|
||||
<Richards@codu.org>
|
||||
|
||||
## To build:
|
||||
|
||||
@@ -21,6 +21,9 @@ make
|
||||
echo '10 9 8 7 6 5 4 3 2 1*p*p*p*p*p*p*p*p*p' | ./richards
|
||||
```
|
||||
|
||||
NOTE: this entry does not work in macOS. See [bugs.md](/bugs.md) for more
|
||||
details.
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
Oh no, yet another dc-style calculator? (see 2000/dlowe using an embedded Perl
|
||||
@@ -34,7 +37,7 @@ What would you do to prove or disprove his claim without attempting to unravel t
|
||||
This is an implementation of the classic UNIX dc command, the reverse-polish
|
||||
calculator. Actually it's a pretty bad implementation, since it only implements
|
||||
32-bit integers (well, sizeof(int)-sized integers). It only implements the
|
||||
commands +, -, *, /, p (only for numbers), register stacks, macros and
|
||||
commands `+`, `-`, `*`, `/`, `p` (only for numbers), register stacks, macros and
|
||||
comparisons. Wow, you'd think I could've done better in 2K of code.
|
||||
|
||||
OH! I forgot to mention! It's a JIT.
|
||||
@@ -48,19 +51,19 @@ integers are at least 32-bit.
|
||||
You will probably get warnings while compiling the code. In particular:
|
||||
|
||||
* If your system requires the inclusion of alloca.h to use alloca, use the
|
||||
compile flag -DAH
|
||||
* If your system cannot use mmap, use the compile flag -DNM
|
||||
compile flag `-DAH`.
|
||||
* If your system cannot use mmap, use the compile flag `-DNM`.
|
||||
* I don't include any headers I don't strictly need to, so you'll get warnings
|
||||
about (at least) memcpy, isdigit, atoi, calloc, malloc and alloca if you
|
||||
didn't use -DAH.
|
||||
* GCC likes to complain about while (a = b) (assignments as a condition).
|
||||
* I don't return from main, even though it's declared to return int.
|
||||
about (at least) `memcpy()`, `isdigit()`, `atoi()`, `calloc()`, `malloc()`
|
||||
and `alloca()` if you didn't use `-DAH`.
|
||||
* GCC likes to complain about `while (a = b)` (assignments as a condition).
|
||||
* I don't return from `main()`, even though it's declared to return int.
|
||||
|
||||
Platforms on which all known/tested optimization levels work with no additional
|
||||
flags:
|
||||
|
||||
* gcc 4.6.2 + x86[_64] + GNU/Linux, Mac OS X or Windows
|
||||
* clang 2.9-16 + x86[_64] + GNU/Linux or Mac OS X
|
||||
* gcc 4.6.2 + x86[\_64] + GNU/Linux, Mac OS X or Windows
|
||||
* clang 2.9-16 + x86[\_64] + GNU/Linux or Mac OS X
|
||||
* tcc 0.9.25
|
||||
* gcc 4.4.5 + alpha, arm, mips[el], powerpc[64], s390x (IBM zSeries)
|
||||
* gcc 4.1.3 + vax + NetBSD
|
||||
@@ -68,7 +71,7 @@ flags:
|
||||
Platforms which work but not at all optimization levels or needing special
|
||||
flags:
|
||||
|
||||
* owcc 1.9 + x86 + Windows: Needs -DNM -DAH -fno-stack-check
|
||||
* owcc 1.9 + x86 + Windows: Needs `-DNM -DAH -fno-stack-check`
|
||||
* gcc 4.4.5 + sh4: -O0 works, higher optimization levels don't work for unknown reasons.
|
||||
|
||||
## Copyright and CC BY-SA 4.0 License:
|
||||
|
||||
@@ -192,7 +192,7 @@ u main()
|
||||
#if NM
|
||||
malloc(H);
|
||||
#else
|
||||
mmap(0, H, -1, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
mmap(NULL, H, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
|
||||
#endif
|
||||
while (b = fgets(malloc(999), 999, stdin))
|
||||
((f) K(b, d)) (d);
|
||||
|
||||
Reference in new issue
Block a user