Files
Eremey Valetov ff7babdec9
Verify and publish documentation / test (macos-latest) (push) Canceled after 0s
Verify and publish documentation / test (ubuntu-latest) (push) Canceled after 0s
Verify and publish documentation / docs (push) Canceled after 0s
Verify and publish documentation / deploy (push) Canceled after 0s
Harden runtime and notebook integration and publish documentation
Validate physical cards and CLI arguments, guard live DO cells, and share
word encoding and checked numeric conversion. Preserve media on failed runs
and bound notebook input, output, execution time and process cleanup.

Clarify fixed-form editor support and compatibility evidence, add executable
quick-start examples, and gate GitHub Pages on Linux/macOS and strict docs CI.
2026-11-21 15:13:01 -05:00

225 lines
6.1 KiB
Python

#!/usr/bin/env python3
"""FORTRAN II tables 23-27, C28-6003 printed page 50.
Writes the boundary programs to the supplied output directory. A passing run prints
nothing: STOP is on stderr. The bound is allowed.
"""
import os
import sys
if len(sys.argv) != 2:
raise SystemExit("usage: %s OUTPUT_DIRECTORY" % sys.argv[0])
OUT = sys.argv[1]
def cards(label, text):
if len(text) > 660:
raise SystemExit("statement longer than 10 cards: %s" % text[:40])
lines = []
pos = 0
first = True
cont = 1
while first or pos < len(text):
chunk = text[pos : pos + 66]
pos += 66
if first:
pref = "%5d " % label if label else " "
lines.append(pref + chunk)
first = False
else:
if cont > 9:
raise SystemExit("too many continuations")
lines.append(" %d%s" % (cont, chunk))
cont += 1
if pos >= len(text):
break
for i, ln in enumerate(lines):
if len(ln) > 72:
raise SystemExit("card longer than 72: %s" % ln)
if i < len(lines) - 1 and len(ln) != 72:
raise SystemExit("short card would insert blanks: %s" % ln)
return lines
def write(name, stmts):
lines = []
for lab, text in stmts:
lines.extend(cards(lab, text))
path = os.path.join(OUT, name + ".f")
with open(path, "w") as f:
f.write("\n".join(lines) + "\n")
def names(prefix, n):
return ["%s%04d" % (prefix, i) for i in range(1, n + 1)]
def chunked(keyword, items):
stmts = []
chunk = []
def line_of(xs):
return keyword + " " + ",".join(xs)
for item in items:
if chunk and len(line_of(chunk + [item])) > 66:
stmts.append((0, line_of(chunk)))
chunk = []
chunk.append(item)
if chunk:
stmts.append((0, line_of(chunk)))
return stmts
def header(kind, name, args):
text = "%s %s" % (kind, name)
if args:
text += "(" + ",".join(args) + ")"
return (0, text)
def subdef(nsub, nfun, args, extra):
"""nsub subroutines and nfun functions, each with `args` dummies.
The last function gains `extra` further dummies. Words are
(nsub+nfun)*(1+args) + extra.
"""
stmts = []
for i in range(1, nsub + 1):
stmts.append(header("SUBROUTINE", "S%02d" % i, names("A", args)))
stmts.append((0, "RETURN"))
stmts.append((0, "END"))
for i in range(1, nfun + 1):
k = args + (extra if i == nfun else 0)
stmts.append(header("FUNCTION", "G%02d" % i, names("A", k)))
stmts.append((0, "G%02d=1.0" % i))
stmts.append((0, "RETURN"))
stmts.append((0, "END"))
stmts.append((0, "STOP"))
stmts.append((0, "END"))
return stmts
def common_units(counts):
"""One main and len(counts)-1 subroutines. Each count is the number
of COMMON names in that unit. The same spelling in two units is two
literal appearances.
"""
stmts = []
for i, n in enumerate(counts):
if i:
stmts.append((0, "SUBROUTINE S%02d" % i))
stmts.extend(chunked("COMMON", names("C", n)))
if i:
stmts.append((0, "RETURN"))
else:
stmts.append((0, "STOP"))
stmts.append((0, "END"))
return stmts
def calls(n, hol):
return [(0, "CALL S(%s)" % hol) for _ in range(n)]
def holarg(n1, n7):
"""n1 arguments of 1H (2 words) and n7 arguments of 7H (3 words),
all in the main program.
"""
stmts = [
(0, "SUBROUTINE S(X)"),
(0, "RETURN"),
(0, "END"),
(0, "SUBROUTINE S7(A)"),
(0, "DIMENSION A(2)"),
(0, "RETURN"),
(0, "END"),
]
stmts.extend(calls(n1, "1HA"))
stmts.extend([(0, "CALL S7(7Habcdefg)") for _ in range(n7)])
stmts.append((0, "STOP"))
stmts.append((0, "END"))
return stmts
def holarg_two(n):
"""The main program and subroutine T each have n arguments of 1H.
HOLARG is per program, so each total stands alone.
"""
stmts = [
(0, "SUBROUTINE S(X)"),
(0, "RETURN"),
(0, "END"),
(0, "SUBROUTINE T"),
]
stmts.extend(calls(n, "1HA"))
stmts.append((0, "RETURN"))
stmts.append((0, "END"))
stmts.extend(calls(n, "1HA"))
stmts.append((0, "STOP"))
stmts.append((0, "END"))
return stmts
def formats(n, sfn):
stmts = []
if sfn:
stmts.append((0, "BONEF(X)=X"))
stmts.extend([(0, "FORMAT(I1)") for _ in range(n)])
stmts.append((0, "STOP"))
stmts.append((0, "END"))
return stmts
def stops(n):
stmts = [(0, "STOP") for _ in range(n)]
stmts.append((0, "END"))
return stmts
def stops_split(nsub, nmain):
"""STOP statements in a subroutine and in the main program.
TSTOPS is a compilation total. 150 and 150 is 300. 150 and 151 is 301.
"""
stmts = [(0, "SUBROUTINE T")]
stmts.extend((0, "STOP") for _ in range(nsub))
stmts.append((0, "RETURN"))
stmts.append((0, "END"))
stmts.extend((0, "STOP") for _ in range(nmain))
stmts.append((0, "END"))
return stmts
def pauses(n):
stmts = [(0, "PAUSE") for _ in range(n)]
stmts.append((0, "STOP"))
stmts.append((0, "END"))
return stmts
def main():
os.makedirs(OUT, exist_ok=True)
open(os.path.join(OUT, "empty.out"), "w").close()
# 30*15 + 30*15 = 900. One more dummy on the last function is 901.
write("subdef-ok", subdef(30, 30, 14, 0))
write("subdef-over", subdef(30, 30, 14, 1))
write("common-ok", common_units([256, 256, 88]))
write("common-over", common_units([256, 256, 89]))
write("holarg-ok", holarg(450, 0))
write("holarg-over", holarg(449, 1))
write("holarg-two", holarg_two(450))
write("nonexc-ok", formats(1499, False))
write("nonexc-over", formats(1500, False))
write("nonexc-sfn", formats(1498, True))
write("nonexc-sfnover", formats(1499, True))
write("tstops-ok", stops(300))
write("tstops-over", stops(301))
write("tstops-split-ok", stops_split(150, 150))
write("tstops-split-over", stops_split(150, 151))
write("tstops-pause", pauses(301))
if __name__ == "__main__":
main()