MCPcopy Create free account
hub / github.com/CashScript/cashscript / formatBitAuthScript

Function formatBitAuthScript

packages/utils/src/bitauth-script.ts:34–55  ·  view source on GitHub ↗
(bytecode: Script, sourceMap: string, sourceCode: string, sourceTags?: string)

Source from the content-addressed store, hash-verified

32}
33
34export function formatBitAuthScript(bytecode: Script, sourceMap: string, sourceCode: string, sourceTags?: string): string {
35 const locationData = sourceMapToLocationData(sourceMap);
36 const sourceLines = sourceCode.split('\n');
37
38 // Splice synthetic annotation lines (e.g. for-loop updates) into source and remap opcode lines
39 const insertions = buildInsertions(locationData, sourceLines, sourceTags);
40 const splicedSourceLines = spliceSyntheticSourceLines(sourceLines, insertions);
41 const splicedLocationData = updateLocationData(locationData, insertions);
42
43 // Group opcodes by display line and convert to ASM
44 const lineToAsm = buildLineToAsmMap(bytecode, splicedLocationData);
45
46 // Format output
47 const escapedLines = splicedSourceLines.map(escapeCommentChars);
48 const maxAsmLen = Math.max(...escapedLines.map((_, i) => (lineToAsm[i + 1] || '').length));
49 const maxSrcLen = Math.max(...escapedLines.map((l) => l.length));
50
51 return escapedLines.map((src, i) => {
52 const asm = lineToAsm[i + 1] || '';
53 return `${asm.padEnd(maxAsmLen)} /* ${src.padEnd(maxSrcLen)} */`;
54 }).join('\n');
55}
56
57// --- Helpers ---
58

Callers 2

Calls 5

sourceMapToLocationDataFunction · 0.85
buildInsertionsFunction · 0.85
updateLocationDataFunction · 0.85
buildLineToAsmMapFunction · 0.85

Tested by

no test coverage detected