raz / commit 23f6bd0d

commit
23f6bd0ddf5b5bee0226e8ebff8cd8aefc78308e
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
5b585758
Drop seed-check, by the owner's word

src/ and the seed have grown apart: the dumper pairs that compared them
unit by unit, src/check.sh and its list of files the seed can't read,
go. make fixpoint and make seed-bench stay; test/Recover.raz runs in
make check. continue takes its alphabetical place among the reserved
words, which kept the seed's numbers only for those dumpers.

patch · log

30 files changed, +42 -4744

CLAUDE.md modified +5 -6

@@ -15,7 +15,7 @@
1515 make kernels # test/bench's kernels against FPC -O2's twins
1616 make loc # lines of the compiler, by rloc; the last, code, is the budget
1717 make tests # the small Pascal tests of scan, x64, link and elf
18- make seed-check # src/ against the seed: scan to x64, then the messages and statuses of every program
18+ make seed-bench # the scanner's and the compiler's speed against the seed's
1919 make fixpoint # the seed builds src, that builds src, that again: the last two agree
2020 make gdb # gdb stops at a line of a test and names it
2121 make stress # 40,000 native threads; make check runs a small version
@@ -135,8 +135,10 @@
135135 `src/` is the compiler, in raz: one module to a
136136 seed unit, the same names. `seed/`, the Free Pascal compiler it was
137137 ported from, is the **seed**: frozen at its last version, kept to build
138-`src/` the first time and as the reference its units are tested
139-against, and to be dropped in time. Never edit the seed; a difference
138+`src/` the first time (`make raz`, `make fixpoint`), and to be dropped
139+in time. `src/` is no longer tested against it unit by unit (the owner
140+dropped `seed-check` after v0.17.0): `make check`, the fixpoint and
141+`conform/` are its tests. Never edit the seed; a difference
140142 found is told to the owner.
141143
142144 `sbcl/` is an example, not part of the build: a second compiler, in
@@ -237,9 +239,6 @@
237239 is written with its type; shared with anything else, the name alone is
238240 that other declaration. A `match` arm on an enumeration takes the
239241 type's names alone or with the type, which must be the matched one.
240-- `continue` is the last reserved word, so that the others keep the
241- seed's numbers; the seed's dumpers intern it first
242- (`src/test/seedcontinue.pas`).
243242 - `Width` follows glibc's `wcwidth` but gives a control 0, and 0 to the
244243 format characters glibc counts as 1 (Egyptian hieroglyph controls,
245244 interlinear annotation), but for the prepended concatenation marks.

Makefile (history) modified +2 -5

@@ -47,10 +47,7 @@
4747 check: raz build/raz-lib.3
4848 test/check.sh
4949
50-# the compiler's units, and the whole compiler, tested against the seed's
51-seed-check: raz | build
52- src/check.sh
53-
50+# the scanner's and the compiler's speed against the seed's
5451 seed-bench: raz | build
5552 src/bench.sh
5653
@@ -184,4 +181,4 @@
184181 site: raz pdf
185182 python3 site/build.py
186183
187-.PHONY: units tests seed-check seed-bench fixpoint check gdb bench kernels stress fmt loc man pdf dist site clean install uninstall
184+.PHONY: units tests seed-bench fixpoint check gdb bench kernels stress fmt loc man pdf dist site clean install uninstall

doc/compiler.md (history) modified +5 -10

@@ -14,7 +14,7 @@
1414 | File | Lines | Code | What |
1515 |---|---|---|---|
1616 | `src/Diag.raz` | 410 | 315 | Messages: positions, source excerpts, colour, counts |
17-| `src/Scan.raz` | 1,127 | 934 | Symbols, literals, comments, positions |
17+| `src/Scan.raz` | 1,125 | 934 | Symbols, literals, comments, positions |
1818 | `src/Sym.raz` | 707 | 566 | Types, objects, scopes, layout |
1919 | `src/Chunk.raz` | 363 | 279 | The compiled program: chunks, fixups, line notes |
2020 | `src/X64.raz` | 1,517 | 1,253 | The instruction encoder, jumps within a procedure, the assembler |
@@ -1769,7 +1769,7 @@
17691769 instruction, or of calls to gen right there.
17701770 - **An instruction:** a routine in `X64.raz` built on `opM` or `opR`,
17711771 and a line in `test/enctest.pas` to check its encoding (the seed's
1772- test; `src/test/X64Dump.raz` is the port's).
1772+ test), and a program in `conform/` or `test/` that uses it.
17731773 - **A machine:** a new `Gen.raz`, answering the same calls, and an
17741774 encoder and assembler for it in place of `X64.raz`.
17751775 - **A statement:** a reserved word in `Scan.raz` (in `Sym` and `words`,
@@ -1783,12 +1783,7 @@
17831783 to suit `src/`); a raz that already exists could do it as well.
17841784 `make fixpoint` has the seed's build compile `src/`, that compile it
17851785 again, and that again, and checks that the last two are the same file.
1786-`make seed-check` tests each unit of `src/` against the seed's. The
1787-seed has no `continue`, the last reserved word of `src/Scan.raz`, so
1788-the Pascal dumpers in `src/test` use `seedcontinue`, which interns the
1789-name right after the seed's reserved words: every name then has the
1790-same number on both sides, and only the end of a file's symbols, one
1791-higher in `src/`, is renumbered (`ScanDump.raz`'s `seedSym`). A file
1792-that uses something the seed doesn't know is left out (`src/check.sh`'s
1793-`newer`). After any change: `make check`, `make bench`,
1786+`make seed-bench` compares the speed of the two. Each unit of `src/`
1787+was once tested against the seed's, while it was ported; that test was
1788+dropped after v0.17.0, as the two had grown apart. After any change: `make check`, `make bench`,
17941789 `make loc`.

src/README.md (history) modified +11 -41

@@ -6,42 +6,19 @@
66 rules: plain code, each module opening with what it is, what it
77 depends on and what it leaves out. The seed is never edited from here.
88
9- make seed-check # each unit against the seed's, on the same files
10- make seed-bench # the scanner's speed against the seed's
9+ make seed-bench # the scanner's and the compiler's speed against the seed's
1110 make fixpoint # the seed builds src, that builds src, that builds it again
12-
13-`Chunk` and `Sym` have no input files to read, so each has a dumper
14-pair, `test/ChunkDump` and `test/SymDump`, that runs one fixed
15-pseudo-random script of calls on its side and prints all it made or
16-answered (`Sym` also ends, as an argument says, in the error of a name
17-declared twice or of too many scopes): the output, the messages and
18-the status must be the same. `Link` and `Elf` are tested by
19-`test/LinkDump`, which makes a program of chunks by a script and writes
20-it as a static, a dynamic and a stripped executable, which must be the
21-same file; `X64` by `test/X64Dump`, every encoder with operands from a
22-script, bytes, fixups and listing, and by `test/AsmDump` on the files
23-`test/genasm.py` makes: a long run of every instruction the assembler
24-knows, and a file for each of its errors.
25-`Gen` and `Item` were tested by `test/GenDump`, a script of calls, valid
26-by construction, that compiles 80 procedures with every kind of
27-expression, statement, call, check, frame and defer, and the entry
28-point, and by `test/ItemDump`, a script of operands and operations with
29-mistakes among them, over 60 scripts (the text its messages point into
30-is `test/ItemDump.txt`): the bytes, fixups, line notes and listing, and
31-the messages, had to be the same as the seed's. They were, until the
32-compiler's code was improved (v0.10.1): `src/` makes better code than
33-the seed, so the dumpers are kept, as a way to read what `Gen` makes,
34-and no longer compared. `src/check.sh` says what is.
3511
36-`Parse` and `Raz`, the last two units, are tested whole: the seed builds
37-`src/Raz.raz` into `build/src/raz.src`, and each compiler, run as
38-`build/cmp/raz` (a program holds the paths it was made from, and the
39-library is found beside the compiler), compiles the library, the
40-examples, the tools, `src/` itself, every test of `test/` and
41-`conform/`, and the 348,025-line program of `test/genbench.py`, with the
42-options each test has. The messages and the status must be the same
43-for every file (the executables no longer are, since v0.10.1): 409 of them, 289 of which are errors.
44-`make seed-bench` gives the speed of both.
12+While it was ported, each unit was tested against the seed's: a pair
13+of dumpers, one over each side's units, read the same files or ran the
14+same pseudo-random script of calls, and had to print the same, with
15+the same messages and status; the compiler built whole had to give
16+every program the messages and status the seed gave. That test was
17+dropped after v0.17.0: the two had grown apart, the compiler making
18+better code since v0.10.1 and following newer reports since, and
19+`make check`, `conform/` and the fixpoint test the compiler as it is.
20+`test/Recover.raz`, the pattern of going on after an error, is run by
21+`make check`.
4522
4623 `make fixpoint` (`fixpoint.sh`) is the proof that the port is whole:
4724 the seed builds `Raz.raz` (stage 1), stage 1 builds it (stage 2), and
@@ -50,13 +27,6 @@
5027 than the seed's). Stage 3 then stands in for `./raz`, and `make check` and
5128 `make bench` run on it. Each stage is built by the same command in the
5229 same place, since a program holds the paths it was made from.
53-
54-`check.sh` builds a dumper for each side, `test/ScanDump.pas` over the
55-seed's units and `test/ScanDump.raz` over these, and has both read the
56-library, the examples, every test of the compiler and a file for each
57-message the scanner makes (`test/genlex.py`) and for hundreds of reals
58-that are hard to read exactly (`test/genreals.py`): the output, the
59-messages and the status must be the same.
6030
6131 ## What the port found
6232

src/Scan.raz (history) modified +5 -7

@@ -22,14 +22,12 @@
2222 sBecomes, sColon, sSemicolon, sComma, sPeriod, sUpto, sEllipsis,
2323 sLparen, sRparen, sLbrak, sRbrak, sLbrace, sRbrace, sArrow, sAmp, sTilde, sBar,
2424 sBlank,
25- (* the reserved words, in the order of words below: alphabetical
26- but for continue, which came last (report 2026-10.31), so that
27- the others keep the numbers the seed gives them *)
28- sAnd, sBegin, sBreak, sBy, sCode, sConst, sDefer, sDiv, sDo, sElse,
25+ (* the reserved words, in the order of words below *)
26+ sAnd, sBegin, sBreak, sBy, sCode, sConst, sContinue, sDefer, sDiv, sDo, sElse,
2927 sElsif, sEnd, sExtern, sFor, sForward, sIf, sImport, sIn, sLink,
3028 sMatch, sMod, sModule, sNot, sOf, sOr, sPacked, sProc, sRecord,
3129 sRepeat, sReturn, sSet, sShl, sShr, sThen, sTo, sTry, sType, sUntil, sVar,
32- sVariant, sVolatile, sWhile, sXor, sContinue,
30+ sVariant, sVolatile, sWhile, sXor,
3331 sEof);
3432
3533 (* Where the scanner is. Importing a module compiles it in the middle
@@ -53,12 +51,12 @@
5351 NumWords = 44;
5452 NumOps = 28;
5553 words: [NumWords][]U8 = [
56- "and", "begin", "break", "by", "code", "const", "defer", "div", "do",
54+ "and", "begin", "break", "by", "code", "const", "continue", "defer", "div", "do",
5755 "else", "elsif", "end", "extern", "for", "forward", "if", "import",
5856 "in", "link", "match", "mod", "module", "not", "of", "or", "packed",
5957 "proc", "record", "repeat", "return", "set", "shl", "shr", "then",
6058 "to", "try", "type", "until", "var", "variant", "VOLATILE", "while",
61- "xor", "continue"];
59+ "xor"];
6260 (* sPlus to sBlank *)
6361 ops: [NumOps][]U8 = [
6462 "+", "-", "*", "/", "=", "#", "<", "<=", ">", ">=",

src/bench.sh (history) modified +2 -1

@@ -1,9 +1,10 @@
11 #!/bin/sh
22 # The scanner's speed against the seed's, on the compiler's own
33 # benchmark program: the best of seven runs of each. Run from the
4-# repository root, after src/check.sh has built the tests.
4+# repository root, after make raz.
55 set -e
66 b=build/src
7+mkdir -p $b
78 python3 test/genbench.py 12000 >$b/Bench.raz
89 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/scanbench.seed src/test/ScanBench.pas >/dev/null
910 ./raz -Werror -I src -o $b/scanbench.src src/test/ScanBench.raz

src/check.sh deleted +0 -190

@@ -1,190 +0,0 @@
1-#!/bin/sh
2-# Tests src/'s units against the seed's: each dumper reads the same
3-# files and must give the same standard output, standard error and
4-# status. Run from the repository root, after `make raz`; the seed's
5-# side is built by fpc from seed/.
6-set -e
7-b=build/src
8-# The seed predates raw strings and match on a string (report
9-# 2026-10.25): the files that use them are the compiler's alone, and
10-# so are those whose message says what match takes. It predates, too,
11-# an INT widened in an expression and the rest (report 2026-10.26),
12-# the messages for an I64 that goes to an INT, and a help that
13-# converts the narrower of two integers; and views, v.(T),
14-# whose tests are conform/*/View*.raz, and which Math, examples/Elf.raz
15-# and, through Math, test/bench/NBody.raz use; and returning a slice of
16-# the frame as an error (report 2026-10.27); an array constant typed
17-# []T (report 2026-10.29); [] as the empty slice, seen through a view
18-# (report 2026-10.30); and U8, I8 and I16 widening to INT, continue,
19-# and enumerations' names with their types (report 2026-10.31).
20-newer="conform/run/RawStrings.raz conform/err/ScanRawOpen.raz conform/err/ScanRawIndent.raz
21- conform/run/MatchStr.raz conform/err/MatchStrTwice.raz conform/err/MatchStrNoElse.raz
22- conform/err/MatchStrVar.raz conform/err/MatchReal.raz conform/err/AtMatch.raz
23- examples/Sh.raz examples/Settings.raz
24- conform/run/IntWiden.raz conform/err/IntIncNarrow.raz conform/err/IntNarrow.raz conform/err/IntNarrowSum.raz
25- conform/err/IntResultsNarrow.raz conform/err/GenIntTypes.raz
26- lib/Math.raz examples/Elf.raz test/bench/NBody.raz
27- conform/err/FrameSlice.raz
28- conform/run/ArrayConstLen.raz conform/err/ArrayConstLenEmpty.raz conform/err/ArrayConstLenLiteral.raz
29- conform/run/EmptySlice.raz
30- conform/run/SmallWiden.raz conform/err/SmallWidenMade.raz conform/err/SmallWidenNeg.raz
31- conform/err/SmallWidenI64.raz conform/err/SmallWidenMadeOp.raz
32- conform/run/Continue.raz conform/err/ContinueOutside.raz conform/err/ContinueDefer.raz
33- conform/err/ContinueName.raz
34- conform/run/EnumNames.raz conform/err/EnumShared.raz conform/err/EnumNoName.raz
35- conform/err/EnumArmType.raz conform/err/EnumSharedImported.raz conform/err/EnumTwiceOther.raz
36- tools/Widths.raz lib/Width.raz"
37-newer() {
38- case $1 in conform/*/View*.raz) return 0 ;; esac
39- for g in $newer; do [ $g = $1 ] && return 0; done
40- return 1
41-}
42-mkdir -p $b
43-fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/scandump.seed src/test/ScanDump.pas >/dev/null
44-./raz -Werror -I src -o $b/scandump.src src/test/ScanDump.raz
45-python3 src/test/genreals.py > $b/reals.raz
46-# one small file for each message the scanner makes, and the places
47-# diag shows them in: a tab, a long line, characters before the place
48-mkdir -p $b/lex
49-python3 src/test/genlex.py $b/lex
50-n=0; bad=0
51-for f in $b/lex/*.raz lib/*.raz examples/*.raz tools/*.raz src/*.raz src/test/*.raz test/run/*.raz test/err/*.raz \
52- conform/*/*.raz $b/reals.raz; do
53- [ -f "$f" ] || continue
54- newer $f && continue
55- s1=0; s2=0
56- $b/scandump.seed $f >$b/seed.out 2>$b/seed.err || s1=$?
57- $b/scandump.src $f >$b/src.out 2>$b/src.err || s2=$?
58- n=$((n + 1))
59- if [ $s1 != $s2 ] || ! cmp -s $b/seed.out $b/src.out || ! cmp -s $b/seed.err $b/src.err; then
60- echo "differs: $f (status $s1 and $s2)"; bad=$((bad + 1))
61- fi
62-done
63-echo "$n files, $bad differ"
64-test $bad = 0
65-
66-# Jump: a parser's way of going on after an error
67-./raz -Werror -I src -o $b/recover src/test/Recover.raz
68-printf 'a bad b bad bad c\nd bad\n' >$b/rec.raz
69-r=$($b/recover $b/rec.raz 2>/dev/null) || test $? = 1
70-test "$r" = "8 names, 4 failed, 4 errors" && echo "recover ok"
71-
72-# Chunk and Sym: a fixed pseudo-random script each, run by both sides,
73-# which print all they have made or answered; Sym also ends, as the
74-# argument says, in an error, whose message and status must agree
75-for u in Chunk Sym; do
76- l=$(echo $u | tr A-Z a-z)
77- fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/${l}dump.seed src/test/${u}Dump.pas >/dev/null
78- ./raz -Werror -I src -o $b/${l}dump.src src/test/${u}Dump.raz
79-done
80-for a in "" dup deep; do
81- for s in seed src; do
82- t=0; $b/chunkdump.$s >$b/chunk.$s 2>/dev/null || t=$?
83- t2=0; $b/symdump.$s $a >$b/sym.$s.out 2>$b/sym.$s.err || t2=$?
84- echo "$t $t2" >$b/status.$s
85- done
86- cmp $b/status.seed $b/status.src
87- cmp $b/chunk.seed $b/chunk.src
88- cmp $b/sym.seed.out $b/sym.src.out
89- cmp $b/sym.seed.err $b/sym.src.err
90-done
91-echo "chunk and sym ok"
92-
93-# Link and Elf: a program of chunks made by a script, linked and written
94-# as a static, a dynamic and a stripped executable, which must be the
95-# same file from both sides
96-fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/linkdump.seed src/test/LinkDump.pas >/dev/null
97-./raz -Werror -I src -o $b/linkdump.src src/test/LinkDump.raz
98-for m in 0 1 2; do
99- $b/linkdump.seed $m $b/link.seed
100- $b/linkdump.src $m $b/link.src
101- cmp $b/link.seed $b/link.src
102-done
103-echo "link and elf ok"
104-
105-# X64: every encoder, then the assembler on a long run of instructions
106-# of every kind and a file for each error it makes; the bytes and the
107-# listing, or the message and status, must be the same
108-fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/x64dump.seed src/test/X64Dump.pas >/dev/null
109-./raz -Werror -I src -o $b/x64dump.src src/test/X64Dump.raz
110-$b/x64dump.seed >$b/x64.seed
111-$b/x64dump.src >$b/x64.src
112-cmp $b/x64.seed $b/x64.src
113-fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/asmdump.seed src/test/AsmDump.pas >/dev/null
114-./raz -Werror -I src -o $b/asmdump.src src/test/AsmDump.raz
115-mkdir -p $b/asm
116-python3 src/test/genasm.py $b/asm
117-n=0; bad=0
118-for f in $b/asm/*.raz; do
119- s1=0; s2=0
120- $b/asmdump.seed $f >$b/seed.out 2>$b/seed.err || s1=$?
121- $b/asmdump.src $f >$b/src.out 2>$b/src.err || s2=$?
122- n=$((n + 1))
123- if [ $s1 != $s2 ] || ! cmp -s $b/seed.out $b/src.out || ! cmp -s $b/seed.err $b/src.err; then
124- echo "differs: $f (status $s1 and $s2)"; bad=$((bad + 1))
125- fi
126-done
127-echo "x64: $n assembler files, $bad differ"
128-test $bad = 0
129-
130-# Gen and Item were tested here against the seed's while they were ported,
131-# by the code they made: the same bytes, listings and line notes. Since the
132-# compiler's own code was improved (v0.10.1) that code is no longer the
133-# seed's, so they are tested by what the seed can still check, the
134-# messages and statuses of Parse and Raz below, and by the fixpoint and
135-# the tests of `make check`, on the compiler they make.
136-
137-# Parse and Raz: the compiler this makes, built by the seed, compiles
138-# what the seed compiles, with the same messages and status (the files
139-# are no longer the same, as it makes better code): every example, test and tool, and the library, with each
140-# one's own options. Both sides run as build/cmp/raz, since a program
141-# holds the paths it was made from and the library is found beside the
142-# compiler.
143-printf 'module Version;\nconst Text* = "%s";\nend Version.\n' "$(tr -d "'" < build/version.inc)" >$b/Version.raz
144-./raz -Werror -I src -I $b -o $b/raz.src src/Raz.raz
145-c=build/cmp
146-mkdir -p $c
147-ln -sfn ../../lib $c/lib
148-# and the big program that times the compiler, 348,025 lines
149-mkdir -p $c/bench
150-python3 test/genbench.py 12000 >$c/bench/Bench.raz
151-files=
152-for f in $c/bench/Bench.raz lib/*.raz examples/*.raz tools/*.raz src/*.raz test/run/*.raz test/libc/*.raz test/bench/*.raz \
153- conform/run/*.raz test/err/*.raz conform/err/*.raz; do
154- newer $f || files="$files $f"
155-done
156-for side in seed src; do
157- rm -rf $c/$side
158- mkdir -p $c/$side
159- if [ $side = seed ]; then cp build/seed/raz $c/raz; else cp $b/raz.src $c/raz; fi
160- for f in $files; do
161- dir=$(dirname $f); name=$(basename $f .raz); x=$(echo $dir | tr / _).$name
162- flags=
163- case $dir in
164- examples|tools|lib|src) flags=-Werror ;;
165- esac
166- [ -f $dir/$name.args ] && [ $dir = test/err ] && flags="$flags $(cat $dir/$name.args)"
167- case $dir in
168- lib) opts= ;;
169- src|tools) opts="-I src -I build/src" ;;
170- test/err) opts="-I test/err/mods -I test/run/mods" ;;
171- *) opts="-I $dir/mods" ;;
172- esac
173- s=0
174- $c/raz $flags $opts -o $c/$side/$x $f >$c/$side/$x.out 2>$c/$side/$x.err || s=$?
175- echo $s >$c/$side/$x.status
176- done
177-done
178-n=0; bad=0
179-for f in $files; do
180- x=$(dirname $f | tr / _).$(basename $f .raz)
181- n=$((n + 1))
182- for e in .out .err .status; do
183- [ -f $c/seed/$x$e ] || [ -f $c/src/$x$e ] || continue
184- if ! cmp -s $c/seed/$x$e $c/src/$x$e; then
185- echo "differs: $f ($x$e)"; bad=$((bad + 1)); break
186- fi
187- done
188-done
189-echo "raz: $n files, $bad differ"
190-test $bad = 0

src/test/AsmDump.pas deleted +0 -46

@@ -1,46 +0,0 @@
1-{ Assembles the instructions in the file of the argument, as the body of
2- a code procedure that ends in end, and prints the bytes and the
3- listing: the seed's side of a test of the assembler in src/X64.raz,
4- whose AsmDump.raz does the same and prints the same. Constants are
5- numbers, with a minus sign, and sums of them. }
6-program asmdump;
7-{$mode objfpc}{$H-}
8-uses diag, scan, seedcontinue, chunk, x64;
9-var i: longint; path: string;
10-
11-function ConstVal(whole: boolean): int64;
12-var neg: boolean; v: int64;
13-begin
14- neg := tok = sMinus;
15- if neg then Next;
16- if tok <> sInt then Mark('expected a number');
17- v := ival;
18- Next;
19- if neg then v := -v;
20- while whole and (tok in [sPlus, sMinus]) do begin
21- neg := tok = sMinus;
22- Next;
23- if tok <> sInt then Mark('expected a number');
24- if neg then v := v - ival else v := v + ival;
25- Next;
26- end;
27- ConstVal := v;
28-end;
29-
30-begin
31- if Open(ParamStr(1)) <> '' then Fatal('no file');
32- path := 'lib/Rt.raz';
33- curFile := Intern(@path[1], length(path));
34- listing := true;
35- NewChunk(secText, 0, 0);
36- BeginChunk(0);
37- NoteLine(1, 1);
38- Next;
39- Assemble(@ConstVal);
40- EndChunk(0);
41- chunks^[0].live := true;
42- for i := 0 to pc - 1 do write(HexStr(code^[i], 2));
43- writeln;
44- List(0);
45- Finish;
46-end.

src/test/AsmDump.raz deleted +0 -55

@@ -1,55 +0,0 @@
1-(* Assembles the instructions in the file of the argument, as the body of
2- a code procedure that ends in end, and prints the bytes and the
3- listing: src/X64.raz's assembler's side of a test against the seed's,
4- AsmDump.pas, which prints the same. Constants are numbers, with a
5- minus sign, and sums of them. *)
6-module AsmDump;
7-import Out, Files, Diag, Scan, Chunk, X64;
8-
9-proc number(neg: BOOL): (I64, ERROR);
10-var v: I64;
11-begin
12- if Scan.tok # Scan.sInt then return 0, Scan.mark("expected a number"); end;
13- v := Scan.ival;
14- Scan.next;
15- if neg then v := -v; end;
16- return v, nil;
17-end;
18-
19-proc constant(whole: BOOL): (I64, ERROR);
20-var neg: BOOL; v, w: I64;
21-begin
22- neg := Scan.tok = Scan.sMinus;
23- if neg then Scan.next; end;
24- v := try number(neg);
25- while whole and ((Scan.tok = Scan.sPlus) or (Scan.tok = Scan.sMinus)) do
26- neg := Scan.tok = Scan.sMinus;
27- Scan.next;
28- w := try number(neg);
29- v := v + w;
30- end;
31- return v, nil;
32-end;
33-
34-proc main*;
35-var i: INT; path: []U8; err: ERROR;
36-begin
37- if LEN(Scan.open(Files.arg(1))) # 0 then Diag.fatal("no file"); end;
38- path := "lib/Rt.raz";
39- Chunk.setCurFile(Scan.intern(ADR(path[0]), LEN(path)));
40- X64.setListing(true);
41- _ := Chunk.newChunk(Chunk.secText, 0, 0);
42- Chunk.beginChunk(0);
43- Chunk.noteLine(1, 1);
44- Scan.next;
45- err := X64.assemble(constant);
46- if err # nil then Diag.finish; end;
47- Chunk.endChunk(0);
48- Chunk.setLive(0);
49- for i := 0 to Chunk.pc - 1 do Out.hex(U64(Chunk.text[i]), 2); end;
50- Out.ln;
51- X64.list(0);
52- Diag.finish;
53-end;
54-
55-end AsmDump.

src/test/ChunkDump.pas deleted +0 -89

@@ -1,89 +0,0 @@
1-{ Makes a program of chunks by a fixed pseudo-random script and prints
2- all of it: the seed's side of a test of src/Chunk.raz, whose
3- ChunkDump.raz does the same and prints the same. }
4-program chunkdump;
5-{$mode objfpc}{$H-}
6-uses diag, scan, seedcontinue, chunk;
7-var
8- seed: int64;
9- names: array[0..7] of longint;
10- i, k, n, op, c, sum, open, x, y, z: longint;
11- b: array[0..63] of byte;
12-
13-function Rnd(n: longint): longint;
14-begin
15- seed := (seed * 1103515245 + 12345) and $7FFFFFFF;
16- Rnd := (seed shr 8) mod n;
17-end;
18-
19-begin
20- seed := 7;
21- for i := 0 to 7 do begin b[0] := 97 + i; names[i] := Intern(@b[0], 1) end;
22- open := -1;
23- sum := 0;
24- for k := 1 to 30000 do begin
25- op := Rnd(16);
26- case op of
27- 0..3: Put1(Rnd(256));
28- 4: begin x := Rnd(1 shl 30); y := Rnd(1 shl 30); Put4(x - y) end;
29- 5: begin x := Rnd(1 shl 30); y := Rnd(1 shl 30); Put8(int64(x) * 4096 - y) end;
30- 6: begin
31- if open >= 0 then EndChunk(open);
32- x := Rnd(5); y := Rnd(9);
33- open := NewChunk(secText, x - 1, y - 1);
34- BeginChunk(open);
35- end;
36- 7: begin x := Rnd(8); curFile := names[x]; x := Rnd(300); y := Rnd(80); NoteLine(x, y) end;
37- 8: if numChunks > 0 then begin x := Rnd(numChunks); y := Rnd(100); AddFixup(pc, x, y - 50) end;
38- 9: if (open >= 0) and (pc - chunks^[open].start > 8) then begin x := Rnd(6); TakeBack(x) end;
39- 10: begin
40- x := Rnd(5); y := Rnd(9);
41- c := NewChunk(secRodata, x - 1, y - 1);
42- n := Rnd(64);
43- for i := 0 to n - 1 do b[i] := Rnd(256);
44- x := Rnd(4);
45- SetData(c, @b[0], n, 1 shl x);
46- n := Rnd(4);
47- for i := 1 to n do begin x := Rnd(8); y := Rnd(numChunks); z := Rnd(10); AddDataFixup(c, x * 8, y, z) end;
48- end;
49- 11: begin
50- x := Rnd(5); y := Rnd(9);
51- c := NewChunk(secBss, x - 1, y - 1);
52- x := Rnd(100); y := Rnd(4);
53- SetBss(c, x, 1 shl y);
54- end;
55- 12: begin x := Rnd(8); c := ExternChunk(names[x]) end;
56- 13: if numChunks > 0 then begin
57- x := Rnd(numChunks); y := Rnd(8); z := Rnd(200); n := Rnd(5);
58- NoteVar(x, names[y], z - 100, n);
59- end;
60- 14: if pc >= 8 then begin
61- x := Rnd(1 shl 30); y := Rnd(1 shl 30);
62- Put4At(pc - 8, x - y);
63- sum := (sum + Get4At(pc - 8)) and $FFFFFF;
64- end;
65- 15: if numChunks > 0 then begin
66- x := Rnd(numChunks); chunks^[x].live := true;
67- x := Rnd(numChunks); y := Rnd(1 shl 30); chunks^[x].adr := y;
68- end;
69- end;
70- end;
71- if open >= 0 then EndChunk(open);
72- writeln('sum ', sum, ' pc ', pc, ' rolen ', rolen);
73- for i := 0 to numChunks - 1 do
74- with chunks^[i] do
75- writeln('C ', i, ' ', ord(sec), ' ', start, ' ', size, ' ', align, ' ', firstFix, ' ', numFix, ' ',
76- module, ' ', name, ' ', adr, ' ', ord(live), ' ', ord(ext), ' ', ChunkName(i));
77- for i := 0 to numFixups - 1 do
78- writeln('F ', fixups^[i].at, ' ', fixups^[i].chunk, ' ', fixups^[i].addend);
79- for i := 0 to numDataFixups - 1 do
80- writeln('D ', dataFixups^[i].at, ' ', dataFixups^[i].chunk, ' ', dataFixups^[i].addend);
81- for i := 0 to numLines - 1 do
82- writeln('L ', lines^[i].at, ' ', lines^[i].chunk, ' ', lines^[i].path, ' ', lines^[i].line, ' ', lines^[i].col);
83- for i := 0 to numVarNotes - 1 do
84- writeln('V ', varNotes[i].chunk, ' ', varNotes[i].name, ' ', varNotes[i].off, ' ', varNotes[i].kind);
85- for i := 0 to pc - 1 do write(HexStr(code^[i], 2));
86- writeln;
87- for i := 0 to rolen - 1 do write(HexStr(rodata^[i], 2));
88- writeln;
89-end.

src/test/ChunkDump.raz deleted +0 -118

@@ -1,118 +0,0 @@
1-(* Makes a program of chunks by a fixed pseudo-random script and prints
2- all of it: src/Chunk.raz's side of a test against the seed's,
3- ChunkDump.pas, which prints the same. *)
4-module ChunkDump;
5-import Out, Fmt, Scan, Chunk;
6-
7-var seed: I64;
8-
9-proc rnd(n: INT): INT;
10-begin
11- seed := (seed * 1103515245 + 12345) & 7FFFFFFFH;
12- return INT((seed shr 8) mod I64(n));
13-end;
14-
15-(* a flag, as the number the seed's side prints for it *)
16-proc bit(f: BOOL): INT;
17-begin
18- if f then return 1; end;
19- return 0;
20-end;
21-
22-proc main*;
23-var
24- names: [8]INT; b: [64]U8;
25- i, k, n, op, c, sum, open, x, y, z: INT;
26-begin
27- seed := 7;
28- for i := 0 to 7 do b[0] := U8(97 + i); names[i] := Scan.intern(ADR(b[0]), 1); end;
29- open := -1;
30- sum := 0;
31- for k := 1 to 30000 do
32- op := rnd(16);
33- match op of
34- | 0..3: Chunk.put1(rnd(256));
35- | 4: x := rnd(1 shl 30); y := rnd(1 shl 30); Chunk.put4(x - y);
36- | 5: x := rnd(1 shl 30); y := rnd(1 shl 30); Chunk.put8(I64(x) * 4096 - I64(y));
37- | 6:
38- if open >= 0 then Chunk.endChunk(open); end;
39- x := rnd(5); y := rnd(9);
40- open := Chunk.newChunk(Chunk.secText, x - 1, y - 1);
41- Chunk.beginChunk(open);
42- | 7:
43- x := rnd(8); Chunk.setCurFile(names[x]);
44- x := rnd(300); y := rnd(80); Chunk.noteLine(x, y);
45- | 8:
46- if Chunk.numChunks > 0 then
47- x := rnd(Chunk.numChunks); y := rnd(100); Chunk.addFixup(Chunk.pc, x, y - 50);
48- end;
49- | 9:
50- if (open >= 0) and (Chunk.pc - Chunk.chunks[open].start > 8) then
51- x := rnd(6); Chunk.takeBack(x);
52- end;
53- | 10:
54- x := rnd(5); y := rnd(9);
55- c := Chunk.newChunk(Chunk.secRodata, x - 1, y - 1);
56- n := rnd(64);
57- for i := 0 to n - 1 do b[i] := U8(rnd(256)); end;
58- x := rnd(4);
59- Chunk.setData(c, ADR(b[0]), n, 1 shl x);
60- n := rnd(4);
61- for i := 1 to n do
62- x := rnd(8); y := rnd(Chunk.numChunks); z := rnd(10);
63- Chunk.addDataFixup(c, x * 8, y, z);
64- end;
65- | 11:
66- x := rnd(5); y := rnd(9);
67- c := Chunk.newChunk(Chunk.secBss, x - 1, y - 1);
68- x := rnd(100); y := rnd(4);
69- Chunk.setBss(c, x, 1 shl y);
70- | 12: x := rnd(8); c := Chunk.externChunk(names[x]);
71- | 13:
72- if Chunk.numChunks > 0 then
73- x := rnd(Chunk.numChunks); y := rnd(8); z := rnd(200); n := rnd(5);
74- Chunk.noteVar(x, names[y], z - 100, n);
75- end;
76- | 14:
77- if Chunk.pc >= 8 then
78- x := rnd(1 shl 30); y := rnd(1 shl 30);
79- Chunk.put4At(Chunk.pc - 8, x - y);
80- sum := (sum + Chunk.get4At(Chunk.pc - 8)) & 0FFFFFFH;
81- end;
82- | else:
83- if Chunk.numChunks > 0 then
84- x := rnd(Chunk.numChunks); Chunk.setLive(x);
85- x := rnd(Chunk.numChunks); y := rnd(1 shl 30); Chunk.setAdr(x, y);
86- end;
87- end;
88- end;
89- if open >= 0 then Chunk.endChunk(open); end;
90- Fmt.print("sum {} pc {} rolen {}\n", [Fmt.int(sum), Fmt.int(Chunk.pc), Fmt.int(Chunk.rolen)]);
91- for i := 0 to Chunk.numChunks - 1 do
92- Fmt.print("C {} {} {} {} {} {} {} {} {} {} {} {} {}\n", [Fmt.int(i), Fmt.int(INT(Chunk.chunks[i].sec)),
93- Fmt.int(Chunk.chunks[i].start), Fmt.int(Chunk.chunks[i].size), Fmt.int(Chunk.chunks[i].align),
94- Fmt.int(Chunk.chunks[i].firstFix), Fmt.int(Chunk.chunks[i].numFix), Fmt.int(Chunk.chunks[i].home),
95- Fmt.int(Chunk.chunks[i].name), Fmt.int(Chunk.chunks[i].adr),
96- Fmt.int(bit(Chunk.chunks[i].live)), Fmt.int(bit(Chunk.chunks[i].ext)), Fmt.str(Chunk.chunkName(i))]);
97- end;
98- for i := 0 to Chunk.numFixups - 1 do
99- Fmt.print("F {} {} {}\n", [Fmt.int(Chunk.fixups[i].at), Fmt.int(Chunk.fixups[i].chunk), Fmt.int(Chunk.fixups[i].addend)]);
100- end;
101- for i := 0 to Chunk.numDataFixups - 1 do
102- Fmt.print("D {} {} {}\n", [Fmt.int(Chunk.dataFixups[i].at), Fmt.int(Chunk.dataFixups[i].chunk), Fmt.int(Chunk.dataFixups[i].addend)]);
103- end;
104- for i := 0 to Chunk.numLines - 1 do
105- Fmt.print("L {} {} {} {} {}\n", [Fmt.int(Chunk.lines[i].at), Fmt.int(Chunk.lines[i].chunk),
106- Fmt.int(Chunk.lines[i].path), Fmt.int(Chunk.lines[i].line), Fmt.int(Chunk.lines[i].col)]);
107- end;
108- for i := 0 to Chunk.numVarNotes - 1 do
109- Fmt.print("V {} {} {} {}\n", [Fmt.int(Chunk.varNotes[i].chunk), Fmt.int(Chunk.varNotes[i].name),
110- Fmt.int(Chunk.varNotes[i].off), Fmt.int(Chunk.varNotes[i].kind)]);
111- end;
112- for i := 0 to Chunk.pc - 1 do Out.hex(U64(Chunk.text[i]), 2); end;
113- Out.ln;
114- for i := 0 to Chunk.rolen - 1 do Out.hex(U64(Chunk.rodata[i]), 2); end;
115- Out.ln;
116-end;
117-
118-end ChunkDump.

src/test/GenDump.pas deleted +0 -708

@@ -1,708 +0,0 @@
1-{ Compiles procedures made by a fixed pseudo-random script of calls to
2- Gen, valid by construction, then prints the bytes, the fixups and the
3- listing (raz -S) of what it made: the seed's side of a test of
4- src/Gen.raz, whose GenDump.raz makes and prints the same. With an
5- argument, the entry point is the dynamic one. }
6-program gendump;
7-{$mode objfpc}{$H-}
8-uses diag, scan, seedcontinue, sym, chunk, x64, gen;
9-
10-const
11- FirstProc = 3;
12- NumProcs = 80;
13- FirstGlob = FirstProc + NumProcs;
14- NumGlobs = 4;
15- Arith: array[0..9] of TSym = (sPlus, sMinus, sTimes, sDiv, sMod, sAmp, sBar, sXor, sShl, sShr);
16- Cmps: array[0..5] of TSym = (sEql, sNeq, sLss, sLeq, sGtr, sGeq);
17- RealOps: array[0..3] of TSym = (sPlus, sMinus, sTimes, sSlash);
18-
19-var
20- seed: int64;
21- slots: array[0..5] of int64;
22- regs: array[0..4] of longint;
23- numRegs: longint;
24- xregs: array[0..3] of longint;
25- numX: longint;
26- tuple2, tuple3, record3, sliceT: PType;
27- results: array[0..8] of PType;
28- curRes: longint;
29-
30-function Rnd(n: longint): longint;
31-begin
32- seed := (seed * 1103515245 + 12345) and $7FFFFFFF;
33- Rnd := (seed shr 8) mod n;
34-end;
35-
36-function Pos: TPos;
37-var p: TPos;
38-begin
39- p.f := 0; p.a := Rnd(400); p.b := p.a + 1;
40- Pos := p;
41-end;
42-
43-function Size: longint;
44-begin
45- Size := 1 shl Rnd(4);
46-end;
47-
48-function Slot: int64;
49-begin
50- Slot := slots[Rnd(6)];
51-end;
52-
53-function Bit(f: boolean): longint;
54-begin
55- if f then Bit := 1 else Bit := 0;
56-end;
57-
58-function Flag: boolean;
59-begin
60- Flag := Rnd(2) = 0;
61-end;
62-
63-function ConstVal: int64;
64-var x: longint; r: int64;
65-begin
66- x := Rnd(1 shl 30);
67- case Rnd(7) of
68- 0: r := x mod 10;
69- 1: r := -(x mod 100);
70- 2: r := int64(1) shl (x mod 20);
71- 3: r := x;
72- 4: r := int64(x) * 4096 * 4096 * 9 - 7;
73- 5: r := -int64(x) * 8;
74- else r := x mod 1000 - 500;
75- end;
76- ConstVal := r;
77-end;
78-
79-function NewObjs(t: PType; n: longint): PObj;
80-var first, o, last: PObj; i: longint;
81-begin
82- first := nil; last := nil;
83- for i := 0 to n - 1 do begin
84- o := NewObj(oVar, 0, t);
85- o^.val := 8 * i;
86- if last = nil then first := o else last^.next := o;
87- last := o;
88- end;
89- NewObjs := first;
90-end;
91-
92-procedure MakeTypes;
93-begin
94- tuple2 := NewType(fRecord, 16, 8);
95- tuple2^.tuple := true; tuple2^.len := 2; tuple2^.fields := NewObjs(tInt, 2);
96- tuple3 := NewType(fRecord, 24, 8);
97- tuple3^.tuple := true; tuple3^.len := 3; tuple3^.fields := NewObjs(tInt, 3);
98- record3 := NewType(fRecord, 24, 8);
99- record3^.fields := NewObjs(tReal, 3);
100- sliceT := NewType(fSlice, 16, 8);
101- sliceT^.base := tU8;
102- results[0] := nil;
103- results[1] := tInt;
104- results[2] := tReal;
105- results[3] := sliceT;
106- results[4] := tuple2;
107- results[5] := tuple3;
108- results[6] := tF32;
109- results[7] := tI16;
110- results[8] := record3;
111-end;
112-
113-function MemAdr: TAdr;
114-var a: TAdr; c: longint;
115-begin
116- c := Rnd(3);
117- if c = 0 then begin
118- a.base := bFrame; a.chunk := 0; a.hi := 0; a.off := Slot; if Flag then a.off := a.off + 8;
119- end else if c = 1 then begin
120- a.base := bGlobal; a.chunk := FirstGlob + Rnd(NumGlobs); a.hi := 0; a.off := 8 * Rnd(3);
121- end else begin
122- a.base := bSlot; a.chunk := Slot; a.hi := 0; a.off := 8 * Rnd(3);
123- end;
124- MemAdr := a;
125-end;
126-
127-function PushableAdr: TAdr;
128-var a: TAdr;
129-begin
130- a.chunk := 0; a.hi := 0;
131- if Flag then begin
132- a.base := bFrame; a.off := Slot; if Flag then a.off := a.off + 8;
133- end else begin
134- a.base := bGlobal; a.chunk := FirstGlob + Rnd(NumGlobs); a.off := 8 * Rnd(3);
135- end;
136- PushableAdr := a;
137-end;
138-
139-function RegAdr(r: longint): TAdr;
140-var a: TAdr;
141-begin
142- a.base := bReg; a.chunk := r; a.hi := 0; a.off := 0;
143- RegAdr := a;
144-end;
145-
146-function StackAdr: TAdr;
147-var a: TAdr;
148-begin
149- a.base := bStack; a.chunk := 0; a.hi := 0; a.off := 8 * Rnd(3);
150- StackAdr := a;
151-end;
152-
153-procedure PushIntVar;
154-var a: TAdr; sz, c: longint;
155-begin
156- sz := Size;
157- c := Rnd(5);
158- if (c = 0) and (numRegs > 0) then begin
159- if Flag then inPlace := regs[Rnd(numRegs)];
160- PushVar(RegAdr(regs[Rnd(numRegs)]), 8, false, kWord);
161- end else if c = 1 then begin
162- PushAdr(PushableAdr);
163- a := StackAdr;
164- PushVar(a, sz, Flag, kWord);
165- end else begin
166- a := MemAdr;
167- PushVar(a, sz, Flag, kWord);
168- end;
169-end;
170-
171-procedure IntExpr(b: longint); forward;
172-procedure RealExpr(k: TKind; b: longint); forward;
173-procedure CallExpr(want, b: longint); forward;
174-
175-function RealKind: TKind;
176-begin
177- if Flag then RealKind := kF64 else RealKind := kF32;
178-end;
179-
180-procedure IntExpr(b: longint);
181-var c, sz, n: longint; sg, f: boolean; k: TKind; sy: TSym; a: TAdr;
182-begin
183- if b > 0 then c := Rnd(14) else c := Rnd(3);
184- case c of
185- 0: PushConst(kWord, ConstVal);
186- 1: PushIntVar;
187- 2: PushIntVar;
188- 3, 4, 5: begin
189- IntExpr(b - 1); IntExpr(b - 1);
190- sy := Arith[Rnd(10)]; sz := Size; sg := Flag;
191- Op(sy, kWord, sz, sg);
192- end;
193- 6:
194- if Flag then begin
195- IntExpr(b - 1); IntExpr(b - 1);
196- sy := Cmps[Rnd(6)]; sg := Flag;
197- Compare(sy, kWord, sg);
198- end else begin
199- k := RealKind;
200- RealExpr(k, b - 1); RealExpr(k, b - 1);
201- sy := Cmps[Rnd(6)];
202- Compare(sy, k, false);
203- end;
204- 7: begin
205- IntExpr(b - 1);
206- n := Rnd(4); sz := Size; sg := Flag;
207- if n = 0 then Neg(kWord, sz, sg)
208- else if n = 1 then Complement(sz, sg)
209- else if n = 2 then NotBool
210- else Narrow(sz, sg);
211- end;
212- 8: begin
213- IntExpr(b - 1);
214- a := PushableAdr;
215- sz := Size; sg := Flag;
216- n := 10 + Rnd(100);
217- CheckIndex(n, Pos);
218- IndexArray(a, sz);
219- a := StackAdr; a.off := 0;
220- PushVar(a, sz, sg, kWord);
221- end;
222- 9: begin
223- n := Rnd(3);
224- sz := Size; sg := Flag;
225- if n = 0 then begin
226- a := MemAdr;
227- if a.base = bGlobal then a.base := bFrame;
228- IntExpr(b - 1);
229- f := Flag;
230- IndexSlice(a, sz, f, Pos);
231- end else if n = 1 then begin
232- PushAdr(PushableAdr);
233- IntExpr(b - 1);
234- a := StackAdr; a.off := 0;
235- f := Flag;
236- IndexSlice(a, sz, f, Pos);
237- end else begin
238- a.base := bReg; a.chunk := R13; a.hi := R14; a.off := 0;
239- IntExpr(b - 1);
240- f := Flag;
241- IndexSlice(a, sz, f, Pos);
242- end;
243- a := StackAdr; a.off := 0;
244- PushVar(a, sz, sg, kWord);
245- end;
246- 10: begin
247- k := RealKind;
248- RealExpr(k, b - 1);
249- RealToInt(k);
250- end;
251- 11: CallExpr(1, b - 1);
252- 12: begin
253- IntExpr(b - 1);
254- PushConst(kWord, Rnd(100) - 50);
255- Op(sPlus, kWord, 8, false);
256- end;
257- else begin
258- IntExpr(b - 1);
259- PushConst(kWord, ConstVal);
260- sy := Arith[Rnd(10)]; sz := Size; sg := Flag;
261- Op(sy, kWord, sz, sg);
262- end;
263- end;
264-end;
265-
266-procedure RealExpr(k: TKind; b: longint);
267-var c, n: longint; sy: TSym; a: TAdr; k2: TKind; v: int64;
268-begin
269- if b > 0 then c := Rnd(9) else c := Rnd(3);
270- case c of
271- 0: begin
272- n := Rnd(4);
273- if n = 0 then v := $3FF0000000000000
274- else if n = 1 then v := $4000000000000000
275- else if n = 2 then v := 0
276- else v := $3FE0000000000000;
277- PushConst(k, v);
278- end;
279- 1: begin
280- a := MemAdr;
281- if k = kF32 then PushVar(a, 4, false, k) else PushVar(a, 8, false, k);
282- end;
283- 2:
284- if numX > 0 then begin
285- if Flag then inPlace := xregs[Rnd(numX)];
286- PushVar(RegAdr(xregs[Rnd(numX)]), 8, false, k);
287- end else begin
288- PushAdr(PushableAdr);
289- a := StackAdr;
290- PushVar(a, 8, false, k);
291- end;
292- 3, 4: begin
293- RealExpr(k, b - 1); RealExpr(k, b - 1);
294- sy := RealOps[Rnd(4)];
295- Op(sy, k, 8, false);
296- end;
297- 5: begin
298- IntExpr(b - 1);
299- IntToReal(k, Flag);
300- end;
301- 6: begin
302- RealExpr(k, b - 1);
303- Neg(k, 8, false);
304- end;
305- 7: begin
306- if k = kF32 then k2 := kF64 else k2 := kF32;
307- RealExpr(k2, b - 1);
308- RealToReal(k2);
309- end;
310- else CallExpr(2, b - 1);
311- end;
312-end;
313-
314-procedure CallExpr(want, b: longint);
315-var
316- c: TCall; sig: PType; i, n, kind, r, ni: longint; k: TKind;
317-begin
318- sig := NewType(fProc, 8, 8);
319- sig^.variadic := Rnd(5) = 0;
320- if want = 1 then begin
321- r := Rnd(5);
322- if r = 0 then sig^.base := tBool
323- else if r = 1 then sig^.base := tI8
324- else if r = 2 then sig^.base := tU32
325- else if r = 3 then sig^.base := tuple2
326- else sig^.base := tInt;
327- end else if want = 2 then begin
328- if Flag then sig^.base := tReal else sig^.base := tF32;
329- end else
330- sig^.base := results[Rnd(9)];
331- c.sig := sig; c.param := nil; c.obj := nil; c.ext := Rnd(4) = 0;
332- c.n := 0; c.target := 0;
333- c.chunk := FirstProc + Rnd(NumProcs);
334- if Rnd(5) = 0 then begin c.chunk := -1; c.ext := false; c.target := Slot end;
335- n := Rnd(8);
336- for i := 0 to n - 1 do begin
337- kind := Rnd(4);
338- if kind = 0 then begin
339- k := RealKind;
340- RealExpr(k, b);
341- c.isF[c.n] := true; c.pair[c.n] := false;
342- inc(c.n);
343- end else if kind = 1 then begin
344- IntExpr(b); IntExpr(b);
345- c.isF[c.n] := false; c.pair[c.n] := true;
346- c.isF[c.n + 1] := false; c.pair[c.n + 1] := false;
347- inc(c.n, 2);
348- end else begin
349- IntExpr(b);
350- c.isF[c.n] := false; c.pair[c.n] := false;
351- inc(c.n);
352- end;
353- end;
354- Call(c);
355- ni := 0;
356- if sig^.base <> nil then begin
357- if sig^.base^.form = fSlice then ni := 0
358- else if sig^.base = tuple2 then ni := 2
359- else if BehindPointer(sig^.base) then ni := 0
360- else ni := 1;
361- end;
362- if want = 0 then begin
363- for i := 1 to ni do Drop;
364- end else if ni = 2 then
365- Drop;
366-end;
367-
368-procedure BoolExpr(b: longint);
369-var sy: TSym; sg: boolean;
370-begin
371- if Flag then begin
372- IntExpr(b); IntExpr(b);
373- sy := Cmps[Rnd(6)]; sg := Flag;
374- Compare(sy, kWord, sg);
375- end else
376- IntExpr(b);
377-end;
378-
379-procedure Stmt(b: longint); forward;
380-
381-procedure Assign(b: longint);
382-var a: TAdr; c, sz: longint; k: TKind;
383-begin
384- c := Rnd(6);
385- sz := Size;
386- if c = 0 then begin
387- a := MemAdr;
388- IntExpr(b);
389- PopVar(a, sz);
390- end else if c = 1 then begin
391- PushAdr(PushableAdr);
392- a := StackAdr;
393- IntExpr(b);
394- PopVar(a, sz);
395- end else if (c = 2) and (numRegs > 0) then begin
396- a := RegAdr(regs[Rnd(numRegs)]);
397- inPlace := a.chunk;
398- PushVar(a, 8, false, kWord);
399- IntExpr(b);
400- Op(Arith[Rnd(3)], kWord, 8, false);
401- PopVar(a, 8);
402- end else if (c = 3) and (numX > 0) then begin
403- k := RealKind;
404- a := RegAdr(xregs[Rnd(numX)]);
405- RealExpr(k, b);
406- PopVar(a, 8);
407- end else if c = 4 then begin
408- k := RealKind;
409- a := MemAdr;
410- RealExpr(k, b);
411- if k = kF32 then PopVar(a, 4) else PopVar(a, 8);
412- end else begin
413- a := MemAdr;
414- PushConst(kWord, ConstVal);
415- PopVar(a, sz);
416- end;
417-end;
418-
419-procedure RetStmt(b: longint);
420-var i: longint;
421-begin
422- if curRes = 1 then IntExpr(b)
423- else if curRes = 7 then IntExpr(b)
424- else if curRes = 2 then RealExpr(kF64, b)
425- else if curRes = 6 then RealExpr(kF32, b)
426- else if (curRes = 3) or (curRes = 4) then begin IntExpr(b); IntExpr(b) end
427- else if curRes = 5 then begin
428- for i := 0 to 2 do begin IntExpr(b); ResultTo(8 * i, 8) end;
429- end else if curRes = 8 then begin
430- PushAdr(PushableAdr);
431- CopyResult(0, 24);
432- end;
433- ReturnJump;
434-end;
435-
436-procedure Stmt(b: longint);
437-var
438- c, n, lo, i, start, saved, sz, tmp: longint; L, E, S, fj, tj: longint; a, a2: TAdr; sy: TSym; sg: boolean;
439- mk: int64; f: boolean;
440-begin
441- mk := TempMark;
442- if b <= 0 then c := Rnd(4) else c := Rnd(22);
443- case c of
444- 0, 1, 2, 3: Assign(b);
445- 4: begin
446- L := NoLabel;
447- BoolExpr(b);
448- JumpIf(L, false);
449- Stmt(b - 1);
450- Fix(L);
451- end;
452- 5: begin
453- L := NoLabel;
454- AlignLoop;
455- start := pc;
456- BoolExpr(b);
457- JumpIf(L, false);
458- Stmt(b - 1);
459- JumpBack(start);
460- Fix(L);
461- end;
462- 6: begin
463- L := NoLabel;
464- IntExpr(b); IntExpr(b);
465- sy := Cmps[Rnd(6)]; sg := Flag;
466- if Flag then JumpCmp(sy, sg, L) else JumpOut(sy, sg, L);
467- Stmt(b - 1);
468- Fix(L);
469- end;
470- 7: begin
471- fj := NoLabel; tj := NoLabel;
472- IntExpr(b); IntExpr(b);
473- sy := Cmps[Rnd(6)]; sg := Flag;
474- CondValue(sy, sg, fj, tj);
475- a := MemAdr;
476- PopVar(a, 1);
477- end;
478- 8: CallExpr(0, b);
479- 9: begin
480- a := MemAdr;
481- if a.base = bSlot then begin a.base := bFrame; a.off := slots[0] end;
482- IntExpr(b);
483- PopVar(a, 8);
484- E := NoLabel;
485- n := 2 + Rnd(4); lo := Rnd(5) - 2;
486- if Flag then S := NoLabel else S := pc;
487- start := JumpTable(a.off, lo, n, S, E);
488- for i := 0 to n - 1 do TableEntry(start, pc + 4 * (n - i));
489- for i := 0 to n - 1 do
490- Stmt(b - 1);
491- Fix(E);
492- end;
493- 10: begin
494- PushAdr(PushableAdr); PushAdr(PushableAdr);
495- n := 1 + Rnd(150); lo := 8 * Rnd(3);
496- CopyBlock(n, lo);
497- end;
498- 11: begin
499- PushAdr(PushableAdr);
500- a := MemAdr;
501- if Flag and (numRegs > 1) then begin
502- a.base := bReg; a.chunk := regs[0]; a.hi := regs[1]; a.off := 0;
503- end;
504- n := 1 + Rnd(150);
505- CopyTo(a, n);
506- end;
507- 12: begin
508- a := MemAdr;
509- n := 1 + Rnd(100);
510- ZeroVar(a, n);
511- end;
512- 13: begin
513- tmp := AllocTemp(16, 8);
514- n := Rnd(3);
515- sz := Size; sg := Flag;
516- if n = 0 then begin
517- a := PushableAdr;
518- PushAdr(a); IntExpr(b); IntExpr(b);
519- a := StackAdr; a.off := 0;
520- f := Flag; n := 10 + Rnd(50);
521- Slice(a, f, n, sz, tmp, sg, Pos);
522- end else if n = 1 then begin
523- a := MemAdr;
524- if a.base = bGlobal then a.base := bFrame;
525- IntExpr(b); IntExpr(b);
526- Slice(a, false, 0, sz, tmp, sg, Pos);
527- end else begin
528- IntExpr(b); IntExpr(b); IntExpr(b);
529- SlicePtr(sz, tmp, sg, Pos);
530- end;
531- end;
532- 14: begin
533- a.off := Slot; a2.off := Slot; sz := Size; f := Flag;
534- CopySlice(a.off, a2.off, sz, f, Pos);
535- end;
536- 15: begin
537- n := Rnd(4); sz := Size; sg := Flag;
538- if n = 0 then begin
539- PushAdr(PushableAdr); IntExpr(b);
540- f := Flag;
541- IncDec(sz, sg, f);
542- end else if (n = 1) and (numRegs > 0) then begin
543- IntExpr(b);
544- IncDecReg(regs[0], sz, sg, Flag);
545- end else if n = 2 then begin
546- IntExpr(b);
547- n := 3 + Rnd(6); lo := FirstGlob + Rnd(NumGlobs);
548- CheckEnum(n, lo, Pos);
549- Drop;
550- end else begin
551- IntExpr(b);
552- n := Rnd(8000);
553- CheckNil(n, Pos);
554- Drop;
555- end;
556- end;
557- 16: begin
558- n := Rnd(3);
559- if n = 0 then begin
560- a.off := Slot; a2.off := Slot; n := Rnd(4); f := Flag;
561- CompareSeq(a.off, a2.off, n, f);
562- Drop;
563- end else if n = 1 then begin
564- IntExpr(b);
565- ErrorText(AllocTemp(16, 8));
566- end else begin
567- IntExpr(b);
568- n := 1 + Rnd(200);
569- ZeroNew(n);
570- Drop;
571- end;
572- end;
573- 17: begin
574- n := Rnd(3);
575- if n = 0 then begin
576- IntExpr(b); IntExpr(b); IntExpr(b);
577- Atomic(bCas);
578- end else if n = 1 then begin
579- IntExpr(b); IntExpr(b);
580- Atomic(bXchg);
581- end else begin
582- IntExpr(b); IntExpr(b);
583- Atomic(bXadd);
584- end;
585- Drop;
586- end;
587- 18: begin
588- n := Rnd(7);
589- for i := 1 to n do IntExpr(b);
590- SysCall(n);
591- Drop;
592- if Flag then Fence;
593- end;
594- 19: begin
595- L := NoLabel;
596- start := DeferBegin(L, saved);
597- Stmt(b - 1);
598- DeferEnd(L, saved);
599- RunDefer(start);
600- end;
601- 20: if curRes <> 0 then RetStmt(b) else Assign(b);
602- else
603- if curRes <> 0 then begin
604- TryAlign;
605- TryReturn(Slot);
606- end else
607- Assign(b);
608- end;
609- ReleaseTemps(mk);
610-end;
611-
612-procedure GenProc(c: longint);
613-var
614- sig: PType; params, p, last: PObj; i, n, kind, mask, j, ns, line: longint; t: PType;
615- mk: TCodeMark; open: boolean;
616-begin
617- sig := NewType(fProc, 8, 8);
618- curRes := Rnd(9);
619- sig^.base := results[curRes];
620- params := nil; last := nil;
621- n := Rnd(8);
622- for i := 0 to n - 1 do begin
623- kind := Rnd(5);
624- if kind = 0 then t := tReal
625- else if kind = 1 then t := sliceT
626- else if kind = 2 then t := tI32
627- else t := tInt;
628- p := NewObj(oVar, 0, t);
629- p^.param := true;
630- p^.isVar := kind = 4;
631- if last = nil then params := p else last^.next := p;
632- last := p;
633- end;
634- BeginProc(sig, params);
635- for i := 0 to 5 do slots[i] := AllocPerm(8, 8);
636- mask := Rnd(32);
637- j := Rnd(16);
638- mask := mask or (j shl XBit);
639- if Rnd(3) = 0 then mask := 0;
640- numRegs := 0; numX := 0;
641- for j := 0 to 4 do
642- if mask and (1 shl j) <> 0 then begin regs[numRegs] := VarRegs[j]; inc(numRegs) end;
643- for j := 0 to 3 do
644- if mask and (1 shl (XBit + j)) <> 0 then begin
645- xregs[numX] := XVarRegs[j]; inc(numX);
646- XHome(XVarRegs[j], AllocPerm(8, 8));
647- end;
648- j := 0;
649- p := params;
650- while p <> nil do begin
651- if (p^.typ = tInt) and (not p^.isVar) and (j < numRegs) and Flag then begin
652- p^.reg := regs[j]; inc(j);
653- end else if (p^.typ = tReal) and (numX > 0) and Flag then begin
654- p^.reg := xregs[0];
655- end else if Flag then
656- KeepArrived(p);
657- p := p^.next;
658- end;
659- UseRegs(mask);
660- line := 1 + Rnd(40);
661- EnterBody(c, line);
662- MarkCode(mk);
663- if Flag then begin
664- Stmt(2);
665- Rewind(mk);
666- Redo(mk);
667- end;
668- ns := 2 + Rnd(8);
669- for i := 1 to ns do Stmt(3);
670- open := Flag and (sig^.base <> nil);
671- if (sig^.base <> nil) and (not open) then RetStmt(2);
672- EndProc(c, open);
673- writeln('proc ', c, ' lost ', Bit(lost), ' regs ', mask, ' saves ', chunks^[c].saveMask, ' at ', chunks^[c].saveAt);
674-end;
675-
676-function ChunkNameOf(i: longint): longint;
677-var s: string;
678-begin
679- s := 'p' + chr(48 + i div 10) + chr(48 + i mod 10);
680- ChunkNameOf := Intern(@s[1], 3);
681-end;
682-
683-var
684- i, c, entry: longint; path: string; links: array[0..1] of TLink; dyn: boolean;
685-begin
686- seed := 5;
687- path := 'lib/Rt.raz';
688- if Open(path) <> '' then Fatal('no file');
689- dyn := ParamCount >= 1;
690- listing := true;
691- curFile := Intern(@path[1], length(path));
692- for i := 0 to NumProcs - 1 do begin c := NewChunk(secText, -1, ChunkNameOf(i)); chunks^[c].live := true end;
693- for i := 0 to NumGlobs - 1 do begin
694- c := NewChunk(secBss, -1, ChunkNameOf(NumProcs + i));
695- SetBss(c, 64, 8);
696- end;
697- MakeTypes;
698- for i := 0 to NumProcs - 1 do GenProc(FirstProc + i);
699- links[0].chunk := FirstProc; links[0].into := FirstGlob;
700- links[1].chunk := FirstProc + 1; links[1].into := FirstGlob + 1;
701- entry := EntryPoint(dyn, nil, nil, FirstProc + 2, FirstProc + 3, links, 2);
702- writeln('entry ', entry, ' pc ', pc, ' fixups ', numFixups, ' lines ', numLines, ' said ', SaidCount);
703- for i := 0 to pc - 1 do write(HexStr(code^[i], 2));
704- writeln;
705- for i := 0 to numFixups - 1 do writeln('F ', fixups^[i].at, ' ', fixups^[i].chunk, ' ', fixups^[i].addend);
706- for i := 0 to numLines - 1 do writeln('L ', lines^[i].at, ' ', lines^[i].chunk, ' ', lines^[i].line, ' ', lines^[i].col);
707- List(-1);
708-end.

src/test/GenDump.raz deleted +0 -732

@@ -1,732 +0,0 @@
1-(* Compiles procedures made by a fixed pseudo-random script of calls to
2- Gen, valid by construction (an expression pushes its operands, then
3- operates on them; a statement leaves the stack as it found it), then
4- prints the bytes, the fixups, the line notes and the listing (raz -S)
5- of what it made: src/Gen.raz's side of a test against the seed's,
6- GenDump.pas, which makes and prints the same. With the argument dyn,
7- the entry point is the dynamic one. *)
8-module GenDump;
9-import Out, Fmt, Diag, Scan, Sym, Chunk, X := X64, Gen;
10-
11-const
12- FirstProc = 3; (* chunks 0 to 2 are Gen's own *)
13- NumProcs = 80;
14- FirstGlob = FirstProc + NumProcs;
15- NumGlobs = 4;
16- Arith: [10]Scan.Sym = [Scan.sPlus, Scan.sMinus, Scan.sTimes, Scan.sDiv, Scan.sMod,
17- Scan.sAmp, Scan.sBar, Scan.sXor, Scan.sShl, Scan.sShr];
18- Cmps: [6]Scan.Sym = [Scan.sEql, Scan.sNeq, Scan.sLss, Scan.sLeq, Scan.sGtr, Scan.sGeq];
19- RealOps: [4]Scan.Sym = [Scan.sPlus, Scan.sMinus, Scan.sTimes, Scan.sSlash];
20-
21-var
22- seed: I64;
23- slots: [6]I64; (* frame slots of the procedure *)
24- regs: [5]INT; (* the registers of variables it keeps *)
25- numRegs: INT;
26- xregs: [4]INT; (* ... of reals, as numbered from XmmVar *)
27- numX: INT;
28- tuple2, tuple3, record3, sliceT: ^Sym.Type;
29- results: [9]^Sym.Type;
30- curRes: INT; (* the procedure's result: an index of results *)
31-
32-proc rnd(n: INT): INT;
33-begin
34- seed := (seed * 1103515245 + 12345) & 7FFFFFFFH;
35- return INT((seed shr 8) mod I64(n));
36-end;
37-
38-proc pos: Diag.Pos;
39-var p: Diag.Pos;
40-begin
41- p.f := 0; p.a := rnd(400); p.b := p.a + 1;
42- return p;
43-end;
44-
45-(* a size of 1, 2, 4 or 8 bytes *)
46-proc size: INT;
47-begin
48- return 1 shl rnd(4);
49-end;
50-
51-(* a slot of the procedure's frame *)
52-proc slot: I64;
53-begin
54- return slots[rnd(6)];
55-end;
56-
57-proc bit(f: BOOL): INT;
58-begin
59- if f then return 1; end;
60- return 0;
61-end;
62-
63-proc flag: BOOL;
64-begin
65- return rnd(2) = 0;
66-end;
67-
68-proc constVal: I64;
69-var x: INT; r: I64;
70-begin
71- x := rnd(1 shl 30);
72- match rnd(7) of
73- | 0: r := x mod 10;
74- | 1: r := -(x mod 100);
75- | 2: r := I64(1) shl (x mod 20);
76- | 3: r := x;
77- | 4: r := I64(x) * 4096 * 4096 * 9 - 7;
78- | 5: r := -I64(x) * 8;
79- | else: r := x mod 1000 - 500;
80- end;
81- return r;
82-end;
83-
84-proc newObjs(t: ^Sym.Type; n: INT): ^Sym.Obj;
85-var first, o, last: ^Sym.Obj; i: INT;
86-begin
87- first := nil; last := nil;
88- for i := 0 to n - 1 do
89- o := Sym.newObj(Sym.oVar, 0, t);
90- o^.val := 8 * i;
91- if last = nil then first := o; else last^.next := o; end;
92- last := o;
93- end;
94- return first;
95-end;
96-
97-proc makeTypes;
98-begin
99- tuple2 := Sym.newType(Sym.fRecord, 16, 8);
100- tuple2^.tuple := true; tuple2^.len := 2; tuple2^.fields := newObjs(Sym.tInt, 2);
101- tuple3 := Sym.newType(Sym.fRecord, 24, 8);
102- tuple3^.tuple := true; tuple3^.len := 3; tuple3^.fields := newObjs(Sym.tInt, 3);
103- record3 := Sym.newType(Sym.fRecord, 24, 8);
104- record3^.fields := newObjs(Sym.tReal, 3);
105- sliceT := Sym.newType(Sym.fSlice, 16, 8);
106- sliceT^.base := Sym.tU8;
107- results[0] := nil;
108- results[1] := Sym.tInt;
109- results[2] := Sym.tReal;
110- results[3] := sliceT;
111- results[4] := tuple2;
112- results[5] := tuple3;
113- results[6] := Sym.tF32;
114- results[7] := Sym.tI16;
115- results[8] := record3;
116-end;
117-
118-(* Variables *)
119-
120-(* the address of a variable of the procedure that has one: in the frame,
121- a chunk, or a slot holding its address *)
122-proc memAdr: Gen.Adr;
123-var a: Gen.Adr; c: INT;
124-begin
125- c := rnd(3);
126- if c = 0 then
127- a.base := Gen.bFrame; a.chunk := 0; a.hi := 0; a.off := slot(); if flag() then a.off := a.off + 8; end;
128- elsif c = 1 then
129- a.base := Gen.bGlobal; a.chunk := FirstGlob + rnd(NumGlobs); a.hi := 0; a.off := 8 * rnd(3);
130- else
131- a.base := Gen.bSlot; a.chunk := INT(slot()); a.hi := 0; a.off := 8 * rnd(3);
132- end;
133- return a;
134-end;
135-
136-(* an address that can go on the stack: frame or chunk *)
137-proc pushableAdr: Gen.Adr;
138-var a: Gen.Adr;
139-begin
140- a.chunk := 0; a.hi := 0;
141- if flag() then
142- a.base := Gen.bFrame; a.off := slot(); if flag() then a.off := a.off + 8; end;
143- else
144- a.base := Gen.bGlobal; a.chunk := FirstGlob + rnd(NumGlobs); a.off := 8 * rnd(3);
145- end;
146- return a;
147-end;
148-
149-proc regAdr(r: INT): Gen.Adr;
150-var a: Gen.Adr;
151-begin
152- a.base := Gen.bReg; a.chunk := r; a.hi := 0; a.off := 0;
153- return a;
154-end;
155-
156-proc stackAdr: Gen.Adr;
157-var a: Gen.Adr;
158-begin
159- a.base := Gen.bStack; a.chunk := 0; a.hi := 0; a.off := 8 * rnd(3);
160- return a;
161-end;
162-
163-proc pushIntVar;
164-var a: Gen.Adr; sz: INT; c: INT;
165-begin
166- sz := size();
167- c := rnd(5);
168- if (c = 0) and (numRegs > 0) then
169- if flag() then Gen.setInPlace(regs[rnd(numRegs)]); end;
170- Gen.pushVar(regAdr(regs[rnd(numRegs)]), 8, false, Gen.kWord);
171- elsif c = 1 then
172- Gen.pushAdr(pushableAdr());
173- a := stackAdr();
174- Gen.pushVar(a, sz, flag(), Gen.kWord);
175- else
176- a := memAdr();
177- Gen.pushVar(a, sz, flag(), Gen.kWord);
178- end;
179-end;
180-
181-proc intExpr(b: INT); forward;
182-proc realExpr(k: Gen.Kind; b: INT); forward;
183-proc callExpr(want, b: INT); forward;
184-
185-proc realKind: Gen.Kind;
186-begin
187- if flag() then return Gen.kF64; end;
188- return Gen.kF32;
189-end;
190-
191-proc intExpr(b: INT);
192-var c, sz, n: INT; sg, f: BOOL; k: Gen.Kind; sy: Scan.Sym; a: Gen.Adr;
193-begin
194- if b > 0 then c := rnd(14); else c := rnd(3); end;
195- match c of
196- | 0: Gen.pushConst(Gen.kWord, constVal());
197- | 1: pushIntVar();
198- | 2: pushIntVar();
199- | 3, 4, 5:
200- intExpr(b - 1); intExpr(b - 1);
201- sy := Arith[rnd(10)]; sz := size(); sg := flag();
202- Gen.op(sy, Gen.kWord, sz, sg);
203- | 6:
204- if flag() then
205- intExpr(b - 1); intExpr(b - 1);
206- sy := Cmps[rnd(6)]; sg := flag();
207- Gen.compare(sy, Gen.kWord, sg);
208- else
209- k := realKind();
210- realExpr(k, b - 1); realExpr(k, b - 1);
211- sy := Cmps[rnd(6)];
212- Gen.compare(sy, k, false);
213- end;
214- | 7:
215- intExpr(b - 1);
216- n := rnd(4); sz := size(); sg := flag();
217- if n = 0 then Gen.neg(Gen.kWord, sz, sg);
218- elsif n = 1 then Gen.complement(sz, sg);
219- elsif n = 2 then Gen.notBool();
220- else Gen.narrow(sz, sg); end;
221- | 8:
222- (* an element of an array in the frame or a chunk *)
223- intExpr(b - 1);
224- a := pushableAdr();
225- sz := size(); sg := flag();
226- n := 10 + rnd(100);
227- Gen.checkIndex(n, pos());
228- Gen.indexArray(a, sz);
229- a := stackAdr(); a.off := 0;
230- Gen.pushVar(a, sz, sg, Gen.kWord);
231- | 9:
232- (* an element of a slice, in a frame slot or on the stack, or in registers *)
233- n := rnd(3);
234- sz := size(); sg := flag();
235- if n = 0 then
236- a := memAdr();
237- if a.base = Gen.bGlobal then a.base := Gen.bFrame; end;
238- intExpr(b - 1);
239- f := flag();
240- Gen.indexSlice(a, sz, f, pos());
241- elsif n = 1 then
242- Gen.pushAdr(pushableAdr());
243- intExpr(b - 1);
244- a := stackAdr(); a.off := 0;
245- f := flag();
246- Gen.indexSlice(a, sz, f, pos());
247- else
248- a.base := Gen.bReg; a.chunk := X.R13; a.hi := X.R14; a.off := 0;
249- intExpr(b - 1);
250- f := flag();
251- Gen.indexSlice(a, sz, f, pos());
252- end;
253- a := stackAdr(); a.off := 0;
254- Gen.pushVar(a, sz, sg, Gen.kWord);
255- | 10:
256- k := realKind();
257- realExpr(k, b - 1);
258- Gen.realToInt(k);
259- | 11: callExpr(1, b - 1);
260- | 12:
261- (* x + 1, and the offset noted on a word *)
262- intExpr(b - 1);
263- Gen.pushConst(Gen.kWord, rnd(100) - 50);
264- Gen.op(Scan.sPlus, Gen.kWord, 8, false);
265- | else:
266- intExpr(b - 1);
267- Gen.pushConst(Gen.kWord, constVal());
268- sy := Arith[rnd(10)]; sz := size(); sg := flag();
269- Gen.op(sy, Gen.kWord, sz, sg);
270- end;
271-end;
272-
273-proc realExpr(k: Gen.Kind; b: INT);
274-var c, n: INT; sy: Scan.Sym; a: Gen.Adr; k2: Gen.Kind; v: I64;
275-begin
276- if b > 0 then c := rnd(9); else c := rnd(3); end;
277- match c of
278- | 0:
279- n := rnd(4);
280- if n = 0 then v := 3FF0000000000000H;
281- elsif n = 1 then v := 4000000000000000H;
282- elsif n = 2 then v := 0;
283- else v := 3FE0000000000000H; end;
284- Gen.pushConst(k, v);
285- | 1:
286- a := memAdr();
287- if k = Gen.kF32 then Gen.pushVar(a, 4, false, k); else Gen.pushVar(a, 8, false, k); end;
288- | 2:
289- if numX > 0 then
290- if flag() then Gen.setInPlace(xregs[rnd(numX)]); end;
291- Gen.pushVar(regAdr(xregs[rnd(numX)]), 8, false, k);
292- else
293- Gen.pushAdr(pushableAdr());
294- a := stackAdr();
295- Gen.pushVar(a, 8, false, k);
296- end;
297- | 3, 4:
298- realExpr(k, b - 1); realExpr(k, b - 1);
299- sy := RealOps[rnd(4)];
300- Gen.op(sy, k, 8, false);
301- | 5:
302- intExpr(b - 1);
303- Gen.intToReal(k, flag());
304- | 6:
305- realExpr(k, b - 1);
306- Gen.neg(k, 8, false);
307- | 7:
308- if k = Gen.kF32 then k2 := Gen.kF64; else k2 := Gen.kF32; end;
309- realExpr(k2, b - 1);
310- Gen.realToReal(k2);
311- | else: callExpr(2, b - 1);
312- end;
313-end;
314-
315-(* A call of one of the procedures, with arguments of all kinds. want: 0
316- for a statement, any result; 1 an integer is left on the stack, 2 a
317- real. *)
318-proc callExpr(want, b: INT);
319-var
320- c: Gen.CallInfo; sig: ^Sym.Type; i, n, kind, r, ni: INT; k: Gen.Kind;
321-begin
322- sig := Sym.newType(Sym.fProc, 8, 8);
323- sig^.variadic := rnd(5) = 0;
324- if want = 1 then
325- r := rnd(5);
326- if r = 0 then sig^.base := Sym.tBool;
327- elsif r = 1 then sig^.base := Sym.tI8;
328- elsif r = 2 then sig^.base := Sym.tU32;
329- elsif r = 3 then sig^.base := tuple2;
330- else sig^.base := Sym.tInt; end;
331- elsif want = 2 then
332- if flag() then sig^.base := Sym.tReal; else sig^.base := Sym.tF32; end;
333- else
334- sig^.base := results[rnd(9)];
335- end;
336- c.sig := sig; c.param := nil; c.obj := nil; c.ext := rnd(4) = 0;
337- c.n := 0; c.target := 0;
338- c.chunk := FirstProc + rnd(NumProcs);
339- if rnd(5) = 0 then c.chunk := -1; c.ext := false; c.target := slot(); end;
340- n := rnd(8);
341- for i := 0 to n - 1 do
342- kind := rnd(4);
343- if kind = 0 then
344- k := realKind();
345- realExpr(k, b);
346- c.isF[c.n] := true; c.pair[c.n] := false;
347- INC(c.n);
348- elsif kind = 1 then
349- intExpr(b); intExpr(b);
350- c.isF[c.n] := false; c.pair[c.n] := true;
351- c.isF[c.n + 1] := false; c.pair[c.n + 1] := false;
352- INC(c.n, 2);
353- else
354- intExpr(b);
355- c.isF[c.n] := false; c.pair[c.n] := false;
356- INC(c.n);
357- end;
358- end;
359- Gen.call(c);
360- (* what comes back: a value or two, or nothing, or a temporary *)
361- ni := 0;
362- if sig^.base # nil then
363- if sig^.base^.form = Sym.fSlice then ni := 0;
364- elsif sig^.base = tuple2 then ni := 2;
365- elsif Sym.behindPointer(sig^.base) then ni := 0;
366- else ni := 1; end;
367- end;
368- if want = 0 then
369- for i := 1 to ni do Gen.drop(); end;
370- elsif ni = 2 then
371- Gen.drop(); (* the second; the first is the value *)
372- end;
373-end;
374-
375-(* A condition, left as a BOOL on the stack *)
376-proc boolExpr(b: INT);
377-var sy: Scan.Sym; sg: BOOL;
378-begin
379- if flag() then
380- intExpr(b); intExpr(b);
381- sy := Cmps[rnd(6)]; sg := flag();
382- Gen.compare(sy, Gen.kWord, sg);
383- else
384- intExpr(b);
385- end;
386-end;
387-
388-proc stmt(b: INT); forward;
389-
390-(* a variable assigned the value on top: its address, if on the stack,
391- having been pushed first *)
392-proc assign(b: INT);
393-var a: Gen.Adr; c, sz: INT; k: Gen.Kind;
394-begin
395- c := rnd(6);
396- sz := size();
397- if c = 0 then
398- a := memAdr();
399- intExpr(b);
400- Gen.popVar(a, sz);
401- elsif c = 1 then
402- Gen.pushAdr(pushableAdr());
403- a := stackAdr();
404- intExpr(b);
405- Gen.popVar(a, sz);
406- elsif (c = 2) and (numRegs > 0) then
407- a := regAdr(regs[rnd(numRegs)]);
408- Gen.setInPlace(a.chunk);
409- Gen.pushVar(a, 8, false, Gen.kWord);
410- intExpr(b);
411- Gen.op(Arith[rnd(3)], Gen.kWord, 8, false);
412- Gen.popVar(a, 8);
413- elsif (c = 3) and (numX > 0) then
414- k := realKind();
415- a := regAdr(xregs[rnd(numX)]);
416- realExpr(k, b);
417- Gen.popVar(a, 8);
418- elsif c = 4 then
419- k := realKind();
420- a := memAdr();
421- realExpr(k, b);
422- if k = Gen.kF32 then Gen.popVar(a, 4); else Gen.popVar(a, 8); end;
423- else
424- a := memAdr();
425- Gen.pushConst(Gen.kWord, constVal());
426- Gen.popVar(a, sz);
427- end;
428-end;
429-
430-proc retStmt(b: INT);
431-var i: INT;
432-begin
433- if curRes = 1 then intExpr(b);
434- elsif curRes = 7 then intExpr(b);
435- elsif curRes = 2 then realExpr(Gen.kF64, b);
436- elsif curRes = 6 then realExpr(Gen.kF32, b);
437- elsif (curRes = 3) or (curRes = 4) then intExpr(b); intExpr(b);
438- elsif curRes = 5 then
439- for i := 0 to 2 do intExpr(b); Gen.resultTo(8 * i, 8); end;
440- elsif curRes = 8 then
441- Gen.pushAdr(pushableAdr());
442- Gen.copyResult(0, 24);
443- end;
444- Gen.returnJump();
445-end;
446-
447-proc stmt(b: INT);
448-var
449- c, n, lo, i, start, saved, sz, tmp: INT; L, E, S, fj, tj: INT; a, a2: Gen.Adr; sy: Scan.Sym; sg: BOOL;
450- mk: I64; f: BOOL;
451-begin
452- mk := Gen.tempMark();
453- if b <= 0 then c := rnd(4); else c := rnd(22); end;
454- match c of
455- | 0, 1, 2, 3: assign(b);
456- | 4:
457- (* if cond then s end *)
458- L := Gen.NoLabel;
459- boolExpr(b);
460- Gen.jumpIf(L, false);
461- stmt(b - 1);
462- Gen.fix(L);
463- | 5:
464- (* while cond do s end *)
465- L := Gen.NoLabel;
466- Gen.alignLoop();
467- start := Chunk.pc;
468- boolExpr(b);
469- Gen.jumpIf(L, false);
470- stmt(b - 1);
471- Gen.jumpBack(start);
472- Gen.fix(L);
473- | 6:
474- (* if a < b then s end, with a jump on the comparison *)
475- L := Gen.NoLabel;
476- intExpr(b); intExpr(b);
477- sy := Cmps[rnd(6)]; sg := flag();
478- if flag() then Gen.jumpCmp(sy, sg, L); else Gen.jumpOut(sy, sg, L); end;
479- stmt(b - 1);
480- Gen.fix(L);
481- | 7:
482- (* v := a < b and c, a condition worked out into a BOOL *)
483- fj := Gen.NoLabel; tj := Gen.NoLabel;
484- intExpr(b); intExpr(b);
485- sy := Cmps[rnd(6)]; sg := flag();
486- Gen.condValue(sy, sg, fj, tj);
487- a := memAdr();
488- Gen.popVar(a, 1);
489- | 8: callExpr(0, b);
490- | 9:
491- (* a match through a jump table *)
492- a := memAdr();
493- if a.base = Gen.bSlot then a.base := Gen.bFrame; a.off := slots[0]; end;
494- intExpr(b);
495- Gen.popVar(a, 8);
496- E := Gen.NoLabel;
497- n := 2 + rnd(4); lo := rnd(5) - 2;
498- if flag() then S := Gen.NoLabel; else S := Chunk.pc; end;
499- start := Gen.jumpTable(a.off, lo, n, S, E);
500- for i := 0 to n - 1 do Gen.tableEntry(start, Chunk.pc + 4 * (n - i)); end;
501- for i := 0 to n - 1 do
502- stmt(b - 1);
503- end;
504- Gen.fix(E);
505- | 10:
506- Gen.pushAdr(pushableAdr()); Gen.pushAdr(pushableAdr());
507- n := 1 + rnd(150); lo := 8 * rnd(3);
508- Gen.copyBlock(n, lo);
509- | 11:
510- Gen.pushAdr(pushableAdr());
511- a := memAdr();
512- if flag() and (numRegs > 1) then
513- a.base := Gen.bReg; a.chunk := regs[0]; a.hi := regs[1]; a.off := 0;
514- end;
515- n := 1 + rnd(150);
516- Gen.copyTo(a, n);
517- | 12:
518- a := memAdr();
519- n := 1 + rnd(100);
520- Gen.zeroVar(a, n);
521- | 13:
522- (* a slice of an array, of a slice, of a pointer *)
523- tmp := INT(Gen.allocTemp(16, 8));
524- n := rnd(3);
525- sz := size(); sg := flag();
526- if n = 0 then
527- a := pushableAdr();
528- Gen.pushAdr(a); intExpr(b); intExpr(b);
529- a := stackAdr(); a.off := 0;
530- f := flag(); n := 10 + rnd(50);
531- Gen.slice(a, f, n, sz, tmp, sg, pos());
532- elsif n = 1 then
533- a := memAdr();
534- if a.base = Gen.bGlobal then a.base := Gen.bFrame; end;
535- intExpr(b); intExpr(b);
536- Gen.slice(a, false, 0, sz, tmp, sg, pos());
537- else
538- intExpr(b); intExpr(b); intExpr(b);
539- Gen.slicePtr(sz, tmp, sg, pos());
540- end;
541- | 14:
542- a.off := slot(); a2.off := slot(); sz := size(); f := flag();
543- Gen.copySlice(a.off, a2.off, sz, f, pos());
544- | 15:
545- n := rnd(4); sz := size(); sg := flag();
546- if n = 0 then
547- Gen.pushAdr(pushableAdr()); intExpr(b);
548- f := flag();
549- Gen.incDec(sz, sg, f);
550- elsif (n = 1) and (numRegs > 0) then
551- intExpr(b);
552- Gen.incDecReg(regs[0], sz, sg, flag());
553- elsif n = 2 then
554- intExpr(b);
555- n := 3 + rnd(6); lo := FirstGlob + rnd(NumGlobs);
556- Gen.checkEnum(n, lo, pos());
557- Gen.drop();
558- else
559- intExpr(b);
560- n := rnd(8000);
561- Gen.checkNil(n, pos());
562- Gen.drop();
563- end;
564- | 16:
565- n := rnd(3);
566- if n = 0 then
567- a.off := slot(); a2.off := slot(); n := rnd(4); f := flag();
568- Gen.compareSeq(a.off, a2.off, n, f);
569- Gen.drop();
570- elsif n = 1 then
571- intExpr(b);
572- Gen.errorText(Gen.allocTemp(16, 8));
573- else
574- intExpr(b);
575- n := 1 + rnd(200);
576- Gen.zeroNew(n);
577- Gen.drop();
578- end;
579- | 17:
580- n := rnd(3);
581- if n = 0 then
582- intExpr(b); intExpr(b); intExpr(b);
583- Gen.atomic(Sym.bCas);
584- elsif n = 1 then
585- intExpr(b); intExpr(b);
586- Gen.atomic(Sym.bXchg);
587- else
588- intExpr(b); intExpr(b);
589- Gen.atomic(Sym.bXadd);
590- end;
591- Gen.drop();
592- | 18:
593- n := rnd(7);
594- for i := 1 to n do intExpr(b); end;
595- Gen.sysCall(n);
596- Gen.drop();
597- if flag() then Gen.fence(); end;
598- | 19:
599- (* defer s *)
600- L := Gen.NoLabel;
601- start, saved := Gen.deferBegin(L);
602- stmt(b - 1);
603- Gen.deferEnd(L, saved);
604- Gen.runDefer(start);
605- | 20:
606- if curRes # 0 then retStmt(b); else assign(b); end;
607- | else:
608- if curRes # 0 then
609- Gen.tryAlign();
610- Gen.tryReturn(slot());
611- else
612- assign(b);
613- end;
614- end;
615- Gen.releaseTemps(mk);
616-end;
617-
618-(* Each statement may be preceded by a few that are made and taken back,
619- as the parser does when it compiles a body a second time *)
620-proc genProc(c: INT);
621-var
622- sig: ^Sym.Type; params, p, last: ^Sym.Obj; i, n, kind, mask, j, ns, line: INT; t: ^Sym.Type;
623- mk: Gen.CodeMark; open: BOOL;
624-begin
625- sig := Sym.newType(Sym.fProc, 8, 8);
626- curRes := rnd(9);
627- sig^.base := results[curRes];
628- params := nil; last := nil;
629- n := rnd(8);
630- for i := 0 to n - 1 do
631- kind := rnd(5);
632- if kind = 0 then t := Sym.tReal;
633- elsif kind = 1 then t := sliceT;
634- elsif kind = 2 then t := Sym.tI32;
635- else t := Sym.tInt; end;
636- p := Sym.newObj(Sym.oVar, 0, t);
637- p^.param := true;
638- p^.isVar := kind = 4;
639- if last = nil then params := p; else last^.next := p; end;
640- last := p;
641- end;
642- Gen.beginProc(sig, params);
643- for i := 0 to 5 do slots[i] := Gen.allocPerm(8, 8); end;
644- mask := rnd(32);
645- j := rnd(16);
646- mask := mask | (j shl Gen.XBit);
647- if rnd(3) = 0 then mask := 0; end;
648- numRegs := 0; numX := 0;
649- for j := 0 to 4 do
650- if (mask & (1 shl j)) # 0 then regs[numRegs] := Gen.VarRegs[j]; INC(numRegs); end;
651- end;
652- for j := 0 to 3 do
653- if (mask & (1 shl (Gen.XBit + j))) # 0 then
654- xregs[numX] := Gen.XVarRegs[j]; INC(numX);
655- Gen.xHome(Gen.XVarRegs[j], Gen.allocPerm(8, 8));
656- end;
657- end;
658- (* some parameters live in registers: a register variable's, or kept
659- where they arrived *)
660- j := 0;
661- p := params;
662- while p # nil do
663- if (p^.typ = Sym.tInt) and (not p^.isVar) and (j < numRegs) and flag() then
664- p^.reg := regs[j]; INC(j);
665- elsif (p^.typ = Sym.tReal) and (numX > 0) and flag() then
666- p^.reg := xregs[0];
667- elsif flag() then
668- Gen.keepArrived(p);
669- end;
670- p := p^.next;
671- end;
672- Gen.useRegs(mask);
673- line := 1 + rnd(40);
674- Gen.enterBody(c, line);
675- Gen.markCode(mk);
676- (* a body made and taken back *)
677- if flag() then
678- stmt(2);
679- Gen.rewind(mk);
680- Gen.redo(mk); (* the jumps to the exit went with the code *)
681- end;
682- ns := 2 + rnd(8);
683- for i := 1 to ns do stmt(3); end;
684- open := flag() and (sig^.base # nil);
685- if (sig^.base # nil) and (not open) then retStmt(2); end;
686- _ := Gen.endProc(c, open);
687- Fmt.print("proc {} lost {} regs {} saves {} at {}\n", [Fmt.int(c), Fmt.int(bit(Gen.lost)), Fmt.int(mask),
688- Fmt.int(Chunk.chunks[c].saveMask), Fmt.int(Chunk.chunks[c].saveAt)]);
689-end;
690-
691-(* The name p0, p1, ... of chunk i, interned *)
692-proc chunkNameOf(i: INT): INT;
693-var s: [3]U8;
694-begin
695- s[0] := 'p'; s[1] := U8(48 + i div 10); s[2] := U8(48 + i mod 10);
696- return Scan.intern(ADR(s[0]), 3);
697-end;
698-
699-proc main*;
700-var i, c: INT; path: []U8; links: [2]Gen.Link; entry: INT; dyn: BOOL;
701-begin
702- seed := 5;
703- path := "lib/Rt.raz";
704- if LEN(Scan.open(path)) # 0 then Diag.fatal("no file"); end;
705- dyn := ARGC > 1;
706- X.setListing(true);
707- Chunk.setCurFile(Scan.intern(ADR(path[0]), LEN(path)));
708- for i := 0 to NumProcs - 1 do c := Chunk.newChunk(Chunk.secText, -1, chunkNameOf(i)); Chunk.setLive(c); end;
709- for i := 0 to NumGlobs - 1 do
710- c := Chunk.newChunk(Chunk.secBss, -1, chunkNameOf(NumProcs + i));
711- Chunk.setBss(c, 64, 8);
712- end;
713- makeTypes();
714- for i := 0 to NumProcs - 1 do genProc(FirstProc + i); end;
715- links[0].chunk := FirstProc; links[0].into := FirstGlob;
716- links[1].chunk := FirstProc + 1; links[1].into := FirstGlob + 1;
717- entry := Gen.entryPoint(dyn, nil, nil, FirstProc + 2, FirstProc + 3, links, 2);
718- Fmt.print("entry {} pc {} fixups {} lines {} said {}\n", [Fmt.int(entry), Fmt.int(Chunk.pc),
719- Fmt.int(Chunk.numFixups), Fmt.int(Chunk.numLines), Fmt.int(X.saidCount())]);
720- for i := 0 to Chunk.pc - 1 do Out.hex(U64(Chunk.text[i]), 2); end;
721- Out.ln;
722- for i := 0 to Chunk.numFixups - 1 do
723- Fmt.print("F {} {} {}\n", [Fmt.int(Chunk.fixups[i].at), Fmt.int(Chunk.fixups[i].chunk), Fmt.int(Chunk.fixups[i].addend)]);
724- end;
725- for i := 0 to Chunk.numLines - 1 do
726- Fmt.print("L {} {} {} {}\n", [Fmt.int(Chunk.lines[i].at), Fmt.int(Chunk.lines[i].chunk),
727- Fmt.int(Chunk.lines[i].line), Fmt.int(Chunk.lines[i].col)]);
728- end;
729- X.list(-1);
730-end;
731-
732-end GenDump.

src/test/ItemDump.pas deleted +0 -665

@@ -1,665 +0,0 @@
1-{ Drives item with a fixed pseudo-random script of operands and
2- operations, with mistakes among them, and prints what each step gave
3- (the item, or that it failed, whose message goes to standard error),
4- then the bytes, fixups, line notes and listing (raz -S) of the code
5- it made: the seed's side of a test of src/Item.raz, whose
6- ItemDump.raz does and prints the same. The argument, a number,
7- changes the script. A run ends at the 20th error, as a compile does,
8- so several scripts are run. }
9-program itemdump;
10-{$mode objfpc}{$H-}
11-uses diag, scan, seedcontinue, sym, chunk, x64, gen, item;
12-
13-const
14- FirstProc = 3;
15- NumProcs = 30;
16- FirstGlob = FirstProc + NumProcs;
17- NumGlobs = 4;
18- Steps = 14;
19- YInt = 0; YI64 = 1; YI32 = 2; YU8 = 3; YU16 = 4; YU32 = 5; YU64 = 6; YBool = 7;
20- YReal = 8; YF32 = 9; YI8 = 10; YEnum = 11; YSet = 12; YPtr = 13; YVptr = 14;
21- YPtrArr = 15; YArr = 16; YArrU8 = 17; YSlice = 18; YBytes = 19; YRec = 20;
22- YPacked = 21; YVariant = 22; YProc0 = 23; YProc1 = 24; YProc2 = 25;
23- YPtrRec = 26; YErr = 27; YVrec = 28; YVarr = 29;
24- NumT = 30;
25- IntTypes: array[0..7] of longint = (YInt, YI64, YI32, YU8, YU16, YU32, YU64, YI8);
26- Ops: array[0..19] of TSym = (sPlus, sMinus, sTimes, sDiv, sMod,
27- sAmp, sBar, sXor, sShl, sShr,
28- sEql, sNeq, sLss, sLeq, sGtr, sGeq,
29- sSlash, sIn, sPlus, sMinus);
30- Cmps: array[0..5] of TSym = (sEql, sNeq, sLss, sLeq, sGtr, sGeq);
31-
32-var
33- Letters: string[9];
34- seed: int64;
35- ty: array[0..NumT - 1] of PType;
36- vars: array[0..NumT - 1] of PObj;
37- procs: array[0..5] of PObj;
38- strs: array[0..2] of PObj;
39- arrConst, typeObj, builtinObj, caseObj: PObj;
40- mod0, mod1: PModule;
41- tuple2, record3, packedR, variantT: PType;
42- results: array[0..8] of PType;
43- curRes: longint;
44- call: TCall;
45- jb: jmp_buf;
46- gK: longint;
47- gX: TItem;
48- gOk: boolean;
49-
50-function Rnd(n: longint): longint;
51-begin
52- seed := (seed * 1103515245 + 12345) and $7FFFFFFF;
53- Rnd := (seed shr 8) mod n;
54-end;
55-
56-function Flag: boolean;
57-begin
58- Flag := Rnd(2) = 0;
59-end;
60-
61-function Bit(f: boolean): longint;
62-begin
63- if f then Bit := 1 else Bit := 0;
64-end;
65-
66-function Pos: TPos;
67-var p: TPos;
68-begin
69- p.f := 0; p.a := Rnd(400); p.b := p.a + 1 + Rnd(12);
70- Pos := p;
71-end;
72-
73-function ConstVal: int64;
74-var x: longint; r: int64;
75-begin
76- x := Rnd(1 shl 30);
77- case Rnd(7) of
78- 0: r := x mod 10;
79- 1: r := -(x mod 100);
80- 2: r := int64(1) shl (x mod 20);
81- 3: r := x;
82- 4: r := int64(x) * 4096 * 4096 * 9 - 7;
83- 5: r := -int64(x) * 8;
84- else r := x mod 1000 - 500;
85- end;
86- ConstVal := r;
87-end;
88-
89-function InternStr(const s: shortstring): longint;
90-begin
91- InternStr := Intern(@s[1], length(s));
92-end;
93-
94-{ A name v00, v01, ... , interned }
95-function NameOf(i: longint): longint;
96-var s: string[3];
97-begin
98- s := 'v' + chr(48 + i div 10) + chr(48 + i mod 10);
99- NameOf := Intern(@s[1], 3);
100-end;
101-
102-function NewObjs(cls: TClass; t: PType; n: longint; step: int64; at: longint): PObj;
103-var first, o, last: PObj; i: longint;
104-begin
105- first := nil; last := nil;
106- for i := 0 to n - 1 do begin
107- o := NewObj(cls, NameOf(at + i), t);
108- o^.val := step * i;
109- if last = nil then first := o else last^.next := o;
110- last := o;
111- end;
112- NewObjs := first;
113-end;
114-
115-function ProcType(res: PType; params: PObj; n: longint): PType;
116-var t: PType;
117-begin
118- t := NewType(fProc, 8, 8);
119- t^.base := res;
120- t^.fields := params;
121- t^.len := n;
122- ProcType := t;
123-end;
124-
125-function Param(t: PType; isVar: boolean; at: longint): PObj;
126-var o: PObj;
127-begin
128- o := NewObj(oVar, NameOf(at), t);
129- o^.param := true;
130- o^.isVar := isVar;
131- Param := o;
132-end;
133-
134-procedure MakeTypes;
135-var t: PType; p, q, r: PObj; i: longint;
136-begin
137- ty[YInt] := tInt; ty[YI64] := tI64; ty[YI32] := tI32; ty[YU8] := tU8;
138- ty[YU16] := tU16; ty[YU32] := tU32; ty[YU64] := tU64; ty[YBool] := tBool;
139- ty[YReal] := tReal; ty[YF32] := tF32; ty[YI8] := tI8; ty[YErr] := tError;
140- ty[YBytes] := tBytes;
141- t := NewType(fEnum, 1, 1); t^.len := 5; ty[YEnum] := t;
142- t := NewType(fSet, 8, 8); t^.len := 5; t^.base := ty[YEnum]; ty[YSet] := t;
143- t := NewType(fPtr, 8, 8); t^.base := tI64; ty[YPtr] := t;
144- t := NewType(fPtr, 8, 8); t^.base := tI64; t^.vol := true; ty[YVptr] := t;
145- t := NewType(fArray, 48, 8); t^.base := tI64; t^.len := 6; ty[YArr] := t;
146- t := NewType(fPtr, 8, 8); t^.base := ty[YArr]; ty[YPtrArr] := t;
147- t := NewType(fPtr, 8, 8); t^.base := ty[YArr]; t^.vol := true; ty[YVarr] := t;
148- t := NewType(fArray, 8, 1); t^.base := tU8; t^.len := 8; ty[YArrU8] := t;
149- t := NewType(fSlice, 16, 8); t^.base := tI64; ty[YSlice] := t;
150- record3 := NewType(fRecord, 24, 8);
151- p := NewObj(oField, NameOf(40), tI64); p^.val := 0;
152- q := NewObj(oField, NameOf(41), tReal); q^.val := 8; p^.next := q;
153- r := NewObj(oField, NameOf(42), tI32); r^.val := 16; q^.next := r;
154- record3^.fields := p;
155- ty[YRec] := record3;
156- t := NewType(fPtr, 8, 8); t^.base := record3; ty[YPtrRec] := t;
157- t := NewType(fPtr, 8, 8); t^.base := record3; t^.vol := true; ty[YVrec] := t;
158- packedR := NewType(fRecord, 53, 1);
159- packedR^.packd := true;
160- p := NewObj(oField, NameOf(43), tU8); p^.val := 0;
161- q := NewObj(oField, NameOf(44), tI32); q^.val := 1; p^.next := q;
162- r := NewObj(oField, NameOf(46), ty[YArr]); r^.val := 5; q^.next := r;
163- packedR^.fields := p;
164- ty[YPacked] := packedR;
165- variantT := NewType(fVariant, 16, 8);
166- ty[YVariant] := variantT;
167- tuple2 := NewType(fRecord, 16, 8);
168- tuple2^.tuple := true; tuple2^.len := 2; tuple2^.fields := NewObjs(oVar, tInt, 2, 8, 45);
169- p := Param(tInt, false, 46); p^.next := Param(tReal, false, 47);
170- ty[YProc0] := ProcType(tInt, p, 2);
171- ty[YProc1] := ProcType(nil, nil, 0);
172- p := Param(tI64, true, 48); p^.next := Param(ty[YSlice], false, 49);
173- ty[YProc2] := ProcType(tuple2, p, 2);
174- results[0] := nil; results[1] := tInt; results[2] := tReal; results[3] := ty[YSlice];
175- results[4] := tuple2; results[5] := record3; results[6] := tF32; results[7] := tI16;
176- results[8] := ty[YBytes];
177- for i := 0 to NumT - 1 do
178- if ty[i] = nil then Fatal('a type is missing');
179-end;
180-
181-procedure MakeObjs;
182-var i, c: longint; o: PObj;
183-begin
184- New(mod0); mod0^.name := InternStr('Zero');
185- New(mod1); mod1^.name := InternStr('Other');
186- curModule := mod0;
187- for i := 0 to 5 do begin
188- o := NewObj(oProc, NameOf(50 + i), ty[YProc0 + i mod 3]);
189- o^.chunk := FirstProc + Rnd(NumProcs);
190- o^.ext := i >= 4;
191- o^.isCode := i = 3;
192- procs[i] := o;
193- end;
194- for i := 0 to 2 do begin
195- o := NewObj(oConst, NameOf(60 + i), tStr);
196- o^.val := 2 + 3 * i;
197- c := NewChunk(secRodata, -1, -1);
198- SetData(c, @Letters[1], o^.val + 1, 1);
199- o^.chunk := c;
200- strs[i] := o;
201- end;
202- arrConst := NewObj(oConst, NameOf(63), ty[YArr]);
203- arrConst^.chunk := NewChunk(secRodata, -1, -1);
204- SetData(arrConst^.chunk, @Letters[1], 8, 8);
205- typeObj := NewObj(oType, NameOf(64), ty[YRec]);
206- builtinObj := NewObj(oBuiltin, NameOf(65), tNone);
207- caseObj := NewObj(oCase, NameOf(66), variantT);
208- caseObj^.val := 3;
209- caseObj^.fields := NewObjs(oField, tInt, 2, 8, 67);
210- caseObj^.fields^.val := 8;
211-end;
212-
213-procedure MakeVars;
214-var i, k: longint; o: PObj; t: PType;
215-begin
216- for i := 0 to NumT - 1 do begin
217- t := ty[i];
218- o := NewObj(oVar, NameOf(i), t);
219- o^.lev := 1;
220- k := Rnd(9);
221- if k = 2 then begin
222- o^.lev := 0; o^.chunk := FirstGlob + Rnd(NumGlobs);
223- end else if k = 3 then begin
224- o^.ind := true; o^.val := AllocPerm(8, 8); o^.off := 8 * Rnd(3);
225- end else if k = 4 then begin
226- if (t^.form in [fInt, fPtr]) and (t^.size = 8) then
227- o^.reg := VarRegs[Rnd(5)]
228- else if t^.form = fReal then
229- o^.reg := XVarRegs[Rnd(4)]
230- else if t^.form = fSlice then begin
231- o^.reg := VarRegs[Rnd(3)]; o^.reg2 := VarRegs[3 + Rnd(2)];
232- end;
233- if o^.reg = 0 then o^.val := AllocPerm(t^.size, 8);
234- end else if k = 5 then begin
235- o^.lev := 0; o^.chunk := FirstGlob + Rnd(NumGlobs); o^.module := mod1;
236- end else if k = 6 then begin
237- o^.lev := 0; o^.chunk := FirstGlob + Rnd(NumGlobs); o^.ext := true;
238- end else
239- o^.val := AllocPerm(t^.size + 8, 8);
240- vars[i] := o;
241- end;
242-end;
243-
244-{ Operands }
245-
246-function IntType: PType;
247-begin
248- IntType := ty[IntTypes[Rnd(8)]];
249-end;
250-
251-procedure VarItem(var x: TItem; t: PType);
252-var i, k: longint;
253-begin
254- k := Rnd(NumT);
255- for i := 0 to NumT - 1 do
256- if ty[i] = t then k := i;
257- FillChar(x, SizeOf(x), 0);
258- x.pos := Pos;
259- MakeItem(x, vars[k]);
260-end;
261-
262-procedure Operand(var x: TItem; t: PType);
263-var k: longint; r: double; v: int64;
264-begin
265- FillChar(x, SizeOf(x), 0);
266- x.pos := Pos;
267- if t = nil then begin
268- case Rnd(14) of
269- 0: MakeConst(x, tConst, ConstVal);
270- 1: MakeConst(x, tConst, ConstVal mod 200);
271- 2: begin t := IntType; v := ConstVal mod 100; MakeConst(x, t, v) end;
272- 3: begin r := (ConstVal mod 1000) / 8.0; MakeReal(x, r) end;
273- 4: MakeConst(x, tBool, Rnd(2));
274- 5: MakeItem(x, strs[Rnd(3)]);
275- 6: MakeConst(x, tNil, 0);
276- 7: MakeItem(x, procs[Rnd(6)]);
277- 8: begin
278- if Rnd(4) = 0 then begin
279- case Rnd(3) of
280- 0: MakeItem(x, typeObj);
281- 1: MakeItem(x, builtinObj);
282- else MakeItem(x, caseObj);
283- end;
284- end else
285- MakeItem(x, arrConst);
286- end;
287- 13: begin MakeItem(x, vars[Rnd(NumT)]); Value(x) end;
288- else VarItem(x, ty[Rnd(NumT)]);
289- end;
290- exit;
291- end;
292- k := Rnd(10);
293- if IsInt(t) then begin
294- if k < 3 then begin MakeConst(x, tConst, ConstVal mod 100); exit end;
295- if k = 3 then begin MakeConst(x, t, ConstVal mod 100); exit end;
296- end else if t^.form = fReal then begin
297- if k < 3 then begin r := (ConstVal mod 1000) / 8.0; MakeReal(x, r); exit end;
298- end else if t^.form = fBool then begin
299- if k < 3 then begin MakeConst(x, tBool, Rnd(2)); exit end;
300- end else if t^.form = fPtr then begin
301- if k < 2 then begin MakeConst(x, tNil, 0); exit end;
302- end else if (t^.form = fSlice) and (t^.base = tU8) then begin
303- if k < 3 then begin MakeItem(x, strs[Rnd(3)]); exit end;
304- end;
305- VarItem(x, t);
306-end;
307-
308-procedure CondItem(var x: TItem);
309-var y: TItem; L: longint; op: TSym; t: PType;
310-begin
311- t := IntType;
312- op := Cmps[Rnd(6)];
313- Operand(x, t);
314- Op1(op, x, L);
315- Operand(y, t);
316- Op2(op, x, y, L);
317-end;
318-
319-procedure Place(var x: TItem);
320-var i, k: longint; f: PObj; y, lo, hi: TItem;
321-begin
322- VarItem(x, ty[Rnd(NumT)]);
323- for i := 1 to 3 do begin
324- if Rnd(3) <> 0 then begin
325- k := Rnd(6);
326- if (k = 0) or (x.typ^.form = fPtr) then
327- Deref(x)
328- else if x.typ^.form = fRecord then begin
329- f := x.typ^.fields;
330- k := Rnd(3);
331- while (k > 0) and (f^.next <> nil) do begin f := f^.next; dec(k) end;
332- Field(x, f);
333- end else if x.typ^.form in [fArray, fSlice, fStr] then begin
334- IndexPrep(x);
335- if k < 4 then begin
336- Operand(y, IntType);
337- Index(x, y);
338- end else begin
339- Operand(lo, IntType);
340- SliceLo(lo);
341- Operand(hi, IntType);
342- Slice(x, lo, hi);
343- end;
344- end;
345- end;
346- end;
347-end;
348-
349-procedure Dump(var x: TItem);
350-var name: shortstring; flags: longint;
351-begin
352- name := '-';
353- if x.typ <> nil then name := TypeName(x.typ);
354- flags := Bit(x.vol) + 2 * Bit(x.isVar) + 4 * Bit(x.odd) + 8 * Bit(x.ro) + 16 * Bit(x.deref);
355- write('I ', ord(x.mode), ' ', name, ' ', ord(x.rel), ' ', Bit(x.relSigned), ' ', x.fj, ' ', x.tj, ' ', x.val);
356- writeln(' ', ord(x.base), ' ', x.chunk, ' ', x.off, ' ', flags, ' depth ', depth, ' pushed ', pushed);
357-end;
358-
359-procedure DoCall(var x: TItem);
360-var f, a: TItem; p: PObj; n: longint;
361-begin
362- FillChar(f, SizeOf(f), 0);
363- f.pos := Pos;
364- if Rnd(5) = 0 then MakeItem(f, vars[YProc0 + Rnd(3)])
365- else MakeItem(f, procs[Rnd(6)]);
366- BeginCall(call, f);
367- p := call.param;
368- n := Rnd(4) - 1;
369- while (p <> nil) or (n > 0) do begin
370- if p <> nil then begin
371- if p^.isVar and (Rnd(2) = 0) then begin
372- VarItem(a, ty[YVptr]);
373- Deref(a);
374- end else if Rnd(6) = 0 then Operand(a, nil)
375- else Operand(a, p^.typ);
376- p := p^.next;
377- end else begin
378- Operand(a, nil);
379- n := n - 1;
380- end;
381- PassArg(call, a);
382- if (p = nil) and (n < 0) then n := 0;
383- if (p <> nil) and (n < 0) and (Rnd(4) = 0) then begin p := nil; n := 0 end;
384- end;
385- EndCall(call, x);
386-end;
387-
388-procedure Binary(var x: TItem);
389-var y: TItem; L, M: longint; op: TSym; t: PType;
390-begin
391- L := NoLabel;
392- M := NoLabel;
393- op := Ops[Rnd(20)];
394- case Rnd(8) of
395- 0, 1: t := IntType;
396- 2: t := ty[YReal + Rnd(2)];
397- 3: t := ty[YBool];
398- 4: t := ty[YEnum + Rnd(2)];
399- else t := ty[Rnd(NumT)];
400- end;
401- if Rnd(6) = 0 then begin
402- if Flag then op := sAnd else op := sOr;
403- CondItem(x);
404- Op1(op, x, L);
405- CondItem(y);
406- end else if op = sIn then begin
407- Operand(x, ty[YEnum]);
408- Op1(op, x, L);
409- Operand(y, ty[YSet]);
410- end else begin
411- Operand(x, t);
412- Op1(op, x, L);
413- if Rnd(5) = 0 then Operand(y, nil) else Operand(y, t);
414- end;
415- Op2(op, x, y, L);
416- if (x.mode = mCond) and (Rnd(3) <> 0) then begin
417- if Flag then CondJump(x, M) else CondJumpTrue(x, M);
418- Fix(M);
419- x.mode := mNone;
420- end;
421-end;
422-
423-procedure Unary(var x: TItem);
424-begin
425- Operand(x, nil);
426- case Rnd(3) of
427- 0: Neg(x);
428- 1: NotOp(x);
429- else Complement(x);
430- end;
431-end;
432-
433-procedure DoMatch(var x: TItem);
434-var p, lo, hi: int64; L: longint;
435-begin
436- L := NoLabel;
437- case Rnd(3) of
438- 0: VarItem(x, ty[YVariant]);
439- 1: VarItem(x, ty[YEnum]);
440- else Operand(x, nil);
441- end;
442- p := MatchBegin(x);
443- MatchTag(p, ConstVal mod 10, L);
444- lo := ConstVal mod 10;
445- hi := ConstVal mod 10 + 10;
446- MatchRange(p, lo, hi, L);
447- MatchRange(p, 3, 3, L);
448- Fix(L);
449-end;
450-
451-procedure DoFor(var x: TItem);
452-var o: PObj; lim: TItem; step: int64; exitL: longint;
453-begin
454- o := vars[IntTypes[Rnd(8)]];
455- step := ConstVal mod 5;
456- if step = 0 then step := 1;
457- if Rnd(2) = 0 then step := -step;
458- FillChar(lim, SizeOf(lim), 0);
459- lim.pos := Pos;
460- MakeConst(lim, o^.typ, ConstVal mod 50);
461- exitL := NoLabel;
462- ForStep(o, step);
463- ForNext(o, lim, step, exitL, pc, pc);
464- Fix(exitL);
465- x := lim;
466-end;
467-
468-procedure DoMisc(var x: TItem);
469-var y: TItem;
470-begin
471- case Rnd(5) of
472- 0: begin
473- Place(x);
474- Address(x);
475- Operand(y, x.typ);
476- IncDec(x, y, Flag);
477- end;
478- 1: begin
479- Place(x);
480- Pin(x);
481- end;
482- 2: begin
483- Place(x);
484- CopyDest(x);
485- Place(y);
486- CopyFrom(x, y);
487- end;
488- 3: begin
489- Operand(x, nil);
490- MakeStr(y);
491- Coerce(y, ty[YBytes]);
492- end;
493- else begin
494- Operand(x, nil);
495- NilTest(x);
496- UsesReals(x.pos);
497- Discard(x);
498- end;
499- end;
500-end;
501-
502-procedure DoTemp(var x: TItem);
503-var a: TItem; c, h, n: longint; f: PObj;
504-begin
505- FillChar(x, SizeOf(x), 0);
506- x.pos := Pos;
507- case Rnd(5) of
508- 0: ZeroTemp(x, ty[YVariant]);
509- 1: begin
510- Construct(x, caseObj);
511- f := caseObj^.fields;
512- Operand(a, f^.typ);
513- SetField(x, f, a);
514- end;
515- 2: begin
516- ZeroTemp(x, ty[YRec]);
517- f := ty[YRec]^.fields;
518- if Flag then f := f^.next;
519- Operand(a, f^.typ);
520- SetField(x, f, a);
521- end;
522- 3: begin
523- Operand(a, nil);
524- h := Rnd(3) - 1;
525- n := Rnd(3) - 1;
526- c := ErrorChunk(a, h, n);
527- MakeConst(x, tError, int64(c) + 1);
528- end;
529- else begin
530- Operand(x, ty[YErr]);
531- Msg(x);
532- end;
533- end;
534-end;
535-
536-procedure DoReturn(var x: TItem);
537-var f: PObj;
538-begin
539- if (curRes = 4) and Flag then begin
540- f := tuple2^.fields;
541- if Flag then f := f^.next;
542- if Flag then begin
543- Operand(x, f^.typ);
544- ReturnField(f, x);
545- exit;
546- end;
547- DoCall(x);
548- ReturnAll(x);
549- exit;
550- end;
551- if Rnd(4) = 0 then begin ReturnNone; exit end;
552- Operand(x, results[curRes]);
553- ReturnValue(x);
554-end;
555-
556-procedure Step(k: longint; var x: TItem);
557-var y: TItem;
558-begin
559- FillChar(x, SizeOf(x), 0);
560- case k of
561- 0: begin Operand(x, nil); Value(x) end;
562- 1: begin Operand(x, nil); Address(x) end;
563- 2: begin Operand(x, nil); Coerce(x, ty[Rnd(NumT)]) end;
564- 3: begin Operand(x, nil); CoerceExact(x, IntType, '') end;
565- 4: begin
566- Place(x);
567- Operand(y, x.typ);
568- Assign(x, y);
569- end;
570- 5: Unary(x);
571- 6: Binary(x);
572- 7: begin Operand(x, nil); Convert(x, ty[Rnd(NumT)]) end;
573- 8: Place(x);
574- 9: DoCall(x);
575- 10: DoMatch(x);
576- 11: DoFor(x);
577- 12: DoMisc(x);
578- 13: DoTemp(x);
579- 14: DoReturn(x);
580- else Binary(x);
581- end;
582-end;
583-
584-{ A step, and what it leaves, each a recovery point as the parser's
585- statements are }
586-procedure RunStep;
587-begin
588- gOk := false;
589- recovery := @jb;
590- if setjmp(jb) = 0 then begin
591- Step(gK, gX);
592- gOk := true;
593- end;
594- recovery := nil;
595-end;
596-
597-procedure RunDiscard;
598-begin
599- recovery := @jb;
600- if setjmp(jb) = 0 then Discard(gX);
601- recovery := nil;
602-end;
603-
604-procedure GenProc(c: longint);
605-var sig: PType; i, line: longint;
606-begin
607- curRes := Rnd(9);
608- sig := ProcType(results[curRes], nil, 0);
609- BeginProc(sig, nil);
610- for i := 0 to 5 do AllocPerm(8, 8);
611- MakeVars;
612- checks := Flag;
613- line := 1 + Rnd(40);
614- EnterBody(c, line);
615- for i := 1 to Steps do begin
616- if errors >= 19 then break;
617- gK := Rnd(17);
618- demoted := false;
619- RunStep;
620- if not gOk then
621- writeln('S ', c, ' ', gK, ' failed')
622- else begin
623- writeln('S ', c, ' ', gK, ' ok');
624- Dump(gX);
625- if (gK < 4) or ((gK >= 5) and (gK <= 9)) then RunDiscard;
626- end;
627- writeln('demoted ', Bit(demoted));
628- ResetStack(0, 0);
629- end;
630- EndProc(c, sig^.base <> nil);
631-end;
632-
633-function ChunkNameOf(i: longint): longint;
634-var s: string;
635-begin
636- s := 'p' + chr(48 + i div 10) + chr(48 + i mod 10);
637- ChunkNameOf := Intern(@s[1], 3);
638-end;
639-
640-var
641- i, c: longint; path: string;
642-begin
643- seed := 5;
644- for i := 1 to length(ParamStr(1)) do seed := seed * 10 + ord(ParamStr(1)[i]) - 48;
645- Letters := 'abcdefgh' + #0;
646- path := 'src/test/ItemDump.txt';
647- if Open(path) <> '' then Fatal('no file');
648- Next;
649- listing := true;
650- curFile := Intern(@path[1], length(path));
651- for i := 0 to NumProcs - 1 do begin c := NewChunk(secText, -1, ChunkNameOf(i)); chunks^[c].live := true end;
652- for i := 0 to NumGlobs - 1 do begin
653- c := NewChunk(secBss, -1, ChunkNameOf(NumProcs + i));
654- SetBss(c, 64, 8);
655- end;
656- MakeTypes;
657- MakeObjs;
658- for i := 0 to NumProcs - 1 do GenProc(FirstProc + i);
659- writeln('pc ', pc, ' fixups ', numFixups, ' lines ', numLines, ' said ', SaidCount);
660- for i := 0 to pc - 1 do write(HexStr(code^[i], 2));
661- writeln;
662- for i := 0 to numFixups - 1 do writeln('F ', fixups^[i].at, ' ', fixups^[i].chunk, ' ', fixups^[i].addend);
663- for i := 0 to numLines - 1 do writeln('L ', lines^[i].at, ' ', lines^[i].chunk, ' ', lines^[i].line, ' ', lines^[i].col);
664- List(-1);
665-end.

src/test/ItemDump.raz deleted +0 -679

@@ -1,679 +0,0 @@
1-(* Drives Item with a fixed pseudo-random script of operands and
2- operations, with mistakes among them, and prints what each step gave
3- (the item, or that it failed, whose message goes to standard error),
4- then the bytes, fixups, line notes and listing (raz -S) of the code
5- it made: src/Item.raz's side of a test against the seed's,
6- ItemDump.pas, which does and prints the same. The argument, a digit,
7- changes the script. A run ends at the 20th error, as a compile does,
8- so several scripts are run. *)
9-module ItemDump;
10-import Out, Fmt, Files, Heap, Diag, Scan, Sym, Chunk, X := X64, Gen, Item;
11-
12-const
13- FirstProc = 3; (* chunks 0 to 2 are Gen's own *)
14- NumProcs = 30;
15- FirstGlob = FirstProc + NumProcs;
16- NumGlobs = 4;
17- Steps = 14;
18- (* the types of the script, by number *)
19- YInt = 0; YI64 = 1; YI32 = 2; YU8 = 3; YU16 = 4; YU32 = 5; YU64 = 6; YBool = 7;
20- YReal = 8; YF32 = 9; YI8 = 10; YEnum = 11; YSet = 12; YPtr = 13; YVptr = 14;
21- YPtrArr = 15; YArr = 16; YArrU8 = 17; YSlice = 18; YBytes = 19; YRec = 20;
22- YPacked = 21; YVariant = 22; YProc0 = 23; YProc1 = 24; YProc2 = 25;
23- YPtrRec = 26; YErr = 27; YVrec = 28; YVarr = 29;
24- NumT = 30;
25- IntTypes: [8]INT = [YInt, YI64, YI32, YU8, YU16, YU32, YU64, YI8];
26- Ops: [20]Scan.Sym = [Scan.sPlus, Scan.sMinus, Scan.sTimes, Scan.sDiv, Scan.sMod,
27- Scan.sAmp, Scan.sBar, Scan.sXor, Scan.sShl, Scan.sShr,
28- Scan.sEql, Scan.sNeq, Scan.sLss, Scan.sLeq, Scan.sGtr, Scan.sGeq,
29- Scan.sSlash, Scan.sIn, Scan.sPlus, Scan.sMinus];
30- Cmps: [6]Scan.Sym = [Scan.sEql, Scan.sNeq, Scan.sLss, Scan.sLeq, Scan.sGtr, Scan.sGeq];
31-
32-var
33- Letters: []U8;
34- seed: I64;
35- ty: [NumT]^Sym.Type;
36- vars: [NumT]^Sym.Obj; (* a variable of each type, placed anew for each procedure *)
37- procs: [6]^Sym.Obj;
38- strs: [3]^Sym.Obj;
39- arrConst, typeObj, builtinObj, caseObj: ^Sym.Obj;
40- mod0, mod1: ^Sym.Module;
41- tuple2, record3, packedR, variantT: ^Sym.Type;
42- results: [9]^Sym.Type;
43- curRes: INT; (* the result of the procedure, an index of results *)
44- call: Gen.CallInfo;
45-
46-proc rnd(n: INT): INT;
47-begin
48- seed := (seed * 1103515245 + 12345) & 7FFFFFFFH;
49- return INT((seed shr 8) mod I64(n));
50-end;
51-
52-proc flag: BOOL;
53-begin
54- return rnd(2) = 0;
55-end;
56-
57-proc bit(f: BOOL): INT;
58-begin
59- if f then return 1; end;
60- return 0;
61-end;
62-
63-proc pos: Diag.Pos;
64-var p: Diag.Pos;
65-begin
66- p.f := 0; p.a := rnd(400); p.b := p.a + 1 + rnd(12);
67- return p;
68-end;
69-
70-proc constVal: I64;
71-var x: INT; r: I64;
72-begin
73- x := rnd(1 shl 30);
74- match rnd(7) of
75- | 0: r := x mod 10;
76- | 1: r := -(x mod 100);
77- | 2: r := I64(1) shl (x mod 20);
78- | 3: r := x;
79- | 4: r := I64(x) * 4096 * 4096 * 9 - 7;
80- | 5: r := -I64(x) * 8;
81- | else: r := x mod 1000 - 500;
82- end;
83- return r;
84-end;
85-
86-(* A name, interned *)
87-proc intern(s: []U8): INT;
88-begin
89- return Scan.intern(ADR(s[0]), LEN(s));
90-end;
91-
92-(* A name v00, v01, ... , interned *)
93-proc nameOf(i: INT): INT;
94-var s: [3]U8;
95-begin
96- s[0] := 'v'; s[1] := U8(48 + i div 10); s[2] := U8(48 + i mod 10);
97- return Scan.intern(ADR(s[0]), 3);
98-end;
99-
100-proc newObjs(cls: Sym.Class; t: ^Sym.Type; n: INT; step: I64; at: INT): ^Sym.Obj;
101-var first, o, last: ^Sym.Obj; i: INT;
102-begin
103- first := nil; last := nil;
104- for i := 0 to n - 1 do
105- o := Sym.newObj(cls, nameOf(at + i), t);
106- o^.val := step * I64(i);
107- if last = nil then first := o; else last^.next := o; end;
108- last := o;
109- end;
110- return first;
111-end;
112-
113-proc newType(form: Sym.Form; size, align: I64): ^Sym.Type;
114-begin
115- return Sym.newType(form, size, align);
116-end;
117-
118-proc procType(res: ^Sym.Type; params: ^Sym.Obj; n: INT): ^Sym.Type;
119-var t: ^Sym.Type;
120-begin
121- t := newType(Sym.fProc, 8, 8);
122- t^.base := res;
123- t^.fields := params;
124- t^.len := n;
125- return t;
126-end;
127-
128-proc param(t: ^Sym.Type; isVar: BOOL; at: INT): ^Sym.Obj;
129-var o: ^Sym.Obj;
130-begin
131- o := Sym.newObj(Sym.oVar, nameOf(at), t);
132- o^.param := true;
133- o^.isVar := isVar;
134- return o;
135-end;
136-
137-proc makeTypes;
138-var t: ^Sym.Type; p, q, r: ^Sym.Obj; i: INT;
139-begin
140- ty[YInt] := Sym.tInt; ty[YI64] := Sym.tI64; ty[YI32] := Sym.tI32; ty[YU8] := Sym.tU8;
141- ty[YU16] := Sym.tU16; ty[YU32] := Sym.tU32; ty[YU64] := Sym.tU64; ty[YBool] := Sym.tBool;
142- ty[YReal] := Sym.tReal; ty[YF32] := Sym.tF32; ty[YI8] := Sym.tI8; ty[YErr] := Sym.tError;
143- ty[YBytes] := Sym.tBytes;
144- t := newType(Sym.fEnum, 1, 1); t^.len := 5; ty[YEnum] := t;
145- t := newType(Sym.fSet, 8, 8); t^.len := 5; t^.base := ty[YEnum]; ty[YSet] := t;
146- t := newType(Sym.fPtr, 8, 8); t^.base := Sym.tI64; ty[YPtr] := t;
147- t := newType(Sym.fPtr, 8, 8); t^.base := Sym.tI64; t^.vol := true; ty[YVptr] := t;
148- t := newType(Sym.fArray, 48, 8); t^.base := Sym.tI64; t^.len := 6; ty[YArr] := t;
149- t := newType(Sym.fPtr, 8, 8); t^.base := ty[YArr]; ty[YPtrArr] := t;
150- t := newType(Sym.fPtr, 8, 8); t^.base := ty[YArr]; t^.vol := true; ty[YVarr] := t;
151- t := newType(Sym.fArray, 8, 1); t^.base := Sym.tU8; t^.len := 8; ty[YArrU8] := t;
152- t := newType(Sym.fSlice, 16, 8); t^.base := Sym.tI64; ty[YSlice] := t;
153- (* a record of an I64, an F64 and an I32 *)
154- record3 := newType(Sym.fRecord, 24, 8);
155- p := Sym.newObj(Sym.oField, nameOf(40), Sym.tI64); p^.val := 0;
156- q := Sym.newObj(Sym.oField, nameOf(41), Sym.tReal); q^.val := 8; p^.next := q;
157- r := Sym.newObj(Sym.oField, nameOf(42), Sym.tI32); r^.val := 16; q^.next := r;
158- record3^.fields := p;
159- ty[YRec] := record3;
160- t := newType(Sym.fPtr, 8, 8); t^.base := record3; ty[YPtrRec] := t;
161- t := newType(Sym.fPtr, 8, 8); t^.base := record3; t^.vol := true; ty[YVrec] := t;
162- (* a packed record: a byte, then an I32 that may be misaligned *)
163- packedR := newType(Sym.fRecord, 53, 1);
164- packedR^.packd := true;
165- p := Sym.newObj(Sym.oField, nameOf(43), Sym.tU8); p^.val := 0;
166- q := Sym.newObj(Sym.oField, nameOf(44), Sym.tI32); q^.val := 1; p^.next := q;
167- r := Sym.newObj(Sym.oField, nameOf(46), ty[YArr]); r^.val := 5; q^.next := r;
168- packedR^.fields := p;
169- ty[YPacked] := packedR;
170- variantT := newType(Sym.fVariant, 16, 8);
171- ty[YVariant] := variantT;
172- tuple2 := newType(Sym.fRecord, 16, 8);
173- tuple2^.tuple := true; tuple2^.len := 2; tuple2^.fields := newObjs(Sym.oVar, Sym.tInt, 2, 8, 45);
174- (* procedures: (I64, F64) I64; (); (var I64, []I64) of two results *)
175- p := param(Sym.tInt, false, 46); p^.next := param(Sym.tReal, false, 47);
176- ty[YProc0] := procType(Sym.tInt, p, 2);
177- ty[YProc1] := procType(nil, nil, 0);
178- p := param(Sym.tI64, true, 48); p^.next := param(ty[YSlice], false, 49);
179- ty[YProc2] := procType(tuple2, p, 2);
180- results[0] := nil; results[1] := Sym.tInt; results[2] := Sym.tReal; results[3] := ty[YSlice];
181- results[4] := tuple2; results[5] := record3; results[6] := Sym.tF32; results[7] := Sym.tI16;
182- results[8] := ty[YBytes];
183- for i := 0 to NumT - 1 do
184- if ty[i] = nil then Diag.fatal("a type is missing"); end;
185- end;
186-end;
187-
188-(* The objects named by the script: procedures, strings, constants of
189- an array, a type, a built-in, a case of a variant *)
190-proc makeObjs;
191-var i, c: INT; o: ^Sym.Obj;
192-begin
193- NEW(mod0, Heap.heap); mod0^.name := intern("Zero");
194- NEW(mod1, Heap.heap); mod1^.name := intern("Other");
195- Sym.setCurModule(mod0);
196- for i := 0 to 5 do
197- o := Sym.newObj(Sym.oProc, nameOf(50 + i), ty[YProc0 + i mod 3]);
198- o^.chunk := FirstProc + rnd(NumProcs);
199- o^.ext := i >= 4;
200- o^.isCode := i = 3;
201- procs[i] := o;
202- end;
203- for i := 0 to 2 do
204- o := Sym.newObj(Sym.oConst, nameOf(60 + i), Sym.tStr);
205- o^.val := 2 + 3 * i;
206- c := Chunk.newChunk(Chunk.secRodata, -1, -1);
207- Chunk.setData(c, ADR(Letters[0]), INT(o^.val) + 1, 1);
208- o^.chunk := c;
209- strs[i] := o;
210- end;
211- arrConst := Sym.newObj(Sym.oConst, nameOf(63), ty[YArr]);
212- arrConst^.chunk := Chunk.newChunk(Chunk.secRodata, -1, -1);
213- Chunk.setData(arrConst^.chunk, ADR(Letters[0]), 8, 8);
214- typeObj := Sym.newObj(Sym.oType, nameOf(64), ty[YRec]);
215- builtinObj := Sym.newObj(Sym.oBuiltin, nameOf(65), Sym.tNone);
216- caseObj := Sym.newObj(Sym.oCase, nameOf(66), variantT);
217- caseObj^.val := 3;
218- caseObj^.fields := newObjs(Sym.oField, Sym.tInt, 2, 8, 67);
219- caseObj^.fields^.val := 8;
220-end;
221-
222-(* The variable of each type, in the frame, a chunk, a slot, a register,
223- another module or C's, as the procedure compiled has them *)
224-proc makeVars;
225-var i, k: INT; o: ^Sym.Obj; t: ^Sym.Type;
226-begin
227- for i := 0 to NumT - 1 do
228- t := ty[i];
229- o := Sym.newObj(Sym.oVar, nameOf(i), t);
230- o^.lev := 1;
231- k := rnd(9);
232- if k = 2 then
233- o^.lev := 0; o^.chunk := FirstGlob + rnd(NumGlobs);
234- elsif k = 3 then
235- o^.ind := true; o^.val := Gen.allocPerm(8, 8); o^.off := 8 * rnd(3);
236- elsif k = 4 then
237- if (t^.form in {Sym.fInt, Sym.fPtr}) and (t^.size = 8) then
238- o^.reg := Gen.VarRegs[rnd(5)];
239- elsif t^.form = Sym.fReal then
240- o^.reg := Gen.XVarRegs[rnd(4)];
241- elsif t^.form = Sym.fSlice then
242- o^.reg := Gen.VarRegs[rnd(3)]; o^.reg2 := Gen.VarRegs[3 + rnd(2)];
243- end;
244- if o^.reg = 0 then o^.val := Gen.allocPerm(t^.size, 8); end;
245- elsif k = 5 then
246- o^.lev := 0; o^.chunk := FirstGlob + rnd(NumGlobs); o^.home := mod1;
247- elsif k = 6 then
248- o^.lev := 0; o^.chunk := FirstGlob + rnd(NumGlobs); o^.ext := true;
249- else
250- o^.val := Gen.allocPerm(t^.size + 8, 8);
251- end;
252- vars[i] := o;
253- end;
254-end;
255-
256-(* Operands *)
257-
258-proc intType: ^Sym.Type;
259-begin
260- return ty[IntTypes[rnd(8)]];
261-end;
262-
263-proc varItem(var x: Item.Item; t: ^Sym.Type): ERROR;
264-var i, k: INT;
265-begin
266- k := rnd(NumT);
267- for i := 0 to NumT - 1 do
268- if ty[i] = t then k := i; end;
269- end;
270- x := {};
271- x.pos := pos();
272- return Item.makeItem(x, vars[k]);
273-end;
274-
275-(* An operand of type t, or of any if t is nil *)
276-proc operand(var x: Item.Item; t: ^Sym.Type): ERROR;
277-var k: INT; r: F64; v: I64;
278-begin
279- x := {};
280- x.pos := pos();
281- if t = nil then
282- match rnd(14) of
283- | 0: Item.makeConst(x, Sym.tConst, constVal());
284- | 1: Item.makeConst(x, Sym.tConst, constVal() mod 200);
285- | 2: t := intType(); v := constVal() mod 100; Item.makeConst(x, t, v);
286- | 3: r := F64(constVal() mod 1000) / 8.0; Item.makeReal(x, r);
287- | 4: Item.makeConst(x, Sym.tBool, I64(rnd(2)));
288- | 5: return Item.makeItem(x, strs[rnd(3)]);
289- | 6: Item.makeConst(x, Sym.tNil, 0);
290- | 7: return Item.makeItem(x, procs[rnd(6)]);
291- | 8: if rnd(4) = 0 then
292- match rnd(3) of
293- | 0: return Item.makeItem(x, typeObj);
294- | 1: return Item.makeItem(x, builtinObj);
295- | else: return Item.makeItem(x, caseObj);
296- end;
297- end;
298- return Item.makeItem(x, arrConst);
299- | 13: try Item.makeItem(x, vars[rnd(NumT)]); return Item.value(x);
300- | else: return varItem(x, ty[rnd(NumT)]);
301- end;
302- return nil;
303- end;
304- k := rnd(10);
305- if Sym.isInt(t) then
306- if k < 3 then Item.makeConst(x, Sym.tConst, constVal() mod 100); return nil; end;
307- if k = 3 then Item.makeConst(x, t, constVal() mod 100); return nil; end;
308- elsif t^.form = Sym.fReal then
309- if k < 3 then r := F64(constVal() mod 1000) / 8.0; Item.makeReal(x, r); return nil; end;
310- elsif t^.form = Sym.fBool then
311- if k < 3 then Item.makeConst(x, Sym.tBool, I64(rnd(2))); return nil; end;
312- elsif t^.form = Sym.fPtr then
313- if k < 2 then Item.makeConst(x, Sym.tNil, 0); return nil; end;
314- elsif (t^.form = Sym.fSlice) and (t^.base = Sym.tU8) then
315- if k < 3 then return Item.makeItem(x, strs[rnd(3)]); end;
316- end;
317- return varItem(x, t);
318-end;
319-
320-(* A condition, left as one: a comparison of two integers *)
321-proc condItem(var x: Item.Item): ERROR;
322-var y: Item.Item; L: INT; op: Scan.Sym; t: ^Sym.Type;
323-begin
324- t := intType();
325- op := Cmps[rnd(6)];
326- try operand(x, t);
327- try Item.op1(op, x, L);
328- try operand(y, t);
329- return Item.op2(op, x, y, L);
330-end;
331-
332-(* A variable, or part of one: through a pointer, a field, an element, a slice *)
333-proc place(var x: Item.Item): ERROR;
334-var i, k: INT; f: ^Sym.Obj; y, lo, hi: Item.Item;
335-begin
336- try varItem(x, ty[rnd(NumT)]);
337- for i := 1 to 3 do
338- if rnd(3) # 0 then
339- k := rnd(6);
340- if (k = 0) or (x.typ^.form = Sym.fPtr) then
341- try Item.deref(x);
342- elsif x.typ^.form = Sym.fRecord then
343- f := x.typ^.fields;
344- k := rnd(3);
345- while (k > 0) and (f^.next # nil) do f := f^.next; DEC(k); end;
346- try Item.field(x, f);
347- elsif (x.typ^.form in {Sym.fArray, Sym.fSlice, Sym.fStr}) then
348- try Item.indexPrep(x);
349- if k < 4 then
350- try operand(y, intType());
351- try Item.index(x, y);
352- else
353- try operand(lo, intType());
354- try Item.sliceLo(lo);
355- try operand(hi, intType());
356- try Item.slice(x, lo, hi);
357- end;
358- end;
359- end;
360- end;
361- return nil;
362-end;
363-
364-(* The state of an item *)
365-proc dump(var x: Item.Item);
366-var name: []U8; flags: INT;
367-begin
368- name := "-";
369- if x.typ # nil then name := Sym.typeName(x.typ); end;
370- flags := bit(x.vol) + 2 * bit(x.isVar) + 4 * bit(x.odd) + 8 * bit(x.ro) + 16 * bit(x.deref);
371- Fmt.print("I {} {} {} {} {} {} {}", [Fmt.int(INT(x.mode)), Fmt.str(name), Fmt.int(INT(x.rel)),
372- Fmt.int(bit(x.relSigned)), Fmt.int(x.fj), Fmt.int(x.tj), Fmt.int(x.val)]);
373- Fmt.print(" {} {} {} {} depth {} pushed {}\n", [Fmt.int(INT(x.base)), Fmt.int(x.chunk), Fmt.int(x.off),
374- Fmt.int(flags), Fmt.int(Gen.depth), Fmt.int(Gen.pushed)]);
375-end;
376-
377-(* A call: of a procedure of the script or a variable of a procedure
378- type, with arguments that mostly fit its parameters *)
379-proc doCall(var x: Item.Item): ERROR;
380-var f, a: Item.Item; p: ^Sym.Obj; n: INT;
381-begin
382- f := {};
383- f.pos := pos();
384- if rnd(5) = 0 then try Item.makeItem(f, vars[YProc0 + rnd(3)]);
385- else try Item.makeItem(f, procs[rnd(6)]); end;
386- try Item.beginCall(call, f);
387- p := call.param;
388- n := rnd(4) - 1;
389- while (p # nil) or (n > 0) do
390- if p # nil then
391- if p^.isVar and (rnd(2) = 0) then
392- try varItem(a, ty[YVptr]);
393- try Item.deref(a);
394- elsif rnd(6) = 0 then try operand(a, nil);
395- else try operand(a, p^.typ); end;
396- p := p^.next;
397- else
398- try operand(a, nil);
399- n := n - 1;
400- end;
401- try Item.passArg(call, a);
402- if (p = nil) and (n < 0) then n := 0; end;
403- if (p # nil) and (n < 0) and (rnd(4) = 0) then p := nil; n := 0; end;
404- end;
405- return Item.endCall(call, x);
406-end;
407-
408-(* A binary operation, with a condition's jumps made after it, sometimes *)
409-proc binary(var x: Item.Item): ERROR;
410-var y: Item.Item; L, M: INT; op: Scan.Sym; t: ^Sym.Type;
411-begin
412- L := Gen.NoLabel;
413- M := Gen.NoLabel;
414- op := Ops[rnd(20)];
415- match rnd(8) of
416- | 0, 1: t := intType();
417- | 2: t := ty[YReal + rnd(2)];
418- | 3: t := ty[YBool];
419- | 4: t := ty[YEnum + rnd(2)];
420- | else: t := ty[rnd(NumT)];
421- end;
422- if rnd(6) = 0 then
423- (* and, or *)
424- if flag() then op := Scan.sAnd; else op := Scan.sOr; end;
425- try condItem(x);
426- try Item.op1(op, x, L);
427- try condItem(y);
428- elsif op = Scan.sIn then
429- try operand(x, ty[YEnum]);
430- try Item.op1(op, x, L);
431- try operand(y, ty[YSet]);
432- else
433- try operand(x, t);
434- try Item.op1(op, x, L);
435- if rnd(5) = 0 then try operand(y, nil); else try operand(y, t); end;
436- end;
437- try Item.op2(op, x, y, L);
438- if (x.mode = Item.mCond) and (rnd(3) # 0) then
439- if flag() then try Item.condJump(x, M); else try Item.condJumpTrue(x, M); end;
440- Gen.fix(M);
441- x.mode := Item.mNone; (* its values are used *)
442- end;
443- return nil;
444-end;
445-
446-proc unary(var x: Item.Item): ERROR;
447-begin
448- try operand(x, nil);
449- match rnd(3) of
450- | 0: return Item.neg(x);
451- | 1: return Item.notOp(x);
452- | else: return Item.complement(x);
453- end;
454-end;
455-
456-(* match: the slot of a variant, an enumeration or an integer, and
457- tests of it *)
458-proc doMatch(var x: Item.Item): ERROR;
459-var p, lo, hi: I64; L: INT;
460-begin
461- L := Gen.NoLabel;
462- match rnd(3) of
463- | 0: try varItem(x, ty[YVariant]);
464- | 1: try varItem(x, ty[YEnum]);
465- | else: try operand(x, nil);
466- end;
467- p := try Item.matchBegin(x);
468- Item.matchTag(p, constVal() mod 10, L);
469- lo := constVal() mod 10;
470- hi := constVal() mod 10 + 10;
471- Item.matchRange(p, lo, hi, L);
472- Item.matchRange(p, 3, 3, L);
473- Gen.fix(L);
474- return nil;
475-end;
476-
477-(* A for loop's variable stepped and tested *)
478-proc doFor(var x: Item.Item): ERROR;
479-var o: ^Sym.Obj; lim: Item.Item; step: I64; exitL: INT;
480-begin
481- o := vars[IntTypes[rnd(8)]];
482- step := constVal() mod 5;
483- if step = 0 then step := 1; end;
484- if rnd(2) = 0 then step := -step; end;
485- lim := {};
486- lim.pos := pos();
487- Item.makeConst(lim, o^.typ, constVal() mod 50);
488- exitL := Gen.NoLabel;
489- try Item.forStep(o, step);
490- try Item.forNext(o, lim, step, exitL, Chunk.pc, Chunk.pc);
491- Gen.fix(exitL);
492- x := lim;
493- return nil;
494-end;
495-
496-(* INC and DEC, pin, COPY *)
497-proc doMisc(var x: Item.Item): ERROR;
498-var y: Item.Item;
499-begin
500- match rnd(5) of
501- | 0:
502- try place(x);
503- try Item.address(x);
504- try operand(y, x.typ);
505- return Item.incDec(x, y, flag());
506- | 1:
507- try place(x);
508- return Item.pin(x);
509- | 2:
510- try place(x);
511- try Item.copyDest(x);
512- try place(y);
513- return Item.copyFrom(x, y);
514- | 3:
515- try operand(x, nil);
516- Item.makeStr(y);
517- return Item.coerce(y, ty[YBytes]);
518- | else:
519- try operand(x, nil);
520- Item.nilTest(x);
521- Item.usesReals(x.pos);
522- return Item.discard(x);
523- end;
524-end;
525-
526-(* A variant, a record's fields, an error's chunk, the message of one *)
527-proc doTemp(var x: Item.Item): ERROR;
528-var a: Item.Item; c, h, n: INT; f: ^Sym.Obj;
529-begin
530- x := {};
531- x.pos := pos();
532- match rnd(5) of
533- | 0: Item.zeroTemp(x, ty[YVariant]);
534- | 1:
535- Item.construct(x, caseObj);
536- f := caseObj^.fields;
537- try operand(a, f^.typ);
538- return Item.setField(x, f, a);
539- | 2:
540- Item.zeroTemp(x, ty[YRec]);
541- f := ty[YRec]^.fields;
542- if flag() then f := f^.next; end;
543- try operand(a, f^.typ);
544- return Item.setField(x, f, a);
545- | 3:
546- try operand(a, nil);
547- h := rnd(3) - 1;
548- n := rnd(3) - 1;
549- c := try Item.errorChunk(a, h, n);
550- Item.makeConst(x, Sym.tError, I64(c) + 1);
551- return nil;
552- | else:
553- try operand(x, ty[YErr]);
554- return Item.msg(x);
555- end;
556- return nil;
557-end;
558-
559-proc doReturn(var x: Item.Item): ERROR;
560-var f: ^Sym.Obj;
561-begin
562- if (curRes = 4) and flag() then
563- (* several results *)
564- f := tuple2^.fields;
565- if flag() then f := f^.next; end;
566- if flag() then
567- try operand(x, f^.typ);
568- return Item.returnField(f, x);
569- end;
570- try doCall(x);
571- return Item.returnAll(x);
572- end;
573- if rnd(4) = 0 then return Item.returnNone(); end;
574- try operand(x, results[curRes]);
575- return Item.returnValue(x);
576-end;
577-
578-(* One step of the script, whose item is x *)
579-proc step(k: INT; var x: Item.Item): ERROR;
580-var y: Item.Item;
581-begin
582- x := {};
583- match k of
584- | 0: try operand(x, nil); return Item.value(x);
585- | 1: try operand(x, nil); return Item.address(x);
586- | 2: try operand(x, nil); return Item.coerce(x, ty[rnd(NumT)]);
587- | 3: try operand(x, nil); return Item.coerceExact(x, intType(), "");
588- | 4:
589- try place(x);
590- try operand(y, x.typ);
591- return Item.assign(x, y);
592- | 5: return unary(x);
593- | 6: return binary(x);
594- | 7: try operand(x, nil); return Item.convert(x, ty[rnd(NumT)]);
595- | 8: return place(x);
596- | 9: return doCall(x);
597- | 10: return doMatch(x);
598- | 11: return doFor(x);
599- | 12: return doMisc(x);
600- | 13: return doTemp(x);
601- | 14: return doReturn(x);
602- | else: return binary(x);
603- end;
604-end;
605-
606-(* One procedure of Steps steps *)
607-proc genProc(c: INT);
608-var
609- sig: ^Sym.Type; i, k, line: INT; x: Item.Item; err: ERROR;
610-begin
611- curRes := rnd(9);
612- sig := procType(results[curRes], nil, 0);
613- Item.beginProc(sig, nil);
614- for i := 0 to 5 do _ := Gen.allocPerm(8, 8); end;
615- makeVars();
616- Item.setChecks(flag());
617- line := 1 + rnd(40);
618- Gen.enterBody(c, line);
619- for i := 1 to Steps do
620- if Diag.errors >= 19 then break; end; (* the 20th would end the run *)
621- k := rnd(17);
622- Item.setDemoted(false);
623- err := step(k, x);
624- if err # nil then
625- Fmt.print("S {} {} failed\n", [Fmt.int(c), Fmt.int(k)]);
626- else
627- Fmt.print("S {} {} ok\n", [Fmt.int(c), Fmt.int(k)]);
628- dump(x);
629- (* the items of these steps are as an operand is, on the stack *)
630- if (k < 4) or ((k >= 5) and (k <= 9)) then _ := Item.discard(x); end;
631- end;
632- Fmt.print("demoted {}\n", [Fmt.int(bit(Item.demoted))]);
633- Gen.resetStack(0, 0);
634- end;
635- _ := Gen.endProc(c, sig^.base # nil);
636-end;
637-
638-proc chunkNameOf(i: INT): INT;
639-var s: [3]U8;
640-begin
641- s[0] := 'p'; s[1] := U8(48 + i div 10); s[2] := U8(48 + i mod 10);
642- return Scan.intern(ADR(s[0]), 3);
643-end;
644-
645-proc main*;
646-var i, c: INT; path: []U8; arg: []U8;
647-begin
648- arg := Files.arg(1);
649- seed := 5;
650- for i := 0 to LEN(arg) - 1 do seed := seed * 10 + I64(arg[i]) - 48; end;
651- Letters := "abcdefgh\0";
652- path := "src/test/ItemDump.txt";
653- if LEN(Scan.open(path)) # 0 then Diag.fatal("no file"); end;
654- Scan.next; (* the string the file starts with *)
655- X.setListing(true);
656- Chunk.setCurFile(Scan.intern(ADR(path[0]), LEN(path)));
657- for i := 0 to NumProcs - 1 do c := Chunk.newChunk(Chunk.secText, -1, chunkNameOf(i)); Chunk.setLive(c); end;
658- for i := 0 to NumGlobs - 1 do
659- c := Chunk.newChunk(Chunk.secBss, -1, chunkNameOf(NumProcs + i));
660- Chunk.setBss(c, 64, 8);
661- end;
662- makeTypes();
663- makeObjs();
664- for i := 0 to NumProcs - 1 do genProc(FirstProc + i); end;
665- Fmt.print("pc {} fixups {} lines {} said {}\n", [Fmt.int(Chunk.pc),
666- Fmt.int(Chunk.numFixups), Fmt.int(Chunk.numLines), Fmt.int(X.saidCount())]);
667- for i := 0 to Chunk.pc - 1 do Out.hex(U64(Chunk.text[i]), 2); end;
668- Out.ln;
669- for i := 0 to Chunk.numFixups - 1 do
670- Fmt.print("F {} {} {}\n", [Fmt.int(Chunk.fixups[i].at), Fmt.int(Chunk.fixups[i].chunk), Fmt.int(Chunk.fixups[i].addend)]);
671- end;
672- for i := 0 to Chunk.numLines - 1 do
673- Fmt.print("L {} {} {} {}\n", [Fmt.int(Chunk.lines[i].at), Fmt.int(Chunk.lines[i].chunk),
674- Fmt.int(Chunk.lines[i].line), Fmt.int(Chunk.lines[i].col)]);
675- end;
676- X.list(-1);
677-end;
678-
679-end ItemDump.

src/test/ItemDump.txt deleted +0 -41

@@ -1,41 +0,0 @@
1-"item test"
2- x value sum alpha beta;
3- next beta items len alpha next count alpha beta;
4- value beta count beta next value;
5- len beta count;
6- sum len alpha len len value alpha count;
7- next x n;
8- x next beta len n next;
9- sum x beta len len sum count items beta;
10- tmp beta len alpha len count p;
11- next value items p len p items n;
12- x tmp count beta;
13- n next p items tmp p n;
14- beta beta next value x items x;
15- value alpha sum beta next len;
16- items items tmp items len p len p beta;
17- beta n p tmp sum beta alpha tmp tmp;
18- sum len sum p n;
19- value sum items alpha p items x len;
20- p alpha count;
21- n x tmp count value value p beta x;
22- value next n x value next;
23- tmp value items sum value;
24- x beta x x;
25- sum count alpha p;
26- len x n n alpha x value next items;
27- len items x tmp next len sum;
28- tmp alpha p sum next value value value;
29- beta p sum value alpha count;
30- count p x;
31- items len alpha;
32- alpha len x;
33- beta items len alpha beta count len;
34- x sum n items len items;
35- beta beta p p p p;
36- beta x beta tmp items;
37- n p tmp x next alpha count next;
38- x tmp next alpha next;
39- sum beta tmp n next;
40- x items count next next;
41- next items sum count len count count value tmp;

src/test/LinkDump.pas deleted +0 -91

@@ -1,91 +0,0 @@
1-{ Makes a program of chunks by a fixed pseudo-random script, links it and
2- writes it as an executable to the file of the second argument, in the
3- way the first says (0 static, 1 dynamic, 2 stripped): the seed's side
4- of a test of src/Link.raz and src/Elf.raz, whose LinkDump.raz does
5- the same and writes the same file. }
6-program linkdump;
7-{$mode objfpc}{$H-}
8-uses diag, scan, seedcontinue, chunk, link, elf;
9-const NumC = 200;
10-var
11- seed: int64;
12- names: array[0..7] of longint;
13- i, j, k, kind, n, x, y, z, mode: longint;
14- b: array[0..63] of byte;
15-
16-function Rnd(n: longint): longint;
17-begin
18- seed := (seed * 1103515245 + 12345) and $7FFFFFFF;
19- Rnd := (seed shr 8) mod n;
20-end;
21-
22-var c, e, line, col: longint;
23-begin
24- seed := 5;
25- mode := ord(ParamStr(1)[1]) - 48;
26- for i := 0 to 7 do begin b[0] := 97 + i; names[i] := Intern(@b[0], 1) end;
27- placesChunk := NewChunk(secRodata, -1, -1);
28- SetData(placesChunk, @b[0], 0, 8);
29- for i := 0 to NumC - 1 do begin
30- if i = 0 then kind := 0 else kind := Rnd(10);
31- x := Rnd(4); y := Rnd(8);
32- case kind of
33- 0..5: begin
34- c := NewChunk(secText, x - 1, y);
35- BeginChunk(c);
36- z := Rnd(3); curFile := names[z];
37- line := Rnd(300); col := Rnd(60);
38- NoteLine(line, col);
39- if i = 0 then begin AddFixup(pc, placesChunk, 0); Put4(0) end;
40- n := 2 + Rnd(10);
41- for j := 1 to n do begin
42- z := Rnd(5);
43- if z <= 1 then begin
44- e := Rnd(NumC); y := Rnd(8);
45- AddFixup(pc, e, y);
46- Put4(0);
47- end else if z = 2 then begin
48- z := Rnd(3); curFile := names[z];
49- line := Rnd(300); col := Rnd(60);
50- NoteLine(line, col);
51- end else begin x := Rnd(1 shl 30); Put4(x); x := Rnd(256); Put1(x) end;
52- end;
53- EndChunk(c);
54- n := Rnd(3);
55- for j := 1 to n do begin
56- x := Rnd(8); y := Rnd(200); z := Rnd(6);
57- NoteVar(c, names[x], y - 100, z);
58- end;
59- end;
60- 6, 7: begin
61- c := NewChunk(secRodata, x - 1, y);
62- n := 8 * (1 + Rnd(4));
63- for j := 0 to n - 1 do b[j] := Rnd(256);
64- SetData(c, @b[0], n, 8);
65- for j := 0 to n div 8 - 1 do begin
66- z := Rnd(2);
67- if z = 0 then begin e := Rnd(NumC); y := Rnd(8); AddDataFixup(c, j * 8, e, y) end;
68- end;
69- end;
70- 8: begin
71- c := NewChunk(secBss, x - 1, y);
72- z := Rnd(200); e := Rnd(4);
73- SetBss(c, 1 + z, 1 shl e);
74- end;
75- 9: begin z := Rnd(8); c := ExternChunk(names[z]) end;
76- end;
77- end;
78- { every chunk a fixup names must exist, and be defined if it is reached }
79- while numChunks < NumC do begin c := NewChunk(secBss, -1, -1); SetBss(c, 8, 8) end;
80- for i := 0 to numChunks - 1 do
81- if chunks^[i].size < 0 then SetBss(i, 8, 8);
82- mainPath := 'some/main.raz';
83- if mode = 1 then begin
84- numNeeded := 2;
85- needed[0] := names[0]; needed[1] := names[1];
86- end;
87- stripped := mode = 2;
88- if mode = 2 then placesChunk := -1;
89- MarkLive(1);
90- WriteElf(ParamStr(2), 1);
91-end.

src/test/LinkDump.raz deleted +0 -103

@@ -1,103 +0,0 @@
1-(* Makes a program of chunks by a fixed pseudo-random script, links it
2- and writes it as an executable to the file of the second argument,
3- in the way the first says (0 static, 1 dynamic, 2 stripped):
4- src/Link.raz's and src/Elf.raz's side of a test against the seed's,
5- LinkDump.pas, which writes the same file. *)
6-module LinkDump;
7-import Files, Diag, Scan, Chunk, Link, Elf;
8-
9-const NumC = 200;
10-
11-var seed: I64;
12-
13-proc rnd(n: INT): INT;
14-begin
15- seed := (seed * 1103515245 + 12345) & 7FFFFFFFH;
16- return INT((seed shr 8) mod I64(n));
17-end;
18-
19-(* a library that must be taken *)
20-proc ok(taken: BOOL);
21-begin
22- if not taken then Diag.fatal("too many libraries"); end;
23-end;
24-
25-proc main*;
26-var
27- names: [8]INT; b: [64]U8; arg: []U8;
28- i, j, kind, n, x, y, z, c, e, line, col, mode: INT;
29-begin
30- seed := 5;
31- arg := Files.arg(1);
32- mode := INT(arg[0]) - 48;
33- for i := 0 to 7 do b[0] := U8(97 + i); names[i] := Scan.intern(ADR(b[0]), 1); end;
34- Link.setPlaces(Chunk.newChunk(Chunk.secRodata, -1, -1));
35- Chunk.setData(Link.placesChunk, ADR(b[0]), 0, 8);
36- for i := 0 to NumC - 1 do
37- if i = 0 then kind := 0; else kind := rnd(10); end;
38- x := rnd(4); y := rnd(8);
39- match kind of
40- | 0..5:
41- c := Chunk.newChunk(Chunk.secText, x - 1, y);
42- Chunk.beginChunk(c);
43- z := rnd(3); Chunk.setCurFile(names[z]);
44- line := rnd(300); col := rnd(60);
45- Chunk.noteLine(line, col);
46- if i = 0 then Chunk.addFixup(Chunk.pc, Link.placesChunk, 0); Chunk.put4(0); end;
47- n := 2 + rnd(10);
48- for j := 1 to n do
49- z := rnd(5);
50- if z <= 1 then
51- e := rnd(NumC); y := rnd(8);
52- Chunk.addFixup(Chunk.pc, e, y);
53- Chunk.put4(0);
54- elsif z = 2 then
55- z := rnd(3); Chunk.setCurFile(names[z]);
56- line := rnd(300); col := rnd(60);
57- Chunk.noteLine(line, col);
58- else
59- x := rnd(1 shl 30); Chunk.put4(x); x := rnd(256); Chunk.put1(x);
60- end;
61- end;
62- Chunk.endChunk(c);
63- n := rnd(3);
64- for j := 1 to n do
65- x := rnd(8); y := rnd(200); z := rnd(6);
66- Chunk.noteVar(c, names[x], y - 100, z);
67- end;
68- | 6, 7:
69- c := Chunk.newChunk(Chunk.secRodata, x - 1, y);
70- n := 8 * (1 + rnd(4));
71- for j := 0 to n - 1 do b[j] := U8(rnd(256)); end;
72- Chunk.setData(c, ADR(b[0]), n, 8);
73- for j := 0 to n div 8 - 1 do
74- z := rnd(2);
75- if z = 0 then e := rnd(NumC); y := rnd(8); Chunk.addDataFixup(c, j * 8, e, y); end;
76- end;
77- | 8:
78- c := Chunk.newChunk(Chunk.secBss, x - 1, y);
79- z := rnd(200); e := rnd(4);
80- Chunk.setBss(c, 1 + z, 1 shl e);
81- | else: z := rnd(8); c := Chunk.externChunk(names[z]);
82- end;
83- end;
84- (* every chunk a fixup names must exist, and be defined if it is reached *)
85- while Chunk.numChunks < NumC do
86- c := Chunk.newChunk(Chunk.secBss, -1, -1);
87- Chunk.setBss(c, 8, 8);
88- end;
89- for i := 0 to Chunk.numChunks - 1 do
90- if Chunk.chunks[i].size < 0 then Chunk.setBss(i, 8, 8); end;
91- end;
92- Elf.setMainPath("some/main.raz");
93- if mode = 1 then
94- ok(Elf.needLib(names[0]));
95- ok(Elf.needLib(names[1]));
96- end;
97- Elf.setStripped(mode = 2);
98- if mode = 2 then Link.setPlaces(-1); end;
99- Link.markLive(1);
100- Elf.writeElf(Files.arg(2), 1);
101-end;
102-
103-end LinkDump.

src/test/ScanBench.pas modified +1 -1

@@ -2,7 +2,7 @@
22 against src/Scan.raz (ScanBench.raz). }
33 program scanbench;
44 {$mode objfpc}{$H-}
5-uses diag, scan, seedcontinue;
5+uses diag, scan;
66 var n: longint;
77 begin
88 if Open(ParamStr(1)) <> '' then Fatal('no file');

src/test/ScanDump.pas deleted +0 -21

@@ -1,21 +0,0 @@
1-{ Prints the symbols of a file, one per line: the seed's side of a test
2- of src/Scan.raz, which prints the same. A real is shown by its bits,
3- so that no formatting library decides what is the same. }
4-program scandump;
5-{$mode objfpc}{$H-}
6-uses diag, scan, seedcontinue;
7-var i: longint; bits: int64;
8-begin
9- if Open(ParamStr(1)) <> '' then Fatal('no file');
10- repeat
11- Next;
12- write(LineOf(TokPos), ':', TokPos.a, ':', TokPos.b, ' ', CurLine, ':', CurCol, ' ', ord(tok));
13- case tok of
14- sIdent: write(' ', NameOf(id), ' ', id);
15- sInt, sChar: write(' ', ival);
16- sReal: begin Move(rval, bits, 8); write(' ', HexStr(bits, 16)) end;
17- sString: begin write(' "'); for i := 0 to slen - 1 do write(sbuf[i], ','); write('"') end;
18- end;
19- writeln;
20- until tok = sEof;
21-end.

src/test/ScanDump.raz deleted +0 -45

@@ -1,45 +0,0 @@
1-(* Prints the symbols of a file, one per line: src/Scan.raz's side of a
2- test against the seed's, ScanDump.pas, which prints the same. The
3- symbols are numbered as the seed numbers them: it has no continue
4- (report 2026-10.31), the last reserved word here, so its end of the
5- file is one lower. A file with continue in it isn't compared. *)
6-module ScanDump;
7-import Out, Fmt, Files, Diag, Scan;
8-
9-(* s as the seed numbers it *)
10-proc seedSym(s: Scan.Sym): INT;
11-begin
12- if s = Scan.sEof then return INT(s) - 1; end;
13- return INT(s);
14-end;
15-
16-proc main*;
17-var p: Diag.Pos; bits: ^U64; i: INT; str: []U8; r: F64;
18-begin
19- if LEN(Scan.open(Files.arg(1))) # 0 then Diag.fatal("no file"); end;
20- repeat
21- Scan.next;
22- p := Scan.tokPos();
23- Fmt.print("{}:{}:{} {}:{} {}", [Fmt.int(Diag.lineOf(p)), Fmt.int(p.a), Fmt.int(p.b),
24- Fmt.int(Scan.curLine()), Fmt.int(Scan.curCol()), Fmt.int(seedSym(Scan.tok))]);
25- match Scan.tok of
26- | sIdent: Fmt.print(" {} {}", [Fmt.str(Scan.nameOf(Scan.id)), Fmt.int(Scan.id)]);
27- | sInt: Fmt.print(" {}", [Fmt.int(Scan.ival)]);
28- | sChar: Fmt.print(" {}", [Fmt.int(Scan.ival)]);
29- | sReal:
30- r := Scan.rval;
31- bits := ^U64(ADR(r));
32- Out.str(" ");
33- Out.hex(bits^, 16);
34- | sString:
35- Out.str(" \"");
36- str := Scan.strBytes();
37- for i := 0 to LEN(str) - 1 do Fmt.print("{},", [Fmt.int(INT(str[i]))]); end;
38- Out.str("\"");
39- | else:
40- end;
41- Out.ln;
42- until Scan.tok = Scan.sEof;
43-end;
44-
45-end ScanDump.

src/test/SymDump.pas deleted +0 -185

@@ -1,185 +0,0 @@
1-{ Builds types and objects by a fixed pseudo-random script, asks of them
2- what the parser asks of sym, and prints the answers: the seed's side
3- of a test of src/Sym.raz, whose SymDump.raz does the same and prints
4- the same. With the argument dup or deep it ends in the error of a name
5- declared twice, or of too many scopes. }
6-program symdump;
7-{$mode objfpc}{$H-}
8-uses diag, scan, seedcontinue, sym;
9-const
10- Words: array[0..19] of string = ('alpha', 'alpho', 'beta', 'bet', 'gamma', 'gama', 'delta', 'Delta',
11- 'eps', 'zeta', 'eta', 'theta', 'iota', 'kappa', 'lambda', 'mu', 'nu', 'xi', 'omicron', 'pi');
12-var
13- seed: int64;
14- names: array[0..19] of longint;
15- mods: array[0..2] of PModule;
16- base: array[0..11] of PType;
17- pool: array[0..299] of PType;
18- objs: array[0..299] of PObj;
19- numPool, numObjs, i, k, n, op, x, y, z: longint;
20- t, o2: PType;
21- o: PObj;
22- saved: array[0..MaxDepth - 1] of longint;
23- d: longint;
24- v: int64;
25-
26-function Rnd(n: longint): longint;
27-begin
28- seed := (seed * 1103515245 + 12345) and $7FFFFFFF;
29- Rnd := (seed shr 8) mod n;
30-end;
31-
32-function Fields(m: longint; allowVar: boolean): PObj;
33-var f, first, last: PObj; j, x, y, z: longint;
34-begin
35- first := nil; last := nil;
36- for j := 1 to m do begin
37- x := Rnd(20); y := Rnd(numPool);
38- f := NewObj(oField, names[x], pool[y]);
39- z := Rnd(2); f^.exported := z = 0;
40- z := Rnd(3); f^.isVar := allowVar and (z = 0);
41- f^.val := j * 8;
42- if first = nil then first := f else last^.next := f;
43- last := f;
44- end;
45- Fields := first;
46-end;
47-
48-procedure Add(t: PType);
49-begin
50- if numPool <= High(pool) then begin pool[numPool] := t; inc(numPool) end;
51-end;
52-
53-procedure MakeType;
54-var t: PType; r, m, x: longint; f: PObj;
55-begin
56- r := Rnd(11);
57- case r of
58- 0: t := NewType(fPtr, 8, 8);
59- 1: t := NewType(fArray, 0, 1);
60- 2: t := NewType(fSlice, 16, 8);
61- 3: t := NewType(fRecord, 0, 8);
62- 4: t := NewType(fProc, 8, 8);
63- 5: t := NewType(fSet, 8, 8);
64- 6: t := NewType(fVariant, 16, 8);
65- 7: t := NewType(fEnum, 1, 1);
66- 8: t := NewType(fRecord, 16, 8);
67- 9: t := NewType(fProc, 8, 8);
68- else t := NewType(fPtr, 8, 8);
69- end;
70- x := Rnd(numPool); t^.base := pool[x];
71- t^.len := Rnd(5);
72- x := Rnd(4); t^.vol := x = 0;
73- x := Rnd(4); t^.variadic := (t^.form = fProc) and (x = 0);
74- x := Rnd(2); t^.tuple := (t^.form = fRecord) and (x = 0);
75- if t^.form in [fRecord, fProc, fVariant] then begin
76- m := Rnd(4);
77- t^.fields := Fields(m, t^.form = fProc);
78- t^.len := m;
79- if t^.form = fRecord then t^.base := nil;
80- x := Rnd(2);
81- if (t^.form = fProc) and (x = 0) then t^.base := nil;
82- if t^.form = fVariant then begin
83- f := t^.fields;
84- while f <> nil do begin f^.cls := oCase; x := Rnd(3); f^.fields := Fields(x, false); f := f^.next end;
85- end;
86- end;
87- x := Rnd(3);
88- if x = 0 then begin
89- x := Rnd(20); t^.obj := NewObj(oType, names[x], t);
90- x := Rnd(3); t^.obj^.module := mods[x];
91- end;
92- Add(t);
93-end;
94-
95-begin
96- seed := 11;
97- for i := 0 to 19 do names[i] := Intern(@Words[i][1], length(Words[i]));
98- for i := 0 to 2 do begin
99- New(mods[i]); FillChar(mods[i]^, SizeOf(TModule), 0);
100- mods[i]^.sname := names[i * 5];
101- end;
102- curModule := mods[0];
103- base[0] := tI8; base[1] := tI16; base[2] := tI32; base[3] := tI64; base[4] := tU8;
104- base[5] := tU16; base[6] := tU32; base[7] := tU64; base[8] := tBool; base[9] := tF32;
105- base[10] := tReal; base[11] := tInt;
106- for i := 0 to 11 do Add(base[i]);
107- if ParamCount >= 1 then begin if Open('lib/Rt.raz') <> '' then Fatal('no file'); Next; Next end;
108- numObjs := 0;
109- for k := 1 to 4000 do begin
110- op := Rnd(14);
111- case op of
112- 0, 1, 2: MakeType;
113- 3, 4: if numObjs <= High(objs) then begin
114- x := Rnd(8); y := Rnd(20);
115- if Find(x, names[y]) = nil then begin
116- z := Rnd(8); n := Rnd(numPool);
117- o := NewObj(TClass(z), names[y], pool[n]);
118- z := Rnd(2); o^.exported := z = 0;
119- z := Rnd(3); o^.module := mods[z];
120- Insert(o, x);
121- objs[numObjs] := o; inc(numObjs);
122- writeln('I ', x, ' ', NameOf(names[y]), ' ', o^.scope);
123- end;
124- end;
125- 5: begin x := Rnd(8); y := Rnd(20); o := Find(x, names[y]);
126- write('F ', x, ' ', NameOf(names[y]), ' ');
127- if o = nil then writeln('-') else writeln(ord(o^.cls), ' ', o^.scope);
128- end;
129- 6: begin
130- x := Rnd(8); y := Rnd(20);
131- if ScopeDepth < 6 then OpenScope(x);
132- o := Lookup(names[y]);
133- write('L ', ScopeDepth, ' ', NameOf(names[y]), ' ');
134- if o = nil then writeln('-') else writeln(ord(o^.cls), ' ', o^.scope);
135- z := Rnd(2);
136- if (ScopeDepth > 1) and (z = 0) then CloseScope;
137- end;
138- 7: begin
139- y := Rnd(20); x := Rnd(9) - 1; z := Rnd(3); curModule := mods[z];
140- o := Closest(names[y], x);
141- write('C ', NameOf(names[y]), ' ', x, ' ');
142- if o = nil then writeln('-') else writeln(NameOf(o^.name), ' ', o^.scope);
143- end;
144- 8: begin
145- x := Rnd(numPool); z := Rnd(3); curModule := mods[z];
146- writeln('T ', TypeName(pool[x]));
147- end;
148- 9: begin
149- x := Rnd(numPool); y := Rnd(numPool);
150- writeln('S ', ord(Same(pool[x], pool[y])), ' ', ord(Same(pool[x], pool[x])));
151- t := NewType(fPtr, 8, 8); t^.base := pool[x];
152- o2 := t; t := NewType(fPtr, 8, 8); t^.base := pool[x];
153- writeln('S ', ord(Same(o2, t)));
154- end;
155- 10: if numObjs > 0 then begin x := Rnd(numObjs); writeln('P ', HexStr(Fingerprint(objs[x]), 16)) end;
156- 11: begin
157- x := Rnd(numPool); y := Rnd(1 shl 20); z := Rnd(2); n := Rnd(2);
158- v := int64(y) * 4096 * z - y * n;
159- t := pool[x];
160- writeln('B ', ord(Fits(v, t)), ' ', ord(IsInt(t)), ' ', ord(IsScalar(t)), ' ', ord(IsAggregate(t)), ' ',
161- ord(InTwoRegs(t)), ' ', ord(BehindPointer(t)), ' ', AlignUp(y, 1 shl z));
162- end;
163- 12: if (ScopeDepth > 1) and (ScopeDepth < 6) then begin
164- d := ScopeDepth; SaveScopes(d, saved);
165- writeln('V ', ScopeDepth, ' ', TopScope);
166- RestoreScopes(d, saved);
167- writeln('V ', ScopeDepth, ' ', TopScope);
168- x := NewScope; writeln('N ', x);
169- end;
170- 13: begin x := ScopeDepth; if x > 3 then CutScopes(2); writeln('X ', x, ' ', ScopeDepth) end;
171- end;
172- end;
173- { the universe, and the sizes it made }
174- for i := 0 to 11 do writeln('U ', ord(base[i]^.form), ' ', base[i]^.size, ' ', ord(base[i]^.signed), ' ', NameOf(base[i]^.obj^.name));
175- if ParamCount >= 1 then begin
176- if ParamStr(1) = 'dup' then begin
177- o := NewObj(oVar, names[3], tI8);
178- Insert(o, 100); Insert(o, 100);
179- end;
180- if ParamStr(1) = 'deep' then begin
181- CutScopes(1);
182- for i := 1 to MaxDepth + 1 do OpenScope(i);
183- end;
184- end;
185-end.

src/test/SymDump.raz deleted +0 -225

@@ -1,225 +0,0 @@
1-(* Builds types and objects by a fixed pseudo-random script, asks of them
2- what the parser asks of Sym, and prints the answers: src/Sym.raz's
3- side of a test against the seed's, SymDump.pas, which prints the same.
4- With the argument dup or deep it ends in the error of a name declared
5- twice, or of too many scopes. *)
6-module SymDump;
7-import Out, Fmt, Files, Heap, Diag, Scan, Sym;
8-
9-const
10- Words: [20][]U8 = ["alpha", "alpho", "beta", "bet", "gamma", "gama", "delta", "Delta",
11- "eps", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "omicron", "pi"];
12-
13-var
14- seed: I64;
15- names: [20]INT;
16- mods: [3]^Sym.Module;
17- base: [12]^Sym.Type;
18- pool: [300]^Sym.Type;
19- objs: [300]^Sym.Obj;
20- classes: [8]Sym.Class;
21- numPool, numObjs: INT;
22-
23-proc rnd(n: INT): INT;
24-begin
25- seed := (seed * 1103515245 + 12345) & 7FFFFFFFH;
26- return INT((seed shr 8) mod I64(n));
27-end;
28-
29-proc bit(f: BOOL): INT;
30-begin
31- if f then return 1; end;
32- return 0;
33-end;
34-
35-proc nm(i: INT): []U8;
36-begin
37- return Scan.nameOf(names[i]);
38-end;
39-
40-(* The result of a call that must succeed *)
41-proc ok(e: ERROR);
42-begin
43- if e # nil then Diag.finish; end;
44-end;
45-
46-proc fields(m: INT; allowVar: BOOL): ^Sym.Obj;
47-var f, first, last: ^Sym.Obj; j, x, y, z: INT;
48-begin
49- first := nil; last := nil;
50- for j := 1 to m do
51- x := rnd(20); y := rnd(numPool);
52- f := Sym.newObj(Sym.oField, names[x], pool[y]);
53- z := rnd(2); f^.exported := z = 0;
54- z := rnd(3); f^.isVar := allowVar and (z = 0);
55- f^.val := j * 8;
56- if first = nil then first := f; else last^.next := f; end;
57- last := f;
58- end;
59- return first;
60-end;
61-
62-proc add(t: ^Sym.Type);
63-begin
64- if numPool < 300 then pool[numPool] := t; INC(numPool); end;
65-end;
66-
67-proc makeType;
68-var t: ^Sym.Type; r, m, x: INT; f: ^Sym.Obj;
69-begin
70- r := rnd(11);
71- match r of
72- | 0: t := Sym.newType(Sym.fPtr, 8, 8);
73- | 1: t := Sym.newType(Sym.fArray, 0, 1);
74- | 2: t := Sym.newType(Sym.fSlice, 16, 8);
75- | 3: t := Sym.newType(Sym.fRecord, 0, 8);
76- | 4: t := Sym.newType(Sym.fProc, 8, 8);
77- | 5: t := Sym.newType(Sym.fSet, 8, 8);
78- | 6: t := Sym.newType(Sym.fVariant, 16, 8);
79- | 7: t := Sym.newType(Sym.fEnum, 1, 1);
80- | 8: t := Sym.newType(Sym.fRecord, 16, 8);
81- | 9: t := Sym.newType(Sym.fProc, 8, 8);
82- | else: t := Sym.newType(Sym.fPtr, 8, 8);
83- end;
84- x := rnd(numPool); t^.base := pool[x];
85- t^.len := rnd(5);
86- x := rnd(4); t^.vol := x = 0;
87- x := rnd(4); t^.variadic := (t^.form = Sym.fProc) and (x = 0);
88- x := rnd(2); t^.tuple := (t^.form = Sym.fRecord) and (x = 0);
89- if (t^.form = Sym.fRecord) or (t^.form = Sym.fProc) or (t^.form = Sym.fVariant) then
90- m := rnd(4);
91- t^.fields := fields(m, t^.form = Sym.fProc);
92- t^.len := m;
93- if t^.form = Sym.fRecord then t^.base := nil; end;
94- x := rnd(2);
95- if (t^.form = Sym.fProc) and (x = 0) then t^.base := nil; end;
96- if t^.form = Sym.fVariant then
97- f := t^.fields;
98- while f # nil do
99- f^.cls := Sym.oCase;
100- x := rnd(3); f^.fields := fields(x, false);
101- f := f^.next;
102- end;
103- end;
104- end;
105- x := rnd(3);
106- if x = 0 then
107- x := rnd(20); t^.obj := Sym.newObj(Sym.oType, names[x], t);
108- x := rnd(3); t^.obj^.home := mods[x];
109- end;
110- add(t);
111-end;
112-
113-proc main*;
114-var
115- i, k, op, x, y, z, n, d: INT; t, o2: ^Sym.Type; o: ^Sym.Obj; v: I64;
116- saved: [Sym.MaxDepth]INT; arg: []U8;
117-begin
118- seed := 11;
119- classes := [Sym.oConst, Sym.oType, Sym.oVar, Sym.oProc, Sym.oModule, Sym.oField, Sym.oCase, Sym.oBuiltin];
120- for i := 0 to 19 do names[i] := Scan.intern(ADR(Words[i][0]), LEN(Words[i])); end;
121- for i := 0 to 2 do
122- NEW(mods[i], Heap.heap);
123- mods[i]^.sname := names[i * 5];
124- end;
125- Sym.setCurModule(mods[0]);
126- base[0] := Sym.tI8; base[1] := Sym.tI16; base[2] := Sym.tI32; base[3] := Sym.tI64; base[4] := Sym.tU8;
127- base[5] := Sym.tU16; base[6] := Sym.tU32; base[7] := Sym.tU64; base[8] := Sym.tBool; base[9] := Sym.tF32;
128- base[10] := Sym.tReal; base[11] := Sym.tInt;
129- for i := 0 to 11 do add(base[i]); end;
130- arg := "";
131- if ARGC > 1 then arg := Files.arg(1); end;
132- if LEN(arg) > 0 then
133- if LEN(Scan.open("lib/Rt.raz")) # 0 then Diag.fatal("no file"); end;
134- Scan.next; Scan.next;
135- end;
136- numObjs := 0;
137- for k := 1 to 4000 do
138- op := rnd(14);
139- match op of
140- | 0, 1, 2: makeType;
141- | 3, 4:
142- if numObjs < 300 then
143- x := rnd(8); y := rnd(20);
144- if Sym.find(x, names[y]) = nil then
145- z := rnd(8); n := rnd(numPool);
146- o := Sym.newObj(classes[z], names[y], pool[n]);
147- z := rnd(2); o^.exported := z = 0;
148- z := rnd(3); o^.home := mods[z];
149- ok(Sym.insert(o, x));
150- objs[numObjs] := o; INC(numObjs);
151- Fmt.print("I {} {} {}\n", [Fmt.int(x), Fmt.str(nm(y)), Fmt.int(o^.scope)]);
152- end;
153- end;
154- | 5:
155- x := rnd(8); y := rnd(20); o := Sym.find(x, names[y]);
156- Fmt.print("F {} {} ", [Fmt.int(x), Fmt.str(nm(y))]);
157- if o = nil then Out.str("-\n");
158- else Fmt.print("{} {}\n", [Fmt.int(INT(o^.cls)), Fmt.int(o^.scope)]); end;
159- | 6:
160- x := rnd(8); y := rnd(20);
161- if Sym.scopeDepth() < 6 then ok(Sym.openScope(x)); end;
162- o := Sym.lookup(names[y]);
163- Fmt.print("L {} {} ", [Fmt.int(Sym.scopeDepth()), Fmt.str(nm(y))]);
164- if o = nil then Out.str("-\n");
165- else Fmt.print("{} {}\n", [Fmt.int(INT(o^.cls)), Fmt.int(o^.scope)]); end;
166- z := rnd(2);
167- if (Sym.scopeDepth() > 1) and (z = 0) then Sym.closeScope; end;
168- | 7:
169- y := rnd(20); x := rnd(9) - 1; z := rnd(3); Sym.setCurModule(mods[z]);
170- o := Sym.closest(names[y], x);
171- Fmt.print("C {} {} ", [Fmt.str(nm(y)), Fmt.int(x)]);
172- if o = nil then Out.str("-\n");
173- else Fmt.print("{} {}\n", [Fmt.str(Scan.nameOf(o^.name)), Fmt.int(o^.scope)]); end;
174- | 8:
175- x := rnd(numPool); z := rnd(3); Sym.setCurModule(mods[z]);
176- Fmt.print("T {}\n", [Fmt.str(Sym.typeName(pool[x]))]);
177- | 9:
178- x := rnd(numPool); y := rnd(numPool);
179- Fmt.print("S {} {}\n", [Fmt.int(bit(Sym.same(pool[x], pool[y]))), Fmt.int(bit(Sym.same(pool[x], pool[x])))]);
180- t := Sym.newType(Sym.fPtr, 8, 8); t^.base := pool[x];
181- o2 := t; t := Sym.newType(Sym.fPtr, 8, 8); t^.base := pool[x];
182- Fmt.print("S {}\n", [Fmt.int(bit(Sym.same(o2, t)))]);
183- | 10:
184- if numObjs > 0 then
185- x := rnd(numObjs);
186- Out.str("P "); Out.hex(Sym.fingerprint(objs[x]), 16); Out.ln;
187- end;
188- | 11:
189- x := rnd(numPool); y := rnd(1 shl 20); z := rnd(2); n := rnd(2);
190- v := I64(y) * 4096 * I64(z) - I64(y) * I64(n);
191- t := pool[x];
192- Fmt.print("B {} {} {} {} {} {} {}\n", [Fmt.int(bit(Sym.fits(v, t))), Fmt.int(bit(Sym.isInt(t))),
193- Fmt.int(bit(Sym.isScalar(t))), Fmt.int(bit(Sym.isAggregate(t))), Fmt.int(bit(Sym.inTwoRegs(t))),
194- Fmt.int(bit(Sym.behindPointer(t))), Fmt.int(Sym.alignUp(y, 1 shl z))]);
195- | 12:
196- if (Sym.scopeDepth() > 1) and (Sym.scopeDepth() < 6) then
197- d := Sym.saveScopes(saved);
198- Fmt.print("V {} {}\n", [Fmt.int(Sym.scopeDepth()), Fmt.int(Sym.topScope())]);
199- Sym.restoreScopes(d, saved);
200- Fmt.print("V {} {}\n", [Fmt.int(Sym.scopeDepth()), Fmt.int(Sym.topScope())]);
201- x := Sym.newScope();
202- Fmt.print("N {}\n", [Fmt.int(x)]);
203- end;
204- | else:
205- x := Sym.scopeDepth();
206- if x > 3 then Sym.cutScopes(2); end;
207- Fmt.print("X {} {}\n", [Fmt.int(x), Fmt.int(Sym.scopeDepth())]);
208- end;
209- end;
210- for i := 0 to 11 do
211- Fmt.print("U {} {} {} {}\n", [Fmt.int(INT(base[i]^.form)), Fmt.int(base[i]^.size),
212- Fmt.int(bit(base[i]^.signed)), Fmt.str(Scan.nameOf(base[i]^.obj^.name))]);
213- end;
214- if arg = "dup" then
215- o := Sym.newObj(Sym.oVar, names[3], Sym.tI8);
216- ok(Sym.insert(o, 100));
217- ok(Sym.insert(o, 100));
218- end;
219- if arg = "deep" then
220- Sym.cutScopes(1);
221- for i := 1 to Sym.MaxDepth + 1 do ok(Sym.openScope(i)); end;
222- end;
223-end;
224-
225-end SymDump.

src/test/X64Dump.pas deleted +0 -160

@@ -1,160 +0,0 @@
1-{ Writes every instruction the encoder makes, with operands drawn by a
2- fixed pseudo-random script, then prints the bytes, the fixups and the
3- listing (raz -S) of what it made: the seed's side of a test of
4- src/X64.raz, whose X64Dump.raz does the same and prints the same. }
5-program x64dump;
6-{$mode objfpc}{$H-}
7-uses diag, scan, seedcontinue, chunk, x64;
8-var
9- seed: int64;
10- i, k, op, a, b, c, d, lab1, lab2: longint;
11- m: TMem;
12- path: string;
13-
14-function Rnd(n: longint): longint;
15-begin
16- seed := (seed * 1103515245 + 12345) and $7FFFFFFF;
17- Rnd := (seed shr 8) mod n;
18-end;
19-
20-{ a register, with the stack and base pointers and the high ones often enough }
21-function Reg: longint;
22-begin
23- Reg := Rnd(16);
24-end;
25-
26-{ a size of 1, 2, 4 or 8 bytes }
27-function Size: longint;
28-begin
29- Size := 1 shl Rnd(4);
30-end;
31-
32-{ a value that fits size bytes, of 8 as 32 bits }
33-function Imm(sz: longint): longint;
34-var x: longint;
35-begin
36- x := Rnd(1 shl 30);
37- case Rnd(3) of
38- 0: Imm := x mod 100 - 50;
39- 1: Imm := x - (1 shl 29);
40- else Imm := x mod 20000 - 10000;
41- end;
42- if sz = 1 then Imm := Imm mod 128
43- else if sz = 2 then Imm := Imm mod 32768;
44-end;
45-
46-function RandMem: TMem;
47-var kind, base, idx, sc, disp, x: longint;
48-begin
49- kind := Rnd(6);
50- base := Reg; idx := Reg; sc := 1 shl Rnd(4); x := Rnd(5);
51- case x of
52- 0: disp := 0;
53- 1: disp := Rnd(250) - 125;
54- 2: disp := Rnd(1 shl 20) - (1 shl 19);
55- 3: disp := 127 + Rnd(3) - 1;
56- else disp := -128 + Rnd(3) - 1;
57- end;
58- case kind of
59- 0, 1: RandMem := Mem(base, disp);
60- 2: RandMem := MemRip(Rnd(5), disp);
61- 3, 4: RandMem := MemIdx(base, idx, sc, disp);
62- else RandMem := Mem(base, 0);
63- end;
64-end;
65-
66-begin
67- seed := 3;
68- path := 'lib/Rt.raz';
69- if Open(path) <> '' then Fatal('no file');
70- listing := true;
71- for i := 0 to 4 do NewChunk(secText, i - 1, i);
72- curFile := Intern(@path[1], length(path));
73- BeginChunk(0);
74- lab1 := NoLabel; lab2 := NoLabel;
75- for k := 1 to 3000 do begin
76- if k mod 7 = 0 then begin a := Rnd(300); b := Rnd(60); NoteLine(1 + a, b) end;
77- op := Rnd(50);
78- case op of
79- 0: begin a := Reg; b := Reg; MovRR(a, b) end;
80- 1: begin
81- a := Reg; b := Rnd(6); c := Rnd(1 shl 30);
82- case b of
83- 0: MovRI(a, 0);
84- 1: MovRI(a, c);
85- 2: MovRI(a, -c);
86- 3: MovRI(a, int64(c) * 8 + 5);
87- 4: MovRI(a, int64(c) * 4096 * 4096 * 9 - 7);
88- else MovRI(a, 0);
89- end;
90- end;
91- 2: begin a := Rnd(8); m := RandMem; b := Size; c := Imm(b); AluMI(a, m, c, b) end;
92- 3: begin m := RandMem; b := Size; c := Imm(b); StoreI(m, c, b) end;
93- 4: begin a := Reg; m := RandMem; b := Size; c := Rnd(2); Load(a, m, b, c = 0) end;
94- 5: begin m := RandMem; a := Reg; b := Size; Store(m, a, b) end;
95- 6: begin a := Reg; m := RandMem; Lea(a, m) end;
96- 7: begin a := Rnd(8); b := Reg; c := Reg; Alu(a, b, c) end;
97- 8: begin a := Rnd(8); b := Reg; c := Imm(8); AluI(a, b, c) end;
98- 9: begin a := Rnd(8); b := Reg; m := RandMem; AluM(a, b, m) end;
99- 10: begin a := Reg; b := Reg; Imul(a, b) end;
100- 11: begin a := Reg; c := Imm(8); ImulI(a, c) end;
101- 12: begin a := Rnd(3); b := Reg; if a = 0 then a := shShl else if a = 1 then a := shShr else a := shSar; Shift(a, b) end;
102- 13: begin a := Rnd(3); b := Reg; c := Rnd(64); if a = 0 then a := shShl else if a = 1 then a := shShr else a := shSar; ShiftI(a, b, c) end;
103- 14: begin a := Rnd(4); b := Reg; if a < 2 then a := a + 2 else a := a + 4; Unary(a, b) end;
104- 15: Cqo;
105- 16: begin a := Reg; b := 1 shl Rnd(3); c := Rnd(2); Extend(a, b, c = 0) end;
106- 17: begin a := Rnd(16); b := Reg; SetCC(a, b) end;
107- 18: begin a := Reg; b := Reg; TestRR(a, b) end;
108- 19: begin a := Reg; Push(a) end;
109- 20: begin a := Reg; Pop(a) end;
110- 21: begin a := Rnd(5); CallChunk(a) end;
111- 22: begin a := Rnd(1000); CallBack(a) end;
112- 23: begin a := Reg; CallR(a) end;
113- 24: begin a := Reg; JmpR(a) end;
114- 25: begin m := RandMem; CallM(m) end;
115- 26: begin a := Rnd(5); case a of 0: Ret; 1: Leave; 2: Syscall; 3: Mfence; else Ud2 end end;
116- 27: begin a := 8 shl Rnd(3); Align(a) end;
117- 28: begin a := Rnd(5); case a of 0: RepMovsb; 1: Std; 2: Cld; 3: RepStosb; else RepeCmpsb end end;
118- 29: begin m := RandMem; a := Reg; LockCmpxchg(m, a) end;
119- 30: begin m := RandMem; a := Reg; Xchg(m, a) end;
120- 31: begin m := RandMem; a := Reg; LockXadd(m, a) end;
121- 32: begin a := Reg; b := Reg; MovqXR(a, b) end;
122- 33: begin a := Reg; b := Reg; MovqRX(a, b) end;
123- 34: begin a := Reg; b := Reg; MovX(a, b) end;
124- 35: begin a := Reg; m := RandMem; b := Rnd(2); MovsXM(a, m, b = 0) end;
125- 36: begin m := RandMem; a := Reg; b := Rnd(2); MovsMX(m, a, b = 0) end;
126- 37: begin
127- d := Rnd(5); a := Reg; b := Reg; c := Rnd(2);
128- case d of 0: d := $58; 1: d := $59; 2: d := $5C; 3: d := $5E; else d := $5A end;
129- Sse(d, a, b, c = 0);
130- end;
131- 38: begin
132- d := Rnd(5); a := Reg; m := RandMem; c := Rnd(2);
133- case d of 0: d := $58; 1: d := $59; 2: d := $5C; 3: d := $5E; else d := $5A end;
134- SseM(d, a, m, c = 0);
135- end;
136- 39: begin a := Reg; b := Reg; c := Rnd(2); Ucomis(a, b, c = 0) end;
137- 40: begin a := Reg; b := Reg; c := Rnd(2); Cvtsi2s(a, b, c = 0) end;
138- 41: begin a := Reg; b := Reg; c := Rnd(2); Cvtts2si(a, b, c = 0) end;
139- 42: begin a := Reg; b := Rnd(64); Btc(a, b) end;
140- 43: begin
141- a := Rnd(16); b := Rnd(2);
142- if b = 0 then Jmp(lab1) else Jcc(a, lab2);
143- end;
144- 44: begin a := Rnd(16); b := Rnd(2); c := pc - Rnd(200); if b = 0 then JmpBack(c) else JccBack(a, c) end;
145- 45: if Rnd(3) = 0 then begin FixLink(lab1); lab1 := NoLabel end
146- else begin FixLinkTo(lab2, pc - 20); lab2 := NoLabel end;
147- 46: begin Jmp(lab1); DropJumpTo(lab1) end;
148- 47: begin a := JoinLinks(lab1, lab2); lab1 := a; lab2 := NoLabel end;
149- else begin a := Rnd(256); Put1(a) end;
150- end;
151- end;
152- FixLink(lab1); FixLink(lab2);
153- EndChunk(0);
154- chunks^[0].live := true;
155- writeln('pc ', pc, ' fixups ', numFixups, ' lines ', numLines, ' said ', SaidCount);
156- for i := 0 to pc - 1 do write(HexStr(code^[i], 2));
157- writeln;
158- for i := 0 to numFixups - 1 do writeln('F ', fixups^[i].at, ' ', fixups^[i].chunk, ' ', fixups^[i].addend);
159- List(-1);
160-end.

src/test/X64Dump.raz deleted +0 -208

@@ -1,208 +0,0 @@
1-(* Writes every instruction the encoder makes, with operands drawn by a
2- fixed pseudo-random script, then prints the bytes, the fixups and the
3- listing (raz -S) of what it made: src/X64.raz's side of a test
4- against the seed's, X64Dump.pas, which prints the same. *)
5-module X64Dump;
6-import Out, Fmt, Diag, Scan, Chunk, X64;
7-
8-var seed: I64;
9-
10-proc rnd(n: INT): INT;
11-begin
12- seed := (seed * 1103515245 + 12345) & 7FFFFFFFH;
13- return INT((seed shr 8) mod I64(n));
14-end;
15-
16-(* a register *)
17-proc reg: INT;
18-begin
19- return rnd(16);
20-end;
21-
22-(* a size of 1, 2, 4 or 8 bytes *)
23-proc size: INT;
24-begin
25- return 1 shl rnd(4);
26-end;
27-
28-(* a value that fits sz bytes, of 8 as 32 bits *)
29-proc imm(sz: INT): INT;
30-var x, r: INT;
31-begin
32- x := rnd(1 shl 30);
33- match rnd(3) of
34- | 0: r := x mod 100 - 50;
35- | 1: r := x - (1 shl 29);
36- | else: r := x mod 20000 - 10000;
37- end;
38- if sz = 1 then
39- r := r mod 128;
40- elsif sz = 2 then
41- r := r mod 32768;
42- end;
43- return r;
44-end;
45-
46-proc randMem: X64.Mem;
47-var kind, base, idx, sc, disp, x: INT;
48-begin
49- kind := rnd(6);
50- base := reg(); idx := reg(); sc := 1 shl rnd(4); x := rnd(5);
51- match x of
52- | 0: disp := 0;
53- | 1: disp := rnd(250) - 125;
54- | 2: disp := rnd(1 shl 20) - (1 shl 19);
55- | 3: disp := 127 + rnd(3) - 1;
56- | else: disp := -128 + rnd(3) - 1;
57- end;
58- match kind of
59- | 0, 1: return X64.mem(base, disp);
60- | 2: return X64.memRip(rnd(5), disp);
61- | 3, 4: return X64.memIdx(base, idx, sc, disp);
62- | else: return X64.mem(base, 0);
63- end;
64-end;
65-
66-proc main*;
67-var
68- i, k, op, a, b, c, d, lab1, lab2: INT; m: X64.Mem; path: []U8;
69-begin
70- seed := 3;
71- path := "lib/Rt.raz";
72- if LEN(Scan.open(path)) # 0 then Diag.fatal("no file"); end;
73- X64.setListing(true);
74- for i := 0 to 4 do c := Chunk.newChunk(Chunk.secText, i - 1, i); end;
75- Chunk.setCurFile(Scan.intern(ADR(path[0]), LEN(path)));
76- Chunk.beginChunk(0);
77- lab1 := X64.NoLabel; lab2 := X64.NoLabel;
78- for k := 1 to 3000 do
79- if k mod 7 = 0 then a := rnd(300); b := rnd(60); Chunk.noteLine(1 + a, b); end;
80- op := rnd(50);
81- match op of
82- | 0: a := reg(); b := reg(); X64.movRR(a, b);
83- | 1:
84- a := reg(); b := rnd(6); c := rnd(1 shl 30);
85- match b of
86- | 0: X64.movRI(a, 0);
87- | 1: X64.movRI(a, c);
88- | 2: X64.movRI(a, -c);
89- | 3: X64.movRI(a, I64(c) * 8 + 5);
90- | 4: X64.movRI(a, I64(c) * 4096 * 4096 * 9 - 7);
91- | else: X64.movRI(a, 0);
92- end;
93- | 2: a := rnd(8); m := randMem(); b := size(); c := imm(b); X64.aluMI(a, m, c, b);
94- | 3: m := randMem(); b := size(); c := imm(b); X64.storeI(m, c, b);
95- | 4: a := reg(); m := randMem(); b := size(); c := rnd(2); X64.load(a, m, b, c = 0);
96- | 5: m := randMem(); a := reg(); b := size(); X64.store(m, a, b);
97- | 6: a := reg(); m := randMem(); X64.lea(a, m);
98- | 7: a := rnd(8); b := reg(); c := reg(); X64.alu(a, b, c);
99- | 8: a := rnd(8); b := reg(); c := imm(8); X64.aluI(a, b, c);
100- | 9: a := rnd(8); b := reg(); m := randMem(); X64.aluM(a, b, m);
101- | 10: a := reg(); b := reg(); X64.imul(a, b);
102- | 11: a := reg(); c := imm(8); X64.imulI(a, c);
103- | 12:
104- a := rnd(3); b := reg();
105- if a = 0 then a := X64.shShl; elsif a = 1 then a := X64.shShr; else a := X64.shSar; end;
106- X64.shift(a, b);
107- | 13:
108- a := rnd(3); b := reg(); c := rnd(64);
109- if a = 0 then a := X64.shShl; elsif a = 1 then a := X64.shShr; else a := X64.shSar; end;
110- X64.shiftI(a, b, c);
111- | 14:
112- a := rnd(4); b := reg();
113- if a < 2 then a := a + 2; else a := a + 4; end;
114- X64.unary(a, b);
115- | 15: X64.cqo;
116- | 16: a := reg(); b := 1 shl rnd(3); c := rnd(2); X64.extend(a, b, c = 0);
117- | 17: a := rnd(16); b := reg(); X64.setCC(a, b);
118- | 18: a := reg(); b := reg(); X64.testRR(a, b);
119- | 19: a := reg(); X64.push(a);
120- | 20: a := reg(); X64.pop(a);
121- | 21: a := rnd(5); X64.callChunk(a);
122- | 22: a := rnd(1000); X64.callBack(a);
123- | 23: a := reg(); X64.callR(a);
124- | 24: a := reg(); X64.jmpR(a);
125- | 25: m := randMem(); X64.callM(m);
126- | 26:
127- a := rnd(5);
128- match a of
129- | 0: X64.ret;
130- | 1: X64.leave;
131- | 2: X64.syscall;
132- | 3: X64.mfence;
133- | else: X64.ud2;
134- end;
135- | 27: a := 8 shl rnd(3); X64.align(a);
136- | 28:
137- a := rnd(5);
138- match a of
139- | 0: X64.repMovsb;
140- | 1: X64.std;
141- | 2: X64.cld;
142- | 3: X64.repStosb;
143- | else: X64.repeCmpsb;
144- end;
145- | 29: m := randMem(); a := reg(); X64.lockCmpxchg(m, a);
146- | 30: m := randMem(); a := reg(); X64.xchg(m, a);
147- | 31: m := randMem(); a := reg(); X64.lockXadd(m, a);
148- | 32: a := reg(); b := reg(); X64.movqXR(a, b);
149- | 33: a := reg(); b := reg(); X64.movqRX(a, b);
150- | 34: a := reg(); b := reg(); X64.movX(a, b);
151- | 35: a := reg(); m := randMem(); b := rnd(2); X64.movsXM(a, m, b = 0);
152- | 36: m := randMem(); a := reg(); b := rnd(2); X64.movsMX(m, a, b = 0);
153- | 37:
154- d := rnd(5); a := reg(); b := reg(); c := rnd(2);
155- match d of
156- | 0: d := 58H;
157- | 1: d := 59H;
158- | 2: d := 5CH;
159- | 3: d := 5EH;
160- | else: d := 5AH;
161- end;
162- X64.sse(d, a, b, c = 0);
163- | 38:
164- d := rnd(5); a := reg(); m := randMem(); c := rnd(2);
165- match d of
166- | 0: d := 58H;
167- | 1: d := 59H;
168- | 2: d := 5CH;
169- | 3: d := 5EH;
170- | else: d := 5AH;
171- end;
172- X64.sseM(d, a, m, c = 0);
173- | 39: a := reg(); b := reg(); c := rnd(2); X64.ucomis(a, b, c = 0);
174- | 40: a := reg(); b := reg(); c := rnd(2); X64.cvtsi2s(a, b, c = 0);
175- | 41: a := reg(); b := reg(); c := rnd(2); X64.cvtts2si(a, b, c = 0);
176- | 42: a := reg(); b := rnd(64); X64.btc(a, b);
177- | 43:
178- a := rnd(16); b := rnd(2);
179- if b = 0 then X64.jmp(lab1); else X64.jcc(a, lab2); end;
180- | 44:
181- a := rnd(16); b := rnd(2); c := Chunk.pc - rnd(200);
182- if b = 0 then X64.jmpBack(c); else X64.jccBack(a, c); end;
183- | 45:
184- a := rnd(3);
185- if a = 0 then
186- X64.fixLink(lab1); lab1 := X64.NoLabel;
187- else
188- X64.fixLinkTo(lab2, Chunk.pc - 20); lab2 := X64.NoLabel;
189- end;
190- | 46: X64.jmp(lab1); X64.dropJumpTo(lab1);
191- | 47: a := X64.joinLinks(lab1, lab2); lab1 := a; lab2 := X64.NoLabel;
192- | else: a := rnd(256); Chunk.put1(a);
193- end;
194- end;
195- X64.fixLink(lab1); X64.fixLink(lab2);
196- Chunk.endChunk(0);
197- Chunk.setLive(0);
198- Fmt.print("pc {} fixups {} lines {} said {}\n", [Fmt.int(Chunk.pc), Fmt.int(Chunk.numFixups),
199- Fmt.int(Chunk.numLines), Fmt.int(X64.saidCount())]);
200- for i := 0 to Chunk.pc - 1 do Out.hex(U64(Chunk.text[i]), 2); end;
201- Out.ln;
202- for i := 0 to Chunk.numFixups - 1 do
203- Fmt.print("F {} {} {}\n", [Fmt.int(Chunk.fixups[i].at), Fmt.int(Chunk.fixups[i].chunk), Fmt.int(Chunk.fixups[i].addend)]);
204- end;
205- X64.list(-1);
206-end;
207-
208-end X64Dump.

src/test/genasm.py deleted +0 -244

@@ -1,244 +0,0 @@
1-#!/usr/bin/env python3
2-"""Writes the files the assembler of X64 is tested on, into the directory
3-given: valid.raz, a long run of instructions of every kind the assembler
4-knows, and one small file for each error it reports. Each ends in `end`,
5-as a code procedure's body does. Fixed seed: the same files each run."""
6-import random, sys, os
7-
8-random.seed(7)
9-out = sys.argv[1]
10-os.makedirs(out, exist_ok=True)
11-
12-R64 = "rax rcx rdx rbx rsp rbp rsi rdi r8 r9 r10 r11 r12 r13 r14 r15".split()
13-R32 = "eax ecx edx ebx esp ebp esi edi r8d r9d r10d r11d r12d r13d r14d r15d".split()
14-R16 = "ax cx dx bx sp bp si di r8w r9w r10w r11w r12w r13w r14w r15w".split()
15-R8 = "al cl dl bl spl bpl sil dil r8b r9b r10b r11b r12b r13b r14b r15b".split()
16-BY = {8: R64, 4: R32, 2: R16, 1: R8}
17-PRE = {8: "qword ", 4: "dword ", 2: "word ", 1: "byte "}
18-XM = ["xmm%d" % i for i in range(16)]
19-CC = "o no b ae e ne be a s ns p np l ge le g c nae nc nb z nz na nbe nge nl ng nle".split()
20-
21-
22-def reg(size=8):
23- return random.choice(BY[size])
24-
25-
26-def mem(size=0):
27- k = random.randrange(8)
28- b = random.choice(R64)
29- i = random.choice([r for r in R64 if r != "rsp"])
30- d = random.choice([0, 8, -8, 127, -128, 128, 4096, -4096, 100000])
31- s = random.choice([1, 2, 4, 8])
32- p = PRE[size] if size else ""
33- if k == 0:
34- t = "[%s]" % b
35- elif k == 1:
36- t = "[%s + %d]" % (b, abs(d)) if d >= 0 else "[%s - %d]" % (b, -d)
37- elif k == 2:
38- t = "[%s + %s * %d]" % (b, i, s)
39- elif k == 3:
40- t = "[%s + %s * %d + %d]" % (b, i, s, abs(d)) if d >= 0 else "[%s + %s * %d - %d]" % (b, i, s, -d)
41- elif k == 4:
42- t = "[%s + %s]" % (b, i)
43- elif k == 5:
44- t = "[%s + 0]" % b
45- elif k == 6:
46- t = "[rsp + %d]" % abs(d)
47- else:
48- t = "[%s - %d]" % (b, abs(d) + 1)
49- return p + t
50-
51-
52-def imm(size):
53- if size == 1:
54- return str(random.choice([0, 1, -1, 127, 255, -128, 77]))
55- if size == 2:
56- return str(random.choice([0, 1, -1, 300, 32767, -32768, 255, 65535]))
57- return str(random.choice([0, 1, -1, 127, 128, -128, -129, 100000, -100000, 2147483647, -2147483648, 4294967295]))
58-
59-
60-def size():
61- return random.choice([1, 2, 4, 8])
62-
63-
64-lines = []
65-
66-
67-def emit(s):
68- lines.append(" " + s + ";")
69-
70-
71-for n in range(900):
72- k = random.randrange(40)
73- sz = size()
74- if k < 6:
75- op = random.choice("add or adc sbb and sub xor cmp".split())
76- f = random.randrange(5)
77- if f == 0:
78- emit("%s %s, %s" % (op, reg(sz), reg(sz)))
79- elif f == 1:
80- emit("%s %s, %s" % (op, reg(sz), mem(sz if random.random() < .5 else 0)))
81- elif f == 2:
82- emit("%s %s, %s" % (op, mem(sz if random.random() < .5 else 0), reg(sz)))
83- elif f == 3:
84- emit("%s %s, %s" % (op, reg(sz), imm(sz)))
85- else:
86- emit("%s %s, %s" % (op, mem(sz), imm(sz)))
87- elif k < 10:
88- f = random.randrange(5)
89- if f == 0:
90- emit("mov %s, %s" % (reg(sz), reg(sz)))
91- elif f == 1:
92- emit("mov %s, %s" % (reg(sz), mem()))
93- elif f == 2:
94- emit("mov %s, %s" % (mem(), reg(sz)))
95- elif f == 3:
96- v = random.choice([0, 5, -5, 2147483647, 4294967295, 4294967296, -2147483649, 123456789012345])
97- emit("mov %s, %d" % (reg(8 if sz >= 4 else sz) if sz >= 4 else reg(sz), v if sz == 8 else (v % 65536 if sz == 2 else v % 256 if sz == 1 else v % 4294967296)))
98- else:
99- emit("mov %s, %s" % (mem(sz), imm(sz)))
100- elif k == 10:
101- emit("test %s, %s" % (reg(sz), random.choice([reg(sz), imm(sz) if sz != 1 else "1"])))
102- elif k == 11:
103- emit("xchg %s, %s" % (random.choice([reg(sz), mem()]), reg(sz)))
104- elif k == 12:
105- emit("%slock %s %s, %s" % ("", random.choice(["cmpxchg", "xadd"]), mem(), reg(sz)))
106- elif k == 13:
107- emit("lea %s, %s" % (reg(random.choice([2, 4, 8])), mem()))
108- elif k == 14:
109- op = random.choice(["movzx", "movsx"])
110- emit("%s %s, %s" % (op, reg(random.choice([2, 4, 8])), random.choice([mem(random.choice([1, 2])), reg(random.choice([1, 2]))])))
111- elif k == 15:
112- emit("movsxd %s, %s" % (reg(8), random.choice([mem(4), reg(4)])))
113- elif k == 16:
114- emit("%s %s" % (random.choice("not neg mul imul div idiv inc dec".split()), random.choice([reg(sz), mem(sz)])))
115- elif k == 17:
116- emit("imul %s" % ", ".join([reg(sz if sz > 1 else 4), random.choice([reg(sz if sz > 1 else 4)] * 1 + [mem()])] + ([imm(sz if sz > 1 else 4)] if random.random() < .4 else [])).replace("%", "%"))
117- elif k == 18:
118- op = random.choice("rol ror rcl rcr shl shr sal sar".split())
119- emit("%s %s, %s" % (op, random.choice([reg(sz), mem(sz)]), random.choice([str(random.randrange(64)), "cl"])))
120- elif k == 19:
121- emit("%s %s" % (random.choice(["push", "pop"]), reg(8)))
122- elif k == 20:
123- op = random.choice(["call", "jmp"])
124- emit("%s %s" % (op, random.choice([reg(8), mem()]) if op == "call" else mem()))
125- elif k == 21:
126- emit("set%s %s" % (random.choice(CC), random.choice([reg(1), mem(1)])))
127- elif k == 22:
128- emit("cmov%s %s, %s" % (random.choice(CC), reg(random.choice([2, 4, 8])), random.choice([reg(8), mem()])))
129- elif k == 23:
130- op = random.choice("sqrt add mul sub min div max".split()) + random.choice(["sd", "ss"])
131- emit("%s %s, %s" % (op, random.choice(XM), random.choice([random.choice(XM), mem()])))
132- elif k == 24:
133- op = random.choice("punpcklbw punpcklwd pcmpeqb pand pandn por pxor paddb psubb".split())
134- emit("%s %s, %s" % (op, random.choice(XM), random.choice([random.choice(XM), mem()])))
135- elif k == 25:
136- emit("pshufd %s, %s, %d" % (random.choice(XM), random.choice([random.choice(XM), mem()]), random.randrange(256)))
137- elif k == 26:
138- op = random.choice(["movdqu", "movdqa"])
139- if random.random() < .5:
140- emit("%s %s, %s" % (op, random.choice(XM), random.choice([random.choice(XM), mem()])))
141- else:
142- emit("%s %s, %s" % (op, mem(), random.choice(XM)))
143- elif k == 27:
144- emit("pmovmskb %s, %s" % (reg(4), random.choice(XM)))
145- elif k == 28:
146- emit("%s %s, %s" % (random.choice("bsf bsr tzcnt lzcnt popcnt".split()), reg(random.choice([4, 8])), random.choice([reg(8), mem()])))
147- elif k == 29:
148- op = random.choice(["movsd", "movss"])
149- if random.random() < .5:
150- emit("%s %s, %s" % (op, random.choice(XM), random.choice([random.choice(XM), mem()])))
151- else:
152- emit("%s %s, %s" % (op, mem(), random.choice(XM)))
153- elif k == 30:
154- op = random.choice(["movq", "movd"])
155- if random.random() < .5:
156- emit("%s %s, %s" % (op, random.choice(XM), random.choice([reg(8), mem()])))
157- else:
158- emit("%s %s, %s" % (op, random.choice([reg(8), mem()]), random.choice(XM)))
159- elif k == 31:
160- emit("%s %s, %s" % (random.choice(["ucomisd", "ucomiss"]), random.choice(XM), random.choice([random.choice(XM), mem()])))
161- elif k == 32:
162- emit("%s %s, %s" % (random.choice(["cvtsi2sd", "cvtsi2ss"]), random.choice(XM), random.choice([reg(random.choice([4, 8])), mem(random.choice([4, 8]))])))
163- elif k == 33:
164- emit("%s %s, %s" % (random.choice(["cvttsd2si", "cvttss2si"]), reg(random.choice([4, 8])), random.choice([random.choice(XM), mem()])))
165- elif k == 34:
166- emit("%s %s, %s" % (random.choice(["cvtsd2ss", "cvtss2sd"]), random.choice(XM), random.choice([random.choice(XM), mem()])))
167- elif k == 35:
168- emit(random.choice("ret leave syscall cpuid rdtsc pause nop ud2 int3 hlt cqo cdq mfence lfence sfence".split()))
169- elif k == 36:
170- emit("db " + ", ".join(str(random.choice([0, 1, 255, 128, 77, -1, -128])) for _ in range(random.randrange(1, 6))))
171- elif k == 37:
172- lines.append(" L%d:" % n)
173- lines.append(" add rax, 1;")
174- lines.append(" j%s L%d;" % (random.choice(CC), n))
175- lines.append(" jmp L%d;" % n)
176- elif k == 38:
177- lines.append(" jmp F%d;" % n)
178- lines.append(" nop;")
179- lines.append(" j%s F%d;" % (random.choice(CC), n))
180- lines.append(" F%d:" % n)
181- else:
182- emit("lock add %s, %s" % (mem(sz), reg(sz)))
183-
184-open(os.path.join(out, "valid.raz"), "w").write("\n".join(lines) + "\n end\n")
185-
186-errors = {
187- "empty": "",
188- "badop": "foo rax;",
189- "noinsn": "42;",
190- "nosemi": "nop",
191- "undefined": "jmp nowhere;",
192- "twice": "a: nop; a: nop;",
193- "toomany": "add rax, rbx, rcx, rdx;",
194- "movimm": "mov 1, 2;",
195- "movmm": "mov [rax], [rbx];",
196- "addimm": "add 1, rax;",
197- "pushmem": "push [rax];",
198- "pushsmall": "push eax;",
199- "badmem": "mov rax, [rsi * 4];",
200- "badscale": "mov rax, [rsi + rdi * 3];",
201- "nomem": "mov rax, [];",
202- "unclosed": "mov rax, [rbx;",
203- "shiftcl": "shl rax, dl;",
204- "shiftimm": "shl 3, 1;",
205- "lea": "lea rax, rbx;",
206- "movzx": "movzx rax, rbx;",
207- "movzx4": "movzx rax, dword [rbx];",
208- "setsize": "sete rax;",
209- "cmovimm": "cmove rax, 5;",
210- "sse": "addsd rax, xmm1;",
211- "sse1": "addsd xmm1;",
212- "pshufd": "pshufd xmm1, xmm2;",
213- "pand3": "pand xmm1, xmm2, 3;",
214- "movdq": "movdqu rax, xmm1;",
215- "pmov": "pmovmskb xmm1, rax;",
216- "bits": "popcnt ax, bx;",
217- "movsd": "movsd rax, xmm1;",
218- "movq": "movq rax, rbx;",
219- "ucomi": "ucomisd rax, xmm1;",
220- "cvtsi": "cvtsi2sd rax, xmm1;",
221- "cvtt": "cvttsd2si xmm1, xmm2;",
222- "cvtss": "cvtss2sd rax, xmm1;",
223- "plainops": "ret rax;",
224- "dbrange": "db 256;",
225- "dbneg": "db -129;",
226- "imul1": "imul rax, 5;",
227- "imulmem": "imul [rax], rbx;",
228- "unary2": "not rax, rbx;",
229- "unaryimm": "neg 5;",
230- "inc": "inc 5;",
231- "xchgimm": "xchg rax, 5;",
232- "cmpxchg": "cmpxchg rax, 5;",
233- "calli": "call 5;",
234- "jmpimm": "jmp 5;",
235- "labels65": "".join("l%d: nop; " % i for i in range(65)),
236- "xmm16": "addsd xmm16, xmm1;",
237- "noend": None,
238-}
239-for name, body in errors.items():
240- if body is None:
241- text = " nop;\n"
242- else:
243- text = " " + body + "\n end\n"
244- open(os.path.join(out, "err_%s.raz" % name), "w").write(text)

src/test/genlex.py deleted +0 -29

@@ -1,29 +0,0 @@
1-# Writes into the directory given a file for each message the scanner
2-# makes, with the places diag shows them in: after a tab, in a long
3-# line, after characters of several bytes, in a CRLF file.
4-import sys
5-d = sys.argv[1]
6-cases = {
7- "slip1": "x == y;\n", "slip2": "a && b;\n", "slip3": "a || b;\n", "slip4": "a != b;\n", "slip5": "!a;\n",
8- "str": "x := \"abc\n", "chr": "x := 'a\n", "chr2": "x := 'ab';\n", "chr3": "x := '';\n",
9- "esc": "x := \"\\q\";\n", "esc2": "x := 'a\\x41';\n", "esc3": "x := \"\\x4\";\n",
10- "esc4": "x := \"\\u41\";\n", "esc5": "x := \"\\u{110000}\";\n", "esc6": "x := \"\\u{D800}\";\n",
11- "esc7": "x := \"\\u{1234567}\";\n", "esc8": "x := \"\\u{}\";\n", "esc9": "x := \"\\u{41\";\n",
12- "esc10": "x := \"\\u{1F600}\\u{e9}\\x00\\xff\\n\\t\\r\\0\\\\\\'\\\"\";\n",
13- "cmt": "x := 1; (* open (* nested *)\n", "nul": "x := 1;\0 y;\n", "hexbad": "x := 12AB;\n",
14- "hexbig": "x := 1FFFFFFFFFFFFFFFFH;\n", "hexok": "x := 0FFFFFFFFFFFFFFFFH; y := 7FFFFFFFFFFFFFFFH;\n",
15- "decbig": "x := 9223372036854775808;\n", "decmax": "x := 9223372036854775807;\n",
16- "realhex": "x := 1A.5;\n", "realexp": "x := 1.5E;\n", "realexp2": "x := 1.5E+;\n", "realbig": "x := 1.0E309;\n",
17- "realmax": "x := 1.7976931348623159E308;\n", "reallong": "x := " + "1" * 254 + ".5;\n",
18- "digname": "x := 12abc;\n", "uni": "x := \u00e9;\n", "badutf": b"x := \"a\xc3(\";\n", "badutf2": b"x := \"\xed\xa0\x80\";\n",
19- "badutf3": b"x := \"\xc0\x80\";\n", "badutf4": b"x := \"\xf5\x80\x80\x80\";\n", "badutf5": b"x := \"\xe2\x82\";\n",
20- "okutf": "x := \"h\u00e9llo \u20ac \U0001F600\"; y := '\u00e9'; (* \u00e9 *)\n",
21- "unexp": "x := @;\n", "long": "x := " + "a + " * 60 + "@;\n", "longmid": "x := " + "a + " * 40 + "@ " + "+ b" * 40 + ";\n",
22- "tab": "\t\tx := @;\n", "multi": "x := \"\u00e9\u00e9\u00e9\" + @;\n", "ident64": "x" * 64 + ";\n", "ident63": "x" * 63 + ";\n",
23- "bigstr": "x := \"" + "a" * 70000 + "\";\n", "empty": "", "nonl": "x := y",
24- "ops": "+ - * / = # < <= > >= := : ; , . .. ... ( ) [ ] { } ^ & ~ | _ __ _a\n",
25- "words": "and begin break by code const defer div do else elsif end extern for forward if import in link match mod module not of or packed proc record repeat return set shl shr then to try type until var variant VOLATILE while xor Volatile\n",
26-}
27-for k, v in cases.items():
28- open(f"{d}/{k}.raz", "wb").write(v.encode("utf-8", "surrogateescape") if isinstance(v, str) else v)
29-open(f"{d}/crlf.raz", "wb").write(b"x := 1;\r\ny := @;\r\n")

src/test/genreals.py deleted +0 -19

@@ -1,19 +0,0 @@
1-# Prints a raz module of reals that are hard to read exactly: the
2-# extremes, halves between neighbours, and many random ones.
3-import random
4-random.seed(7)
5-v = ["0.0", "1.0", "0.1", "4.9E-324", "2.4703282292062327E-324", "2.4703282292062328E-324",
6- "2.2250738585072014E-308", "2.2250738585072011E-308", "1.7976931348623157E308",
7- "9007199254740993.0", "9007199254740992.5", "9007199254740993.5", "0.000001E+3",
8- "123456789012345678901234567890.0E-10", "1.0E-400", "0.5E1", "5.0E-1"]
9-for _ in range(3000):
10- d = random.randint(1, 10 ** random.randint(1, 30))
11- e = random.randint(-320, 300)
12- s = str(d)
13- v.append(s[0] + "." + (s[1:] or "0") + "E" + ("%+d" % e if random.random() < .5 else str(e)))
14-for _ in range(500):
15- v.append("%d.%d" % (random.randint(0, 10 ** 6), random.randint(0, 10 ** 12)))
16-print("module Reals;\nvar x: F64;\nbegin")
17-for s in v:
18- print(" x := " + s + ";")
19-print("end Reals.")

src/test/seedcontinue.pas deleted +0 -20

@@ -1,20 +0,0 @@
1-{ The seed has no continue, which report 2026-10.31 made a reserved
2- word, the last of them in src/Scan.raz. This unit interns the name
3- right after the seed's reserved words, before any other, so that
4- every name after it has the number src/ gives it: each dumper that is
5- compared with src/'s side uses it straight after scan. }
6-unit seedcontinue;
7-
8-{$mode objfpc}{$H-}
9-
10-interface
11-
12-implementation
13-
14-uses scan;
15-
16-const Word: string = 'continue';
17-
18-initialization
19- Intern(@Word[1], length(Word));
20-end.

test/check.sh (history) modified +11 -0

@@ -252,6 +252,17 @@
252252 if (ulimit -v 60000; $out/lib_Thread.linux-x86_64 fail) > /dev/null 2>&1; then pass=$((pass + 1))
253253 else echo "FAIL Thread under a memory limit"; fail=$((fail + 1)); fi
254254
255+# the compiler's way of going on after an error, in small: a parser
256+# that reads names, fails on each bad one, and goes on to the next
257+if $raz -Werror -I src -o $out/recover src/test/Recover.raz 2>$out/recover.cerr; then
258+ printf 'a bad b bad bad c\nd bad\n' >$out/rec.raz
259+ r=$($out/recover $out/rec.raz 2>/dev/null) || true
260+ if [ "$r" = "8 names, 4 failed, 4 errors" ]; then pass=$((pass + 1))
261+ else echo "FAIL src/test/Recover.raz: $r"; fail=$((fail + 1)); fi
262+else
263+ echo "FAIL src/test/Recover.raz: $(cat $out/recover.cerr)"; fail=$((fail + 1))
264+fi
265+
255266 # a module imported and never called leaves nothing of its own in the
256267 # program, not even Width's tables: the same program, importing it or
257268 # not, makes a file of the same size (the names the trace shows may