Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
322 changes: 258 additions & 64 deletions @ether/$/deflate/Deflate.ray

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions @ether/poc/deflate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
1 change: 1 addition & 0 deletions @ether/poc/deflate/bad/btype3.deflate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file added @ether/poc/deflate/bad/far.deflate
Binary file not shown.
1 change: 1 addition & 0 deletions @ether/poc/deflate/bad/fixed286.deflate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 7 additions & 0 deletions @ether/poc/deflate/bad/manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
btype3.deflate 3 invalid block type
nlen.deflate 40 invalid stored block lengths
truncated.deflate 3 incomplete or truncated stream
fixed286.deflate 11 invalid literal/length code
far.deflate - invalid distance too far back
repeat.deflate - invalid bit length repeat
oversubscribed.deflate - invalid code lengths set
Binary file added @ether/poc/deflate/bad/nlen.deflate
Binary file not shown.
Binary file added @ether/poc/deflate/bad/oversubscribed.deflate
Binary file not shown.
Binary file added @ether/poc/deflate/bad/repeat.deflate
Binary file not shown.
1 change: 1 addition & 0 deletions @ether/poc/deflate/bad/truncated.deflate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c
39 changes: 39 additions & 0 deletions @ether/poc/deflate/boot.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// language3 as `site3.mts` boots it: the entrypoint with the host's operators where its logic begins, the host's kinds, the
// core library in the order it needs itself, the host's rules again after it (`KINDS_AFTER`), then the files in `LOAD`.
const ether = process.env.ETHER!;
const { Program, Text } = await import(`${ether}/v0.ts/src/language3.ts`);
const fs = await import('node:fs'), path = await import('node:path');

export { Program };
export const booted = async () => {
const entry = fs.readFileSync(path.join(ether, 'ray/.entrypoint.ray2'), 'utf8'), kinds = fs.readFileSync(path.join(ether, 'v0.ts/src/js3.kinds.ray'), 'utf8');
const ops = kinds.indexOf('// What both answer'), made_of = kinds.indexOf('// What a number or text is made of'), logic = entry.indexOf('// What a value answers to `?`');
const source = new Text.Source('@ether/ray/.entrypoint.ray2');
source.value = entry.slice(0, logic) + kinds.slice(ops, made_of) + '\n' + entry.slice(logic);
const program: any = new Program(source);
await program.compile();
program.run(kinds.slice(0, ops) + '\n' + kinds.slice(made_of), { node: program.global });
if (process.env.STEPS) { const read = program.read, limit = Number(process.env.STEPS); program.read = function (...args: unknown[]) { if (++program.steps > limit) throw new Error('ran away at ' + String(args[0]).slice(0, 80)); return read.apply(this, args); }; program.steps = 0; }
const statements = (file: string) => program.code(fs.readFileSync(file, 'utf8')).statements.filter((statement: string) => statement.trim() && !statement.trim().startsWith('//') && !/^@[\w./-]+$/.test(statement.trim()));
const quietly = (file: string) => { for (const statement of statements(file)) { program.steps = 0; try { program.run(statement, { node: program.global }); } catch {} } };
const reading_order = (files: string[]): string[] => {
const texts = new Map(files.map(file => [file, fs.readFileSync(file, 'utf8')]));
const defines = (text: string) => new Set([...text.matchAll(/^([A-Za-z_][\w-]*)(?:\s*<[^>\n]*>)?\s*(?:\^[\w.]+\s*)?:=/gm)].map(m => m[1]));
const info = files.map(file => ({ file, defines: defines(texts.get(file)!), uses: new Set(texts.get(file)!.match(/[A-Za-z_][\w]*/g) ?? []) }));
const needs = new Map(info.map(f => [f.file, new Set(info.filter(g => g !== f && [...g.defines].some(name => f.uses.has(name) && !f.defines.has(name))).map(g => g.file))]));
const order: string[] = [], left = new Set(files);
while (left.size > 0) { const waiting = (file: string) => [...needs.get(file)!].filter(other => left.has(other)).length; const next = [...left].sort((a, b) => waiting(a) - waiting(b) || (a < b ? -1 : 1))[0]; order.push(next); left.delete(next); }
return order;
};
const library = path.join(ether, 'ray');
if (!process.env.NOLIB) for (const file of reading_order(fs.readdirSync(library).filter((file: string) => file.endsWith('.ray') && !file.startsWith('.')).map((file: string) => path.join(library, file)))) quietly(file);
if (process.env.KINDS_AFTER) for (const statement of program.code(kinds).statements) {
const head = statement.split('\n')[0];
if (!/=>\s*$/.test(head) || head.includes('{{')) continue;
program.run(statement, { node: program.global });
const rule = program.global.rules.find((rule: any) => rule.head === program.head(head.trimEnd().slice(0, -2).trim()).head);
if (rule) { rule.id = ++Program.Node.defined; program.global.headed++; }
}
for (const file of (process.env.LOAD ?? '').split(',').filter(Boolean)) quietly(path.resolve(ether, file));
return { program, statements };
};
67 changes: 67 additions & 0 deletions @ether/poc/deflate/corpus.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// DP3 (`read`): each corpus stream read by `Deflate.inflated`, its SHA-256 the one `manifest.txt` has for what zlib inflates
// it to. DP4 (`rewrite`): each stream read into a `Deflate.Stream` and that same value written back, byte for byte the stream.
const { booted } = await import('./boot.mts');
const fs = await import('node:fs'), path = await import('node:path'), crypto = await import('node:crypto');
const { program } = await booted();
const here = path.dirname(new URL(import.meta.url).pathname), corpus = path.join(here, 'corpus'), out = path.join(here, 'out', process.argv[2]);
fs.mkdirSync(out, { recursive: true });
const g = { node: program.global }, none = program.run('None', g);
const run = (text: string) => { program.steps = 0; return program.run(text, g); };
const listed = (bytes: Uint8Array) => { const list = run('Listing.new'); for (const byte of bytes) run(program.written(list) + '.append(' + byte + ')'); return list; };
const bytes_of = (list: unknown): Uint8Array | undefined => {
if (typeof list !== 'object' || list === null || run(program.written(list) + '.listing') !== run('true')) return undefined;
const values: number[] = [];
for (let at = run(program.written(list) + '.head'); at !== none && at !== undefined; at = run(program.written(at) + '.next')) values.push(run(program.written(at) + '.value') as number);
return Uint8Array.from(values);
};
const sha = (bytes: Uint8Array) => crypto.createHash('sha256').update(bytes).digest('hex');
const only = process.env.ONLY?.split(',');
let failed = 0;
// DP6 (`reject`): each stream zlib rejects answers no bytes, and where reading stopped is the bit `bad/manifest.txt` gives
// (`-`: it reads, and what it means does not hold).
if (process.argv[2] === 'reject') {
for (const line of fs.readFileSync(path.join(here, 'bad', 'manifest.txt'), 'utf8').trim().split('\n')) {
const [name, stop, ...reason] = line.split(' ');
if (only && !only.some(part => name.includes(part))) continue;
let answered: Uint8Array | undefined, error = '';
try { answered = bytes_of(run('Deflate.inflated(' + program.written(listed(fs.readFileSync(path.join(here, 'bad', name)))) + ')')); } catch (e: any) { error = String(e?.message).slice(0, 80); }
const reached = program.layouts.reached, held = !answered && !error && (stop === '-' || Number(stop) === reached);
if (!held) failed++;
console.log(held ? 'ok ' : 'FAIL', name.padEnd(24), 'stopped at bit', String(stop === '-' ? '-' : reached).padStart(3), '| zlib:', reason.join(' '), held ? '' : error || (answered ? `read ${answered.length} bytes` : `expected bit ${stop}`));
}
console.log(failed ? `${failed} failed` : 'DP6 every stream zlib rejects is rejected');
process.exit(failed ? 1 : 0);
}
// DP5 (`write`): each input written by `Deflate.deflated`; zlib inflates it to the input, and Ray reads it back to the input.
if (process.argv[2] === 'write') {
const zlib = await import('node:zlib');
for (const name of fs.readdirSync(path.join(here, 'inputs')).sort()) {
if (only && !only.some(part => name.includes(part))) continue;
const input = fs.readFileSync(path.join(here, 'inputs', name)), started = performance.now();
let written: Uint8Array | undefined, inflated: Uint8Array | undefined, read: Uint8Array | undefined, error = '';
try {
written = bytes_of(run('Deflate.deflated(' + program.written(listed(input)) + ')'));
if (written) { fs.writeFileSync(path.join(out, name + '.deflate'), written); inflated = zlib.inflateRawSync(written); read = bytes_of(run('Deflate.inflated(' + program.written(listed(written)) + ')')); }
} catch (e: any) { error = String(e?.message).slice(0, 80); }
const held = !!inflated && !!read && sha(inflated) === sha(input) && sha(read) === sha(input);
if (!held) failed++;
console.log(held ? 'ok ' : 'FAIL', name.padEnd(14), String(input.length).padStart(5), '->', String(written?.length ?? '-').padStart(5), 'bytes', String(Math.round(performance.now() - started)).padStart(7), 'ms', held ? '' : error || 'not the input');
}
console.log(failed ? `${failed} failed` : 'all written so zlib, and Ray, read back the input');
process.exit(failed ? 1 : 0);
}
for (const line of fs.readFileSync(path.join(corpus, 'manifest.txt'), 'utf8').trim().split('\n')) {
const [name, , stream_sha, inflated_sha] = line.split(' ');
if (only && !only.some(part => name.includes(part))) continue;
const stream = fs.readFileSync(path.join(corpus, name)), started = performance.now();
let got: Uint8Array | undefined, error = '';
try {
got = process.argv[2] === 'read' ? bytes_of(run('Deflate.inflated(' + program.written(listed(stream)) + ')')) : bytes_of(run('Deflate.Stream.from(' + program.written(listed(stream)) + ').written'));
} catch (e: any) { error = String(e?.message).slice(0, 80); }
const held = got !== undefined && sha(got) === (process.argv[2] === 'read' ? inflated_sha : stream_sha);
if (got) fs.writeFileSync(path.join(out, name.replace(/\.deflate$/, process.argv[2] === 'read' ? '' : '.deflate')), got);
if (!held) failed++;
console.log(held ? 'ok ' : 'FAIL', name.padEnd(32), String(Math.round(performance.now() - started)).padStart(7), 'ms', held ? '' : error || (got ? `${got.length} bytes, not the same` : 'no bytes'));
}
console.log(failed ? `${failed} failed` : `all ${process.argv[2] === 'read' ? 'read to what zlib inflates them to' : 'written back byte for byte'}`);
process.exitCode = failed ? 1 : 0;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions @ether/poc/deflate/corpus/manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
empty.bin.0.default.deflate 5 f067985d352d2da6dfaef4844a66d06c5371ecbd9530a4d195ac599fef8b3427 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
empty.bin.1.default.deflate 2 9b4fb24edd6d1d8830e272398263cdbf026b97392cc35387b991dc0248a628f9 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
hello.txt.0.default.deflate 10 0422568b284c3e22bace9f6007e08dfa93a84d29849ed8c6fefda0d670b7dff3 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
hello.txt.1.default.deflate 7 9c050feb4ff382803b4dd786f57d6b67089b784a8adf0ac969fe50086360ed91 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
one.txt.0.default.deflate 6 0b96b18b4f7c1dcc466400c20c035f8542c8d19cecebe0e198c10be917b464a8 ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
one.txt.1.default.deflate 3 59fced9a2ff83dabdd7055cf3abd6c12b802e6397b6fba5b8251cdf95d2bc991 ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb
random.bin.0.default.deflate 517 05ac6f07c56e47620e2f30d6589c342c89c5dd65c3448205133c2d7d32b0f171 13bd8ee11c001a4804bc2535d33b807e7e796b001f2970516dea564248968c9b
ray.txt.0.default.deflate 261 9aad2c0b40f39e77ff328909913a8a30ccc912cbeb1789e8a4911872994a24d5 2ac3f639ab3e378293c0afeaabd2a66b3c26e55b5bbf11b0445caa6cafef3f08
ray.txt.1.default.deflate 9 680504f8e79d7996f54a528dc83f79ca2152f5417518c23abc653e30ee55e4d9 2ac3f639ab3e378293c0afeaabd2a66b3c26e55b5bbf11b0445caa6cafef3f08
ray.txt.1.huffman.deflate 89 7f454fba93dd069c417af7ceb6d0a861a35aa36220aaa8cd4c97a48e3c010670 2ac3f639ab3e378293c0afeaabd2a66b3c26e55b5bbf11b0445caa6cafef3f08
run.bin.0.default.deflate 305 8420f85c1ef6df5ef4880bf44702e1d3c29503003ec51934ea6efba0a5f42903 4daeb9ac8be203281aceb5f4511220333686abfde4d2ccd50a49cd156a2e8cf5
run.bin.1.default.deflate 8 fe7245f833be968622f6703335db6a943a8133e9a339f0071c1e93c85095293b 4daeb9ac8be203281aceb5f4511220333686abfde4d2ccd50a49cd156a2e8cf5
run.bin.1.huffman.deflate 50 a0964fe7749bb61fa0838a958b46f855edfacba70f4cb70cde3e8eb1735057bc 4daeb9ac8be203281aceb5f4511220333686abfde4d2ccd50a49cd156a2e8cf5
run.bin.1.rle.deflate 6 3bba2a385b3654e69555cc490ca7424fc20581a4902313b3590fe11436b85875 4daeb9ac8be203281aceb5f4511220333686abfde4d2ccd50a49cd156a2e8cf5
run.bin.6.default.deflate 7 2dba3cb21a95d3b30da70413762d502c0695dd809ab447611f81369c8014267b 4daeb9ac8be203281aceb5f4511220333686abfde4d2ccd50a49cd156a2e8cf5
text.txt.0.default.deflate 1245 05c642c1593de59972d8504eb303e50eb5978067d9a87ce3f858720a8eb950f3 2e7785f33261f8997216a0c236321d26614c906000e1cf35a356cd6d4a2fc0a3
text.txt.1.default.deflate 333 29e9689a4497c3c77a1726282e5bd36c45809d8bcc5613bfa40bedb316b513f2 2e7785f33261f8997216a0c236321d26614c906000e1cf35a356cd6d4a2fc0a3
text.txt.1.huffman.deflate 696 58e06925957f0da674931a687ab2d15d7f5a673ee33bc02f58f277813ffd5f97 2e7785f33261f8997216a0c236321d26614c906000e1cf35a356cd6d4a2fc0a3
text.txt.1.fixed.deflate 422 42702939510ae8d5f46e84898e2d07f9785f8b837737f5429c791b205caf2db0 2e7785f33261f8997216a0c236321d26614c906000e1cf35a356cd6d4a2fc0a3
text.txt.6.default.deflate 327 49f1df9fc9698e839a4108b2385491a4dad1e3541ab3a66a9dde4a0a7d589e14 2e7785f33261f8997216a0c236321d26614c906000e1cf35a356cd6d4a2fc0a3
text.txt.6.filtered.deflate 329 4874e86bde5f4912f704572f6eba8c9fe8c52f096d2097f1bc3b48aa17849b44 2e7785f33261f8997216a0c236321d26614c906000e1cf35a356cd6d4a2fc0a3
text.txt.6.fixed.deflate 410 8a8deefb39c6ce4231e49721c4ea31faf5afa5c3f573d3ee1e66b13c16890322 2e7785f33261f8997216a0c236321d26614c906000e1cf35a356cd6d4a2fc0a3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added @ether/poc/deflate/corpus/ray.txt.0.default.deflate
Binary file not shown.
Binary file not shown.
Binary file added @ether/poc/deflate/corpus/ray.txt.1.huffman.deflate
Binary file not shown.
1 change: 1 addition & 0 deletions @ether/poc/deflate/corpus/run.bin.0.default.deflate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,ÓþAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Binary file not shown.
Binary file added @ether/poc/deflate/corpus/run.bin.1.huffman.deflate
Binary file not shown.
Binary file added @ether/poc/deflate/corpus/run.bin.1.rle.deflate
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions @ether/poc/deflate/corpus/text.txt.0.default.deflate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ø'ûA declaration of a format is its type, its parser and its writer at once. Read, it turns bytes into a value whose fields are the pieces of its header; written, it turns that value back into the same bytes. DEFLATE packs its fields least significant bit first, reads its Huffman codes most significant bit first, and lets a copy reach back into what it has already written, even into the bytes it is writing. A stored block holds its bytes as they are; a fixed block uses the codes the format fixes; a dynamic block carries its own codes, written as the lengths of its codes, themselves written with a code of their own. A declaration of a format is its type, its parser and its writer at once. Read, it turns bytes into a value whose fields are the pieces of its header; written, it turns that value back into the same bytes. DEFLATE packs its fields least significant bit first, reads its Huffman codes most significant bit first, and lets a copy reach back into what it has already written, even into the bytes it is writing. A stored block holds its bytes as they are; a fixed block uses the codes the format fixes; a dynamic block carries its own codes, written as the lengths of its codes, themselves written with a code of their own.
Binary file added @ether/poc/deflate/corpus/text.txt.1.default.deflate
Binary file not shown.
Binary file added @ether/poc/deflate/corpus/text.txt.1.fixed.deflate
Binary file not shown.
3 changes: 3 additions & 0 deletions @ether/poc/deflate/corpus/text.txt.1.huffman.deflate
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ÁAn;EÑ­Ü4¼ |ddÕdQ,¨E
¬'µ{÷ÿœ/ª—Ö)æ`6Œ6×ÃD$¡D×Ó7BÉÓVúÂF%”œ+ä sÿà¯[Ý¡×É~ɓšo;^ÎÙg:-ü¨‰-GÝy†Of#”t·êë“s…äc#„^k$ê&Þv¼œÝʝš¨;ig¿äùÁß¿þ|ýûæi垄’~ÔäpK‘qÑ¢Ø{ˆ+µ±ÜjJ~¿Z{Ø ÌêÉc¦È¸hQlˆ=D‹•Ú°Q9\‰Qæób¹•ÎnåN MÎn"D·ÄŽåV/Î’û †&êÎ~ɓ‘œ+ãöÁ©¹¼²³Üéó¨I(Ù/yb‰º_ØòOŒ?^ُYî¼Òu§Ìê‰ºÓæz˜hñãù‰Q¯a(ìÇ,wŠ­ž„’yʬžç
É–¨;‡›z2¡¤Ì깡îôãíɹBòÁêeVg6Ô=ó|Q½¶L1³a´¹&" %ºž¾Jž¶Ò6*¡ä\!_˜˜£øÝêF½ÖHöKžÄÐÄxÛñrÎ>ÓiáGMl9êÎ3¼x2¡¤»U_Ÿœ+$!ôZ#Q7ñ¶ãåìVîÄÐDÝI{8û%Ïþûþõçëß7O+÷$”´ð£&‡[ŠŒÛˆņØC´X©åV“PòûÕÚÃeVO3EÆmD‹bCì!Z¬Ô†ÊáJŒ2ŸË­tv+wbhrv!º%v,·zq®|løÛ14QwöKž„ˆä\¡·¾HÍå•ý˜åNŸGMBÉ~ÉKÔý–b´øñÊ~Ìr畞¨;eVOԝ6×ÃD‹ÏOŒz{Da?f¹Sl­ð$”ÌsPfõÜ8WH>°DÝ9|ÜԓÙ%eVÏu¤oOÎ’ÎPÇ(³:³¡î±˜çøà
Expand Down
Binary file added @ether/poc/deflate/corpus/text.txt.6.default.deflate
Binary file not shown.
Binary file not shown.
Binary file added @ether/poc/deflate/corpus/text.txt.6.fixed.deflate
Binary file not shown.
44 changes: 44 additions & 0 deletions @ether/poc/deflate/dp0.ray
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// DP0: each feature `Deflate.ray` uses, on a toy format of a few bits.

mark ^keyword := global

Pair := class (high: Binary₂, low: <-Binary₂) => { }
unless Pair.bits_read("1001").high == 2 { INFO@mark `DP0.1a a fixed-width field does not read most significant first` }
unless Pair.bits_read("1001").low == 2 { INFO@mark `DP0.1b a reversed field does not read least significant first` }

Kind := class (kind: Binary₂{< 3}) => { }
unless Kind.bits_read("10").kind == 2 { INFO@mark `DP0.2a a narrowed field does not read what holds` }
if Kind.bits_read("11") { INFO@mark `DP0.2b a narrowed field reads what does not hold` }

Either := class (items: ((small: Binary₂{< 2}) | (Binary₂{== 3}, big: Binary₃))[], Binary₂{== 2}) => { }
either := Either.bits_read("0111101" + "10")
unless either.items.count == 2 { INFO@mark `DP0.3a alternatives in a list do not read each element` }
unless either.items.first.small == 1 { INFO@mark `DP0.3b the first alternative's field is not read` }
unless either.items.last.big == 5 { INFO@mark `DP0.3c the second alternative's field is not read` }

Sized := class (size: Binary₂, values: (Binary₂)[]{length == size}) => { }
sized := Sized.bits_read("10" + "0111")
unless sized.values == [1, 3] { INFO@mark `DP0.4a a list as long as an earlier field does not read that many` }
if Sized.bits_read("10" + "01") { INFO@mark `DP0.4b a list shorter than its length is read` }

Tagged := class (tag: Binary₁, (wide: Binary₄) if tag == 1, (narrow: Binary₂) if tag == 0) => { }
unless Tagged.bits_read("11010").wide == 10 { INFO@mark `DP0.5a a piece whose condition holds is not read` }
unless Tagged.bits_read("010").narrow == 2 { INFO@mark `DP0.5b a piece whose condition does not hold is read` }
if Tagged.bits_read("010").wide !== None { INFO@mark `DP0.5c a piece not read has a value` }

Width := class (bits: Binary₁) => {
width => bits + 1
}
Inner := class<width: Width> (value: Binary{length == width.width}) => { }
Outer := class (width: Width, inner: Inner<width>) => { }
unless Outer.bits_read("1" + "10").inner.value == 2 { INFO@mark `DP0.6 a class given a value read before it does not read with it` }

Aligned := class (head: Binary₃, padding: Binary{(length < 8) && (((at + length) % 8) == 0)}, byte: Byte) => { }
aligned := Aligned.bits_read("101" + "00000" + "00000110")
unless aligned.byte == 6 { INFO@mark `DP0.7 the piece up to the byte boundary does not end there` }

Counted := class (count: Binary₂ = values.count, values: (Binary₂)[]{length == count}) => { }
unless Counted(values: [1, 2]).binary == "10" + "0110" { INFO@mark `DP0.8 a default is not computed when a value is written` }

unless Pair(high: 2, low: 2).binary == "1001" { INFO@mark `DP0.9a a value is not written back to its bits` }
unless Either.bits_read("0111101" + "10").binary == "0111101" + "10" { INFO@mark `DP0.9b a value read is not written back to the same bits` }
10 changes: 10 additions & 0 deletions @ether/poc/deflate/dp2.ray
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// DP2: the RFC's own cases, the claims of `$/deflate/tests/deflate.ray` DF1 to DF6.

mark ^keyword := global

unless Deflate.Huffman([3, 3, 3, 3, 3, 2, 4, 4]).codes.sort_by((code) => code.symbol).map((code) => code.bits) == [0b010, 0b011, 0b100, 0b101, 0b110, 0b00, 0b1110, 0b1111] { INFO@mark `DF1 the code lengths of section 3.2.2's example do not give its codes` }
unless (Deflate.fixed_literals.bits(0) == 0b00110000) && (Deflate.fixed_literals.bits(144) == 0b110010000) && (Deflate.fixed_literals.bits(256) == 0b0000000) { INFO@mark `DF2 the fixed literal codes are not those of section 3.2.6` }
unless Deflate.inflated([0x01, 0x05, 0x00, 0xfa, 0xff, "hello".bytes].flatten) == "hello".bytes { INFO@mark `DF3 a stored block does not read its bytes` }
unless Deflate.inflated([0x03, 0x00]).empty { INFO@mark `DF4 an empty fixed block is not empty` }
unless Deflate.inflated([0x4b, 0x04, 0x00]) == "a".bytes { INFO@mark `DF5 a literal with the fixed codes is not read` }
unless Deflate.inflated([0x4b, 0x84, 0x03, 0x00]) == "aaaaaaaaaa".bytes { INFO@mark `DF6 a back-reference overlapping what it writes is not copied` }
7 changes: 7 additions & 0 deletions @ether/poc/deflate/dp5.ray
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// DP5: data Ray writes from nothing, the claims of `$/deflate/tests/deflate.ray` DF7 and DF8.

mark ^keyword := global

repeated := ("ray " * 64).bytes
unless Deflate.inflated(Deflate.deflated(repeated)) == repeated { INFO@mark `DF7 written bytes do not read back` }
unless Deflate.deflated(repeated).count < repeated.count { INFO@mark `DF8 repeated bytes are not written shorter` }
Empty file.
1 change: 1 addition & 0 deletions @ether/poc/deflate/inputs/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
1 change: 1 addition & 0 deletions @ether/poc/deflate/inputs/one.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a
Binary file added @ether/poc/deflate/inputs/random.bin
Binary file not shown.
Loading
Loading