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:
Cody Boone Ferguson committed 2023-05-01 09:10:07 -07:00
1 parent 7af99c8c9e
commit d0ac8c8213
4 files changed
+44 -14

No files matched your search

+1 -1
View File
@@ -61,7 +61,7 @@ CDEFINE=
# Include files that are needed to compile # Include files that are needed to compile
# #
CINCLUDE= CINCLUDE= -include stdlib.h -include string.h -include stdio.h -include ctype.h
# Optimization # Optimization
# #
+15 -12
View File
@@ -1,7 +1,7 @@
# Most surprisingly portable # Most surprisingly portable
Gregor Richards Gregor Richards
<Richards@codu.org> <Richards@codu.org>
## To build: ## 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 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: ## Judges' remarks:
Oh no, yet another dc-style calculator? (see 2000/dlowe using an embedded Perl 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 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 calculator. Actually it's a pretty bad implementation, since it only implements
32-bit integers (well, sizeof(int)-sized integers). It only implements the 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. comparisons. Wow, you'd think I could've done better in 2K of code.
OH! I forgot to mention! It's a JIT. 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: 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 * If your system requires the inclusion of alloca.h to use alloca, use the
compile flag -DAH compile flag `-DAH`.
* If your system cannot use mmap, use the compile flag -DNM * 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 * 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 about (at least) `memcpy()`, `isdigit()`, `atoi()`, `calloc()`, `malloc()`
didn't use -DAH. and `alloca()` if you didn't use `-DAH`.
* GCC likes to complain about while (a = b) (assignments as a condition). * 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. * 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 Platforms on which all known/tested optimization levels work with no additional
flags: flags:
* gcc 4.6.2 + x86[_64] + GNU/Linux, Mac OS X or Windows * 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 * clang 2.9-16 + x86[\_64] + GNU/Linux or Mac OS X
* tcc 0.9.25 * tcc 0.9.25
* gcc 4.4.5 + alpha, arm, mips[el], powerpc[64], s390x (IBM zSeries) * gcc 4.4.5 + alpha, arm, mips[el], powerpc[64], s390x (IBM zSeries)
* gcc 4.1.3 + vax + NetBSD * gcc 4.1.3 + vax + NetBSD
@@ -68,7 +71,7 @@ flags:
Platforms which work but not at all optimization levels or needing special Platforms which work but not at all optimization levels or needing special
flags: 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. * gcc 4.4.5 + sh4: -O0 works, higher optimization levels don't work for unknown reasons.
## Copyright and CC BY-SA 4.0 License: ## Copyright and CC BY-SA 4.0 License:
+1 -1
View File
@@ -192,7 +192,7 @@ u main()
#if NM #if NM
malloc(H); malloc(H);
#else #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 #endif
while (b = fgets(malloc(999), 999, stdin)) while (b = fgets(malloc(999), 999, stdin))
((f) K(b, d)) (d); ((f) K(b, d)) (d);
+27
View File
@@ -1829,6 +1829,33 @@ instead being something else entirely. The Internet Wayback Machine, although it
archived it, did not load scripts. Do you know if the domain was moved? Do you archived it, did not load scripts. Do you know if the domain was moved? Do you
have an archive or mirror? Please provide us it! Thank you. have an archive or mirror? Please provide us it! Thank you.
## [2011/richards](2011/richards/richards.c) ([README.md](2011/richards/README.md))
## STATUS: doesn't work with some platforms - please help us fix
This does not appear to work with macOS. We're not sure if this is to do with
the Apple silicon chip or not. At a glance it appears to be that it might be the
function pointers. In particular it seems to crash at:
```c
W(1) while ((c = *p)) {
```
in the `K` function. It's called like this, from main():
```c
while (b = fgets(malloc(999), 999, stdin))
((f) K(b, d)) (d);
```
But what is curious is that it seems to have different problems depending on the
macros defined. In an attempt to get it to work the `mmap()` call was changed to
allow for exec and read and write (which might be a problem in such a
combination) but this only works in linux (it already did work in linux,
however, so this doesn't help much).
Do you have a fix? We welcome it!
# 2012 # 2012