Merge pull request #1142 from xexyl/1991-dds-alt-improvement
This commit is contained in:
3 files changed
+59
-37
No files matched your search
+1
-1
@@ -133,7 +133,7 @@ ${PROG}: ${PROG}.c
|
|||||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||||
|
|
||||||
a: a.c
|
a: a.c
|
||||||
${CC} ${CFLAGS} -Wno-return-type $< -o $@ ${LDFLAGS}
|
${CC} ${CFLAGS} -Wno-return-type $< -o a.out ${LDFLAGS}
|
||||||
|
|
||||||
# alternative executable
|
# alternative executable
|
||||||
#
|
#
|
||||||
|
|||||||
+52
-35
@@ -12,6 +12,8 @@ Mastodon: <https://mstdn.social/@DSpinellis>
|
|||||||
make all
|
make all
|
||||||
```
|
```
|
||||||
|
|
||||||
|
There is an alt version for those who use `clang`. See [Alternate
|
||||||
|
code](#alternate-code) below.
|
||||||
|
|
||||||
## To run:
|
## To run:
|
||||||
|
|
||||||
@@ -27,15 +29,6 @@ memory as a `char *s`. It's now a `char s[]`.
|
|||||||
|
|
||||||
NOTE: for `clang` you'll likely have to use the alternate code described below.
|
NOTE: for `clang` you'll likely have to use the alternate code described below.
|
||||||
|
|
||||||
### INABIAF - it's not a bug it's a feature! :-)
|
|
||||||
|
|
||||||
Please note that if the BASIC file cannot be opened for reading or the output
|
|
||||||
file cannot be opened for writing then this program will very likely crash or do
|
|
||||||
something funny.
|
|
||||||
|
|
||||||
These are a mild nuisance but are considered a feature not a bug. We challenge
|
|
||||||
you to fix it for learning if you wish. See also [bugs.md](/bugs.md).
|
|
||||||
|
|
||||||
|
|
||||||
## Try:
|
## Try:
|
||||||
|
|
||||||
@@ -46,7 +39,7 @@ make dds
|
|||||||
```
|
```
|
||||||
|
|
||||||
For example, the author suggests trying:
|
For example, the author suggests trying:
|
||||||
\
|
|
||||||
```sh
|
```sh
|
||||||
./dds LANDER.BAS 2>/dev/null
|
./dds LANDER.BAS 2>/dev/null
|
||||||
./a.out 2>/dev/null
|
./a.out 2>/dev/null
|
||||||
@@ -64,34 +57,57 @@ other types of files?
|
|||||||
|
|
||||||
### Alternate code:
|
### Alternate code:
|
||||||
|
|
||||||
The alternate code allows this entry to work successfully even with clang.
|
This alternate code allows this entry to work successfully even with clang.
|
||||||
Unfortunately it's something of a hack or maybe even a kludge. This however
|
Unfortunately it's something of a hack or maybe even a kludge. This however
|
||||||
seems important because it works well and allows for not messing with the `s`
|
seems important because it works well and allows for not messing with the `s`
|
||||||
string which is quite complicated. Even changing the length could break
|
string which is quite complicated. Even changing the length could break
|
||||||
functionality and indeed the length would have to be longer for this to work
|
functionality and indeed the length would have to be longer for this to work
|
||||||
with clang.
|
with clang.
|
||||||
|
|
||||||
How does it work? The code (which you will see in [dds.c](dds.c)) does a `return
|
How does it work? The original code (which you will see in [dds.c](dds.c)) does
|
||||||
system(q-6);` which equates to `return system("cc a.c");` but clang by default,
|
a `return system(q-6);` which equates to `return system("cc a.c");` but clang by
|
||||||
at least in macOS, has default -Werror and there were some warnings. This means
|
default, at least in macOS, has default `-Werror` and there were some warnings.
|
||||||
that the compilation failed with clang (because it didn't use `make` so no
|
This means that the compilation failed with clang (because it didn't use `make`
|
||||||
[Makefile](Makefile) was used). In particular it would fail (at least with
|
so no [Makefile](Makefile) was used). In particular it would fail (at least with
|
||||||
[LANDER.BAS](LANDER.BAS)) due to a return from `main()` without a return value
|
[LANDER.BAS](LANDER.BAS)) due to a return from `main()` without a return value
|
||||||
and the use of functions not yet declared.
|
and the use of functions not yet declared.
|
||||||
|
|
||||||
Now as noted since the string `s` is complicated and to not inadvertently mess
|
Now as noted since the string `s` is complicated and to not inadvertently mess
|
||||||
something up it was changed so that the code uses `system("make a");` and then an
|
something up it was changed so that the code uses `system("make a");` and then an
|
||||||
appropriate rule was added to the Makefile. Thus for the alternative version you
|
appropriate rule was added to the Makefile. Thus for the alternative version you
|
||||||
now need both `make` and `cc`. If you use gcc you can change the `system()` call
|
now need both `make` and `cc`. If you use gcc you can just use the original
|
||||||
to what was given in this description to get a more authentic feel. If you do
|
version.
|
||||||
this you must then run `./a.out` not `./a`! Thus to use the alternative version:
|
|
||||||
|
#### To build:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make clobber alt
|
make alt
|
||||||
./dds.alt LANDER.BAS 2>/dev/null
|
|
||||||
./a 2>/dev/null
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### To run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./dds.alt some_basic_program.bas 2>/dev/null
|
||||||
|
./a.out 2>/dev/null
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Try:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./dds LANDER.BAS 2>/dev/null
|
||||||
|
./a.out 2>/dev/null
|
||||||
|
```
|
||||||
|
|
||||||
|
### INABIAF - it's not a bug it's a feature! :-)
|
||||||
|
|
||||||
|
Please note that if the BASIC file cannot be opened for reading or the output
|
||||||
|
file cannot be opened for writing then this program will very likely crash or do
|
||||||
|
something funny.
|
||||||
|
|
||||||
|
These are a mild nuisance but are considered a feature not a bug. We challenge
|
||||||
|
you to fix it for learning if you wish. See also [bugs.md](/bugs.md).
|
||||||
|
|
||||||
|
|
||||||
## Judges' remarks:
|
## Judges' remarks:
|
||||||
|
|
||||||
Notice that a file `a.c` has been generated. Can you tell how `a.c` was
|
Notice that a file `a.c` has been generated. Can you tell how `a.c` was
|
||||||
@@ -103,22 +119,23 @@ C programs by way of an obfuscated algorithm.
|
|||||||
|
|
||||||
## Author's remarks:
|
## Author's remarks:
|
||||||
|
|
||||||
This program is a companion to the DDS-BASIC interpreter program that
|
This program is a companion to the [DDS-BASIC interpreter
|
||||||
was submitted to the contest in 1990. This compiles BASIC programs into
|
program](/1990/dds/README.md) that was submitted to [the contest in
|
||||||
executable commands. The input format is almost identical to the input
|
1990](/years.html#1990). This compiles BASIC programs into executable commands.
|
||||||
format of the DDS-BASIC interpreter. The program needs an executable C
|
The input format is almost identical to the input format of the DDS-BASIC
|
||||||
compiler called `cc` in your path in order to work.
|
interpreter. The program needs an executable C compiler called `cc` in your
|
||||||
|
path in order to work.
|
||||||
|
|
||||||
### Program commands:
|
### Program commands:
|
||||||
|
|
||||||
|
|
||||||
- variable names A to Z\
|
- variable names A to Z
|
||||||
- FOR var = exp TO exp\
|
- FOR var = exp TO exp
|
||||||
- GOSUB exp\
|
- GOSUB exp
|
||||||
- GOTO exp\
|
- GOTO exp
|
||||||
- INPUT variable\
|
- INPUT variable
|
||||||
- PRINT exp\
|
- PRINT exp
|
||||||
- REM any text\
|
- REM any text
|
||||||
- variables initialized to 0 on RUN
|
- variables initialized to 0 on RUN
|
||||||
- NEXT variable
|
- NEXT variable
|
||||||
- RETURN
|
- RETURN
|
||||||
@@ -137,7 +154,7 @@ Many system calls and C library calls can be used.
|
|||||||
- Exactly one space is needed after the FOR and NEXT tokens
|
- Exactly one space is needed after the FOR and NEXT tokens
|
||||||
- ALL INPUT MUST BE UPPERCASE.
|
- ALL INPUT MUST BE UPPERCASE.
|
||||||
|
|
||||||
Error checking / error reports:
|
### Error checking / error reports:
|
||||||
|
|
||||||
The compiler silently ignores many errors.
|
The compiler silently ignores many errors.
|
||||||
Other errors may produce errors in later phases of the compilation.
|
Other errors may produce errors in later phases of the compilation.
|
||||||
|
|||||||
+6
-1
@@ -788,9 +788,14 @@ slightly more like the original, even though it's unused.
|
|||||||
|
|
||||||
Cody fixed a segfault that prevented this entry from working in any condition
|
Cody fixed a segfault that prevented this entry from working in any condition
|
||||||
and he also made an [alternate version](1991/dds/dds.alt.c) that works with
|
and he also made an [alternate version](1991/dds/dds.alt.c) that works with
|
||||||
`clang`. The alternate code, described in the README.md file, is what is needed
|
`clang`.
|
||||||
|
|
||||||
|
The alternate code, described in the README.md file, is what is needed
|
||||||
for clang. Reading it might be instructive even if you have gcc.
|
for clang. Reading it might be instructive even if you have gcc.
|
||||||
|
|
||||||
|
Later on Cody improved the fix for clang by a slight modification to the
|
||||||
|
Makefile so that the compiled program is the same as with gcc: `a.out`.
|
||||||
|
|
||||||
## [1991/fine](1991/fine/fine.c) ([README.md](1991/fine/README.md))
|
## [1991/fine](1991/fine/fine.c) ([README.md](1991/fine/README.md))
|
||||||
|
|
||||||
Cody made it look much more like the original entry even after the fix that
|
Cody made it look much more like the original entry even after the fix that
|
||||||
|
|||||||
Reference in new issue
Block a user