@tact-lang/opcode
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -8,2 +8,10 @@ # Changelog | ||
## [0.0.12] - 2023-03-28 | ||
## Changed | ||
- Deterministic function name ordering | ||
## Added | ||
- `lazy_deployment_completed` and `get_abi_ipfs` to known methods | ||
## [0.0.11] - 2023-03-27 | ||
@@ -10,0 +18,0 @@ |
@@ -29,3 +29,2 @@ "use strict"; | ||
// Extract all methods | ||
let unknownIndex = 0; | ||
let extracted = new Map(); | ||
@@ -40,3 +39,3 @@ let callRefs = new Map(); | ||
// Add name to a map and assign name | ||
let name = '?fun_' + (unknownIndex++); | ||
let name = '?fun_ref_' + cell.hash().toString('hex').substring(0, 16); | ||
callRefs.set(k, name); | ||
@@ -58,7 +57,8 @@ // Render cell | ||
}); | ||
extracted.set(name, { ref: true, rendered: w.end(), src: cell, srcOffset: 0 }); | ||
extracted.set(name, { rendered: w.end(), src: cell, srcOffset: 0 }); | ||
return name; | ||
} | ||
let extractedDict = new Map(); | ||
for (let [key, value] of dict) { | ||
let name = knownMethods_1.knownMethods[key] || '?fun_' + (unknownIndex++); | ||
let name = knownMethods_1.knownMethods[key] || '?fun_' + key; | ||
let w = new Writer_1.Writer(); | ||
@@ -78,4 +78,4 @@ w.inIndent(() => { | ||
}); | ||
extracted.set(name, { | ||
ref: false, | ||
extractedDict.set(key, { | ||
name, | ||
rendered: w.end(), | ||
@@ -86,11 +86,21 @@ src: value.cell, | ||
} | ||
// Sort and filter | ||
let dictKeys = Array.from(extractedDict.keys()).sort((a, b) => a - b); | ||
let refsKeys = Array.from(extracted.keys()).sort(); | ||
// Render methods | ||
writer.append(printer(`PROGRAM{`, writer.indent)); | ||
writer.inIndent(() => { | ||
for (let [key] of extracted) { | ||
// Declarations | ||
for (let key of dictKeys) { | ||
let value = extractedDict.get(key); | ||
writer.append(printer(`DECLPROC ${value.name};`, writer.indent)); | ||
} | ||
for (let key of refsKeys) { | ||
writer.append(printer(`DECLPROC ${key};`, writer.indent)); | ||
} | ||
for (let [key, value] of extracted) { | ||
// Dicts | ||
for (let key of dictKeys) { | ||
let value = extractedDict.get(key); | ||
let hash = value.src.hash().toString('hex'); | ||
let opstr = `${key} ${value.ref ? 'PROCREF' : 'PROC'}:<{`; | ||
let opstr = `${value.name} PROC:<{`; | ||
writer.append(printer({ op: opstr, offset: value.srcOffset, length: 0, hash }, writer.indent)); | ||
@@ -105,2 +115,16 @@ writer.inIndent(() => { | ||
} | ||
// Refs | ||
for (let key of refsKeys) { | ||
let value = extracted.get(key); | ||
let hash = value.src.hash().toString('hex'); | ||
let opstr = `${key} PROCREF:<{`; | ||
writer.append(printer({ op: opstr, offset: value.srcOffset, length: 0, hash }, writer.indent)); | ||
writer.inIndent(() => { | ||
value.rendered.split('\n').forEach(line => { | ||
writer.append(line); // Already formatted | ||
}); | ||
}); | ||
opstr = `}>`; | ||
writer.append(printer({ op: opstr, offset: value.srcOffset, length: 0, hash }, writer.indent)); | ||
} | ||
}); | ||
@@ -107,0 +131,0 @@ writer.append(printer(`}END>c`, writer.indent)); |
@@ -34,4 +34,6 @@ "use strict"; | ||
[113617]: 'supported_interfaces', | ||
[115390]: 'lazy_deployment_completed', | ||
[116695]: 'get_reveal_mode', | ||
[118054]: 'get_username', | ||
[121275]: 'get_abi_ipfs', | ||
[122498]: 'get_telemint_auction_state', | ||
@@ -38,0 +40,0 @@ [123660]: 'dnsresolve', |
{ | ||
"name": "@tact-lang/opcode", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/tact-lang/ton-opcode.git", |
@@ -39,4 +39,3 @@ import { Cell, Dictionary, DictionaryValue } from "ton-core"; | ||
// Extract all methods | ||
let unknownIndex = 0; | ||
let extracted = new Map<string, { ref: boolean, rendered: string, src: Cell, srcOffset: number }>(); | ||
let extracted = new Map<string, { rendered: string, src: Cell, srcOffset: number }>(); | ||
let callRefs = new Map<string, string>(); | ||
@@ -52,3 +51,3 @@ function extractCallRef(cell: Cell) { | ||
// Add name to a map and assign name | ||
let name = '?fun_' + (unknownIndex++); | ||
let name = '?fun_ref_' + cell.hash().toString('hex').substring(0, 16); | ||
callRefs.set(k, name); | ||
@@ -71,7 +70,9 @@ | ||
}); | ||
extracted.set(name, { ref: true, rendered: w.end(), src: cell, srcOffset: 0 }); | ||
extracted.set(name, { rendered: w.end(), src: cell, srcOffset: 0 }); | ||
return name; | ||
} | ||
let extractedDict = new Map<number, { name: string, rendered: string, src: Cell, srcOffset: number }>(); | ||
for (let [key, value] of dict) { | ||
let name = knownMethods[key] || '?fun_' + (unknownIndex++); | ||
let name = knownMethods[key] || '?fun_' + key; | ||
let w = new Writer(); | ||
@@ -91,4 +92,4 @@ w.inIndent(() => { | ||
}); | ||
extracted.set(name, { | ||
ref: false, | ||
extractedDict.set(key, { | ||
name, | ||
rendered: w.end(), | ||
@@ -100,11 +101,24 @@ src: value.cell, | ||
// Sort and filter | ||
let dictKeys = Array.from(extractedDict.keys()).sort((a, b) => a - b); | ||
let refsKeys = Array.from(extracted.keys()).sort(); | ||
// Render methods | ||
writer.append(printer(`PROGRAM{`, writer.indent)); | ||
writer.inIndent(() => { | ||
for (let [key] of extracted) { | ||
// Declarations | ||
for (let key of dictKeys) { | ||
let value = extractedDict.get(key)!; | ||
writer.append(printer(`DECLPROC ${value.name};`, writer.indent)); | ||
} | ||
for (let key of refsKeys) { | ||
writer.append(printer(`DECLPROC ${key};`, writer.indent)); | ||
} | ||
for (let [key, value] of extracted) { | ||
// Dicts | ||
for (let key of dictKeys) { | ||
let value = extractedDict.get(key)!; | ||
let hash = value.src.hash().toString('hex'); | ||
let opstr = `${key} ${value.ref ? 'PROCREF' : 'PROC'}:<{`; | ||
let opstr = `${value.name} PROC:<{`; | ||
writer.append(printer({ op: opstr, offset: value.srcOffset, length: 0, hash }, writer.indent)); | ||
@@ -119,2 +133,16 @@ writer.inIndent(() => { | ||
} | ||
// Refs | ||
for (let key of refsKeys) { | ||
let value = extracted.get(key)!; | ||
let hash = value.src.hash().toString('hex'); | ||
let opstr = `${key} PROCREF:<{`; | ||
writer.append(printer({ op: opstr, offset: value.srcOffset, length: 0, hash }, writer.indent)); | ||
writer.inIndent(() => { | ||
value.rendered.split('\n').forEach(line => { | ||
writer.append(line); // Already formatted | ||
}); | ||
}); | ||
opstr = `}>`; | ||
writer.append(printer({ op: opstr, offset: value.srcOffset, length: 0, hash }, writer.indent)); | ||
} | ||
}); | ||
@@ -121,0 +149,0 @@ writer.append(printer(`}END>c`, writer.indent)); |
@@ -31,4 +31,6 @@ export const knownMethods: { [key: number]: string } = { | ||
[113617]: 'supported_interfaces', | ||
[115390]: 'lazy_deployment_completed', | ||
[116695]: 'get_reveal_mode', | ||
[118054]: 'get_username', | ||
[121275]: 'get_abi_ipfs', | ||
[122498]: 'get_telemint_auction_state', | ||
@@ -35,0 +37,0 @@ [123660]: 'dnsresolve', |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6105724
6168