Updates to 1991/brnstnd
Since the author refers to the tool as 'sorta' it is now a symlink to the program. Updated .gitignore. The sorta.README.md file has been format fixed. The README.md has been partially checked. The reason for this commit when it's not is I need to find where a problem in formatting is and in order to do that I need to see the rendered html (a code block is not terminated it would appear).
This commit is contained in:
1 parent
478e620eaa
commit
b7784a3102
4 files changed
+43
-41
No files matched your search
@@ -1,3 +1,4 @@
|
||||
brnstnd
|
||||
brnstnd.orig
|
||||
prog.orig
|
||||
sorta
|
||||
@@ -133,6 +133,7 @@ all: data ${TARGET}
|
||||
|
||||
${PROG}: ${PROG}.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||
${LN} -sf $@ sorta
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
|
||||
+26
-26
@@ -21,7 +21,7 @@ For info on more examples, read the [sorta.README.md](sorta.README.md) file.
|
||||
|
||||
The author wished to win the "most useful program" award and documented this in
|
||||
the source code. The judges were unmoved by this blatant attempt to influence
|
||||
the contest and rejected this idea... so we gave it the `Best of Show`
|
||||
the contest and rejected this idea... so we gave it the "Best of Show"
|
||||
instead!!
|
||||
|
||||
NOTE: One should remove the final trailing newline to obtain the
|
||||
@@ -51,12 +51,12 @@ instance, not to mention infinite-depth tail recursion.
|
||||
|
||||
SORTA ignores its arguments (though it makes them available to the
|
||||
script); it takes all commands, character by character, from its
|
||||
standard input. Unrecognized commands are repeated with a '?'.
|
||||
standard input. Unrecognized commands are repeated with a `'?'`.
|
||||
|
||||
SORTA maintains an `i stack` for integers and an `s stack` for strings. It also
|
||||
SORTA maintains an `i` stack for integers and an `s` stack for strings. It also
|
||||
keeps track of `programs`, one for each character. Operations are silently
|
||||
ignored if the relevant stacks are too low, except as noted for `s`, `S`, and
|
||||
`!`. If the `i stack` or `s stack` (or the stack of buffered macro commands)
|
||||
`!`. If the `i` stack or `s` stack (or the stack of buffered macro commands)
|
||||
grows too high, SORTA will exit silently with exit code 2. (Compile parameter
|
||||
`-Do=250` controls what 'too high' means; you should not make `o` larger than
|
||||
250.) I don't think it's possible to crash the interpreter.
|
||||
@@ -68,24 +68,24 @@ delimiters.
|
||||
### Basic operations
|
||||
|
||||
- `q`: quit
|
||||
- `number`: push that number on top of the i stack
|
||||
- `"string"`: push that string on top of the s stack, no length limit
|
||||
- `[string]`: push that string on top of the s stack, no length limit
|
||||
- `#`: make top of i stack non-destructively in ASCII, push result onto s stack
|
||||
- ` ` `: print top of s stack non-destructively
|
||||
- `$`: print top of s stack non-destructively without newline
|
||||
- `d`: drop (pop) top of i stack
|
||||
- `D`: dup (duplicate) top of i stack
|
||||
- `number`: push that number on top of the `i` stack
|
||||
- `"string"`: push that string on top of the `s` stack, no length limit
|
||||
- `[string]`: push that string on top of the `s` stack, no length limit
|
||||
- `#`: make top of `i` stack non-destructively in ASCII, push result onto `s` stack
|
||||
- ` ` `: print top of `s` stack non-destructively
|
||||
- `$`: print top of `s` stack non-destructively without newline
|
||||
- `d`: drop (pop) top of `i` stack
|
||||
- `D`: dup (duplicate) top of `i` stack
|
||||
- `'`: dup top of s stack
|
||||
- `s`: pop top of i stack. If it is `n`, swap `(n+1)`th-top of `i` stack with top.
|
||||
`1s`, for example, swaps the top two elements; `2s` swaps the top with the
|
||||
third down; etc. This always pops the top of the `i stack`, even upon
|
||||
third down; etc. This always pops the top of the `i` stack, even upon
|
||||
failure.
|
||||
- `S`: pop top of `i stack`, then act just like `s` but upon `s stack`
|
||||
- `l`: pop top of `s stack`, push its length onto `i stack`
|
||||
- `S`: pop top of `i` stack, then act just like `s` but upon `s` stack
|
||||
- `l`: pop top of `s` stack, push its length onto `i` stack
|
||||
- `a`: push argc onto i stack
|
||||
- `A`: pop top of `i stack`, push `argv[i]` on top of `s stack`
|
||||
- `T`: concatenate top two elements of `s stack`
|
||||
- `A`: pop top of `i` stack, push `argv[i]` on top of `s` stack
|
||||
- `T`: concatenate top two elements of `s` stack
|
||||
- ` _ `: negate top of i stack
|
||||
- `+`: pop top two elements of i stack, add, push back sum
|
||||
- ` * `: pop top two elements of i stack, multiply, push back product
|
||||
@@ -97,17 +97,17 @@ delimiters.
|
||||
|
||||
### System operations
|
||||
|
||||
- `o`: pop top of `s stack` and top two of `i stack`; `open(s1,i2,i1);` leave
|
||||
result on `i stack`
|
||||
- `O`: pop top of `i stack`, `close()` it
|
||||
- `u`: pop top of `i stack`, `dup()` it, push result back on
|
||||
- `F`: `fork()`, push result on `i stack`. This is not always safe while SORTA is
|
||||
- `o`: pop top of `s` stack and top two of `i` stack; `open(s1,i2,i1);` leave
|
||||
result on `i` stack
|
||||
- `O`: pop top of `i` stack, `close()` it
|
||||
- `u`: pop top of `i` stack, `dup()` it, push result back on
|
||||
- `F`: `fork()`, push result on `i` stack. This is not always safe while SORTA is
|
||||
reading keyboard input or a script, as the forked programs share file
|
||||
descriptors. It is always safe inside a program (see below).
|
||||
- `P`: `pipe()`, push two ends `<p0> <p1>` onto `i stack`. In case of trouble,
|
||||
`push <?> <-1>` onto `i stack`.
|
||||
- `w`: `wait()`, push successful result (or -1 if no children) on `i stack`
|
||||
- `!`: `execvp()` top of the `s stack`. Arguments are the next things down on
|
||||
- `P`: `pipe()`, push two ends `<p0> <p1>` onto `i` stack. In case of trouble,
|
||||
`push <?> <-1>` onto `i` stack.
|
||||
- `w`: `wait()`, push successful result (or -1 if no children) on `i` stack
|
||||
- `!`: `execvp()` top of the `s` stack. Arguments are the next things down on
|
||||
the s stack, in reverse order from popping; the first character of
|
||||
each string is lopped off. There must be an empty string somewhere
|
||||
in the s stack to terminate the argument list. If the execve()
|
||||
|
||||
@@ -56,13 +56,13 @@ This is self-explanatory.
|
||||
1=D 1s# " | "T 1s#T " is "T D&1sD&& #T$ld " (" 1=2 ")"T `ld
|
||||
1=D 1s# " ^ "T 1s#T " is "T 1=D&2sD&1sD&&&D& #T$ld " (" 1=2 ")"T `ld
|
||||
|
||||
`icalc` shows off SORTA's understanding of integer arithmetic. You can run
|
||||
`icalc` shows off `SORTA`'s understanding of integer arithmetic. You can run
|
||||
it with up to two arguments; the arguments have default values of 27182
|
||||
and 3145. Notice that sorta doesn't have a language primitive for
|
||||
and 3145. Notice that `SORTA` doesn't have a language primitive for
|
||||
converting a string to a number, yet `icalc` is performing arithmetic on
|
||||
its arguments. Can you see how? (Hint: Try `./brnstnd "2 2+" 3 < sorta.icalc`.
|
||||
its arguments. Can you see how? (Hint: Try `./sorta "2 2+" 3 < sorta.icalc`.
|
||||
Look at program A.) `icalc` also provides a useful binary output routine,
|
||||
and if you can't remember offhand that `D2sD3s&2sD&1sD&&&D&` means xor,
|
||||
and if you can't remember offhand that `D2sD3s&2sD&1sD&&&D&` means XOR,
|
||||
you can just look it up here.
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ you can just look it up here.
|
||||
0""1=y`
|
||||
|
||||
This script prints out the maximum file descriptor available from
|
||||
repeated dup()s---usually NOFILE - 1. Can you see how it works?
|
||||
repeated `dup(2)`s---usually `NOFILE - 1`. Can you see how it works?
|
||||
|
||||
|
||||
# [sorta.iecho](sorta.iecho)
|
||||
@@ -83,9 +83,9 @@ repeated dup()s---usually NOFILE - 1. Can you see how it works?
|
||||
[1s1+DA$ld1s1_+D=sD=x]:xld [ given n (argc-n), print args ]ld
|
||||
0a1_+D=x""` [ simulation of /bin/echo ]ld
|
||||
|
||||
This is a clone of /bin/echo, minus any argument processing and escape
|
||||
interpretation. (Note that, unlike some shells' echo, /bin/echo prints a
|
||||
newline even with no arguments.) Try sorta foo bar < iecho.
|
||||
This is a clone of `/bin/echo`, minus any argument processing and escape
|
||||
interpretation. (Note that, unlike some shells' echo, `/bin/echo` prints a
|
||||
newline even with no arguments.) Try `./sorta foo bar < iecho`.
|
||||
|
||||
|
||||
# [sorta.ifact1](sorta.ifact1)
|
||||
@@ -105,8 +105,8 @@ multiply by 2, print it, multiply by 3, print it, etc.
|
||||
1=f 1=f 1=f 1=f 1=f 1=f 1=f 1=f 1=f 1=f
|
||||
|
||||
`ifact1` does a lot of repeated work. `ifact2` takes advantage of this by
|
||||
keeping the current `n!` n on the stack. Each call to routine f (1=f)
|
||||
increments n by 1 and prints out the factorial.
|
||||
keeping the current `n!` `n` on the stack. Each call to routine `f (1=f)`
|
||||
increments `n` by `1` and prints out the factorial.
|
||||
|
||||
|
||||
# [sorta.ifact3](sorta.ifact3)
|
||||
@@ -117,7 +117,7 @@ increments n by 1 and prints out the factorial.
|
||||
0 1 10 1=x
|
||||
|
||||
Finally, `ifact3` removes all the redundancy from `ifact2`, and exhibits
|
||||
proper documentation of stack routines. You can replace the 10 by
|
||||
proper documentation of stack routines. You can replace the `10` by
|
||||
anything in this version.
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ anything in this version.
|
||||
|
||||
["] "2 2+":xT ["]T " produces "T 1=x#T " which should be 4."T`
|
||||
|
||||
Notice that "2 2+" is a literal string inside the program.
|
||||
Notice that `"2 2+"` is a literal string inside the program.
|
||||
|
||||
|
||||
# [sorta.irot13](sorta.irot13)
|
||||
@@ -144,7 +144,7 @@ Notice that "2 2+" is a literal string inside the program.
|
||||
0Ou1=x [ in a more complex spawner, this would be done under a fork ]ld
|
||||
|
||||
Despite its name, `irot13` is meant to show how to exec a program with
|
||||
redirection from within sorta. You run it as `./brnstnd blah < irot13`; it
|
||||
redirection from within `sorta`. You run it as `./sorta blah < irot13`; it
|
||||
opens `blah` and runs a (BSD-style) `tr` command to rotate all letters by 13
|
||||
spots. `1A 0 0 o` opens `argv[1]`; the ` ' ` keeps the filename around for
|
||||
subroutine `h` to print a nice error message if necessary. `0Ou` closes
|
||||
@@ -170,8 +170,8 @@ This script illustrates the classic fork-exec-wait.
|
||||
[3*#" "T$ldD=f]:f
|
||||
1=f
|
||||
|
||||
The sole purpose of this script is to prove that sorta can do infinite
|
||||
tail recursion (in this case, in program `f`). Do `./brnstnd < itailrec | more`
|
||||
The sole purpose of this script is to prove that `sorta` can do infinite
|
||||
tail recursion (in this case, in program `f`). Do `./sorta < itailrec | more`
|
||||
and watch the powers of 3 (mod your computer's word size) flow by.
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user