Files
ioccc/2011/richards
Landon Curt Noll ecabb73bf6 add tools to compare entry's manifest with its files
Added `bin/bin/tar-entry.sh` to build a compressed tarball for an
entry.  The compressed tarball is formed by gnu tar with options
so that the same entry file content will always produce the same
compressed tarball, byte for byte.

As some files are missing from some entries, one should
use the `-W` option as in:

```sh
bin/tar-entry.sh -v 5 -W 2020/ferguson1
```

Added `make form_entry_tarball` to the top level `Makefile`
to build entry tarballs even when files are still missing.

Added `make verify_entry_files` to verify that all entries have all
of their files listed in their manifest, plus the top level ioccc.css
and var.mk files.  As file entry files are still missing (due to
HTML files that need to be built), the overall `make quick_www` and
`make www` do **NOT** (yet) exit when the `make verify_entry_files`
fails.

Improved `bin/chk-entry.sh` by removing some variables
that were not needed.

TODO: Improve `bin/` tool exit codes as the current use is a bit silly.

TODO: Clean out some variables used in `bin/` tools as some of then
are only set printed in debug statements.

TODO: Clean up usage messages, some of the options listed to not
match the `getopts(1)` parsing.  In some cases the option needs to
be parsed but needs to be ignored by the tool because another tool
automatically passes along certain options that really have no
effect.  Such ignored options need to be show as "This option is
ignored" in the usage message.
2024-02-13 03:29:54 -08:00
..
2024-02-01 14:35:49 -08:00
2023-12-26 09:00:03 -08:00
2023-05-08 04:36:28 -07:00
2023-07-06 21:49:38 -07:00
2024-01-24 08:32:46 -08:00
2024-01-24 08:32:46 -08:00

To build:

make

Bugs and (Mis)features:

The current status of this entry is:

STATUS: doesn't work with some platforms - please help us fix

For more detailed information see 2011 richards in bugs.md.

To use:

echo expression | ./richards

Try:

./try.sh

Judges' remarks:

Oh no, yet another dc-style calculator? (see 2000/dlowe using an embedded Perl interpreter and deemed Worst Abuse of the Rules). Well, this one does it (expression calculation, that is, not the rule abuse) in a different way. The author claims that his calculator does just-in-time compilation. What would you do to prove or disprove his claim without attempting to unravel the source?

Author's remarks:

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 comparisons. Wow, you'd think I could've done better in 2K of code.

OH! I forgot to mention! It's a JIT.

Wait, don't stop reading! I know what you're thinking, platform-specific code is discouraged in IOCCC. But do you see any platform-specific code? There's no assembler here! This JIT works on a dozen platforms, and the only platform-specific assumptions it makes are that the stack grows down and 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.

  • 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.

    • NOTE from judges: we added these includes in 2023.
  • 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
  • tcc 0.9.25
  • gcc 4.4.5 + alpha, arm, mips[el], powerpc[64], s390x (IBM zSeries)
  • gcc 4.1.3 + vax + NetBSD

Platforms which work but not at all optimization levels or needing special flags:

  • 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.

This file is Copyright (c) 2023 by Landon Curt Noll. All Rights Reserved. You are free to share and adapt this file under the terms of this license:

Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)

For more information, see: https://creativecommons.org/licenses/by-sa/4.0/