diff --git a/src/ast.ts b/src/ast.ts index e8aae94..f5aece5 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -91,6 +91,12 @@ export type TLBVarIntegerType = { n: TLBMathExpr; } +export type TLBHashmapType = { + kind: "TLBHashmapType"; + key: TLBMathExprType, + value: TLBFieldType +} + export type TLBCellType = { kind: "TLBCellType"; }; @@ -136,6 +142,7 @@ export type TLBFieldType = | TLBBoolType | TLBCoinsType | TLBAddressType + | TLBHashmapType | TLBVarIntegerType | TLBCellType | TLBMathExprType diff --git a/src/astbuilder/fill_constructors.ts b/src/astbuilder/fill_constructors.ts index b20dc80..6c8559a 100644 --- a/src/astbuilder/fill_constructors.ts +++ b/src/astbuilder/fill_constructors.ts @@ -432,6 +432,7 @@ function checkAndRemovePrimitives( typesToDelete.set("MsgAddress", ["606aa05e", "21d0382b"]) typesToDelete.set("VarUInteger", ["11d56c2e"]) typesToDelete.set("VarInteger", ["d466ed5"]) + typesToDelete.set("HashmapE", ["32bae5cb", "28fa3979"]) typesToDelete.forEach((opCodesExpected: string[], typeName: string) => { let typeItems = typeDeclarations.get(typeName); diff --git a/src/astbuilder/handle_type.ts b/src/astbuilder/handle_type.ts index 5c4fdc3..ea9af99 100644 --- a/src/astbuilder/handle_type.ts +++ b/src/astbuilder/handle_type.ts @@ -161,6 +161,16 @@ export function getType( constructor ), }; + } else if (expr.name == "HashmapE") { + if (expr.args.length != 2) { + throw new Error('') + } + let key = getType(expr.args[0], constructor, fieldTypeName) + let value = getType(expr.args[1], constructor, fieldTypeName) + if (key.kind != 'TLBExprMathType') { + throw new Error('Hashmap key should be number') + } + return { kind: "TLBHashmapType", key: key, value: value }; } else if ( expr.name == "VarUInteger" && (expr.args[0] instanceof MathExpr || diff --git a/src/generators/typescript/complex_expr.ts b/src/generators/typescript/complex_expr.ts index 7d6a08f..c6d02e0 100644 --- a/src/generators/typescript/complex_expr.ts +++ b/src/generators/typescript/complex_expr.ts @@ -1,8 +1,8 @@ -import { TLBCode, TLBConstructorTag, TLBField } from "../../ast"; +import { TLBCode, TLBConstructorTag, TLBField, TLBHashmapType, TLBMathExprType } from "../../ast"; import { findNotReservedName, firstLower, getCurrentSlice } from "../../utils"; import { ConstructorContext } from "./generator"; -import { BinaryExpression, Expression, GenDeclaration, Identifier, Statement, TypeExpression, TypeParametersExpression, TypedIdentifier, id, tArrowFunctionExpression, tArrowFunctionType, tBinaryExpression, tDeclareVariable, tExpressionStatement, tForCycle, tFunctionCall, tFunctionDeclaration, tIfStatement, tMemberExpression, tMultiStatement, tNumericLiteral, tReturnStatement, tStringLiteral, tTypeParametersExpression, tTypeWithParameters, tTypedIdentifier, tUnaryOpExpression, toCode } from "./tsgen"; -import { ExprForParam, getNegationDerivationFunctionBody } from "./utils"; +import { BinaryExpression, Expression, GenDeclaration, Identifier, ObjectExpression, Statement, TypeExpression, TypeParametersExpression, TypedIdentifier, id, tArrowFunctionExpression, tArrowFunctionType, tBinaryExpression, tDeclareVariable, tExpressionStatement, tForCycle, tFunctionCall, tFunctionDeclaration, tIfStatement, tMemberExpression, tMultiStatement, tNumericLiteral, tObjectExpression, tObjectProperty, tReturnStatement, tStringLiteral, tTypeParametersExpression, tTypeWithParameters, tTypedIdentifier, tUnaryOpExpression, toCode } from "./tsgen"; +import { ExprForParam, convertToAST, getNegationDerivationFunctionBody, isBigIntExpr } from "./utils"; export function tEqualExpression(left: Expression, right: Expression) { return tBinaryExpression(left, '==', right) @@ -330,3 +330,41 @@ export function negationDerivationFuncDecl( ) ); } +export function dictStoreStmt(currentCell: string, storeParametersInside: Expression[], keyForStore: Expression, valueStore: ObjectExpression): Statement | undefined { + return tExpressionStatement(tFunctionCall(tMemberExpression(id(currentCell), id('storeDict')), storeParametersInside.concat([keyForStore, valueStore]))); +} +export function dictTypeParamExpr(fieldType: TLBHashmapType, typeParamExpr: TypeExpression): TypeExpression | undefined { + return tTypeWithParameters(id('Dictionary'), tTypeParametersExpression([(isBigIntExpr(fieldType.key) ? id('bigint') : id('number')), typeParamExpr])); +} +export function dictValueStore(typeParamExpr: TypeExpression, storeFunctionExpr: Expression) { + return tObjectExpression([ + tObjectProperty(id('serialize'), + tArrowFunctionExpression([tTypedIdentifier(id('arg'), typeParamExpr), tTypedIdentifier(id('builder'), id('Builder'))], [tExpressionStatement(tFunctionCall(tFunctionCall(storeFunctionExpr, [id('arg')]), [id('builder')]))]) + ), + tObjectProperty(id('parse'), + id("() => { throw new Error('Not implemented') }") + ) + ]); +} +export function dictLoadExpr(keyForLoad: Expression, loadFunctionExpr: Expression, currentSlice: string): Expression | undefined { + return tFunctionCall(tMemberExpression(id('Dictionary'), id('load')), [keyForLoad, dictValueLoad(loadFunctionExpr), id(currentSlice)]); +} +function dictValueLoad(loadFunctionExpr: Expression) { + return tObjectExpression([ + tObjectProperty(id('serialize'), + id("() => { throw new Error('Not implemented') }") + ), + tObjectProperty(id('parse'), + loadFunctionExpr + ) + ]); +} +export function dictKeyExpr(keyType: TLBMathExprType, ctx: ConstructorContext, objectId?: string): Expression { + let param: Expression; + if (objectId) { + param = convertToAST(keyType.expr, ctx.constructor, id(objectId)); + } else { + param = convertToAST(keyType.expr, ctx.constructor); + } + return tFunctionCall(tMemberExpression(id('Dictionary.Keys'), (isBigIntExpr(keyType) ? id('BigUint') : id('Uint'))), [param]); +} diff --git a/src/generators/typescript/generator.ts b/src/generators/typescript/generator.ts index d8c63ea..84f9c74 100644 --- a/src/generators/typescript/generator.ts +++ b/src/generators/typescript/generator.ts @@ -1,3 +1,4 @@ +import { Identifier } from "typescript"; import { TLBCode, TLBConstructor, @@ -62,7 +63,6 @@ import { TypeParametersExpression, TypedIdentifier, id, - tArrowFunctionExpression, tComment, tExpressionStatement, tFunctionCall, @@ -94,6 +94,7 @@ import { getTypeParametersExpression, isBigInt, } from "./utils"; +import { dictKeyExpr, dictLoadExpr, dictValueStore, dictTypeParamExpr, dictStoreStmt } from "./complex_expr"; /* @@ -589,9 +590,6 @@ export class TypescriptGenerator implements CodeGenerator { ); }); } else if (field.subFields.length == 0) { - if (field == undefined) { - throw new Error(""); - } let fieldInfo = this.handleType( field, field.fieldType, @@ -902,6 +900,25 @@ export class TypescriptGenerator implements CodeGenerator { if (subExprInfo.storeStmtInside) { result.storeStmtInside = storeInNewCell(currentCell, subExprInfo.storeStmtInside); } + } else if (fieldType.kind == "TLBHashmapType") { + let keyForLoad: Expression = dictKeyExpr(fieldType.key, ctx); + let keyForStore: Expression = dictKeyExpr(fieldType.key, ctx, ctx.typeName); + let subExprInfo = this.handleType( + field, + fieldType.value, + false, + ctx, + slicePrefix, + argIndex + ); + + if (subExprInfo.typeParamExpr && subExprInfo.loadFunctionExpr && subExprInfo.storeFunctionExpr) { + result.loadExpr = dictLoadExpr(keyForLoad, subExprInfo.loadFunctionExpr, currentSlice) + let valueStore = dictValueStore(subExprInfo.typeParamExpr, subExprInfo.storeFunctionExpr) + result.typeParamExpr = dictTypeParamExpr(fieldType, subExprInfo.typeParamExpr) + result.storeStmtInside = dictStoreStmt(currentCell, storeParametersInside, keyForStore, valueStore) + result.storeStmtOutside = dictStoreStmt(currentCell, storeParametersOutside, keyForStore, valueStore) + } } else if (fieldType.kind == "TLBNamedType" && fieldType.arguments.length) { let typeName = fieldType.name; @@ -1021,3 +1038,4 @@ export class TypescriptGenerator implements CodeGenerator { return result; } } + diff --git a/src/generators/typescript/utils.ts b/src/generators/typescript/utils.ts index 16dfda8..ab9ef17 100644 --- a/src/generators/typescript/utils.ts +++ b/src/generators/typescript/utils.ts @@ -3,6 +3,7 @@ import { TLBCode, TLBConstructor, TLBMathExpr, + TLBMathExprType, TLBNumberExpr, TLBNumberType, TLBParameter, @@ -215,6 +216,13 @@ export function getCondition(conditions: Array): Expression { } } +export function isBigIntExpr(fieldType: TLBMathExprType) { + if (fieldType.expr instanceof TLBNumberExpr && fieldType.expr.n <= 64) { + return false; + } + return true; +} + export function isBigInt(fieldType: TLBNumberType) { if (fieldType.bits instanceof TLBNumberExpr) { if (fieldType.bits.n <= 64) { diff --git a/src/main.ts b/src/main.ts index 86112f4..2db2d8e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -27,6 +27,8 @@ export function generate(tree: Program, input: string) { codeGenerator.addTonCoreClassUsage("Cell"); codeGenerator.addTonCoreClassUsage("Address"); codeGenerator.addTonCoreClassUsage("ExternalAddress"); + codeGenerator.addTonCoreClassUsage("Dictionary") + codeGenerator.addTonCoreClassUsage("DictionaryValue") codeGenerator.addBitLenFunction(); diff --git a/test/generated_files/generated_block.ts b/test/generated_files/generated_block.ts index 9d68097..6061141 100644 --- a/test/generated_files/generated_block.ts +++ b/test/generated_files/generated_block.ts @@ -5,6 +5,8 @@ import { BitString } from 'ton' import { Cell } from 'ton' import { Address } from 'ton' import { ExternalAddress } from 'ton' +import { Dictionary } from 'ton' +import { DictionaryValue } from 'ton' export function bitLen(n: number) { return n.toString(2).length;; } @@ -153,23 +155,6 @@ export interface Unary_unary_succ { readonly x: Unary; } -// hme_empty$0 {n:#} {X:Type} = HashmapE n X; - -// hme_root$1 {n:#} {X:Type} root:^(Hashmap n X) = HashmapE n X; - -export type HashmapE = HashmapE_hme_empty | HashmapE_hme_root; - -export interface HashmapE_hme_empty { - readonly kind: 'HashmapE_hme_empty'; - readonly n: number; -} - -export interface HashmapE_hme_root { - readonly kind: 'HashmapE_hme_root'; - readonly n: number; - readonly root: Hashmap; -} - // _ {n:#} _:(Hashmap n True) = BitstringSet n; export interface BitstringSet { @@ -395,7 +380,7 @@ extra_currencies$_ dict:(HashmapE 32 (VarUInteger 32)) export interface ExtraCurrencyCollection { readonly kind: 'ExtraCurrencyCollection'; - readonly dict: HashmapE; + readonly dict: Dictionary; } /* @@ -528,7 +513,7 @@ export interface StateInitWithLibs { readonly special: Maybe; readonly code: Maybe; readonly data: Maybe; - readonly library: HashmapE; + readonly library: Dictionary; } // simple_lib$_ public:Bool root:^Cell = SimpleLib; @@ -853,7 +838,7 @@ export interface ProcessedUpto { export interface ProcessedInfo { readonly kind: 'ProcessedInfo'; - readonly anon0: HashmapE; + readonly anon0: Dictionary; } // ihr_pending$_ import_lt:uint64 = IhrPendingSince; @@ -867,7 +852,7 @@ export interface IhrPendingSince { export interface IhrPendingInfo { readonly kind: 'IhrPendingInfo'; - readonly anon0: HashmapE; + readonly anon0: Dictionary; } /* @@ -1046,7 +1031,7 @@ export interface Transaction { readonly orig_status: AccountStatus; readonly end_status: AccountStatus; readonly in_msg: Maybe>; - readonly out_msgs: HashmapE>; + readonly out_msgs: Dictionary>; readonly total_fees: CurrencyCollection; readonly state_update: HASH_UPDATE; readonly description: TransactionDescr; @@ -1592,7 +1577,7 @@ export interface ShardStateUnsplit { readonly underload_history: number; readonly total_balance: CurrencyCollection; readonly total_validator_fees: CurrencyCollection; - readonly libraries: HashmapE; + readonly libraries: Dictionary; readonly master_ref: Maybe; readonly custom: Maybe; } @@ -1911,7 +1896,7 @@ export interface ShardDescr_shard_descr_new { export interface ShardHashes { readonly kind: 'ShardHashes'; - readonly anon0: HashmapE>; + readonly anon0: Dictionary>; } // bta_leaf$0 {X:Type} {Y:Type} extra:Y leaf:X = BinTreeAug X Y; @@ -2039,7 +2024,7 @@ export type BlockCreateStats = BlockCreateStats_block_create_stats | BlockCreate export interface BlockCreateStats_block_create_stats { readonly kind: 'BlockCreateStats_block_create_stats'; - readonly counters: HashmapE; + readonly counters: Dictionary; } export interface BlockCreateStats_block_create_stats_ext { @@ -2161,7 +2146,7 @@ export interface McBlockExtra { readonly key_block: number; readonly shard_hashes: ShardHashes; readonly shard_fees: ShardFees; - readonly prev_blk_signatures: HashmapE; + readonly prev_blk_signatures: Dictionary; readonly recover_create_msg: Maybe; readonly mint_msg: Maybe; readonly config: ConfigParams | undefined; @@ -2216,7 +2201,7 @@ export interface ValidatorSet_validators_ext { readonly total: number; readonly main: number; readonly total_weight: number; - readonly list: HashmapE; + readonly list: Dictionary; } // _ config_addr:bits256 = ConfigParam 0; @@ -2384,7 +2369,7 @@ export interface ConfigParam__11 { export interface ConfigParam__12 { readonly kind: 'ConfigParam__12'; - readonly workchains: HashmapE; + readonly workchains: Dictionary; } export interface ConfigParam__13 { @@ -2472,7 +2457,7 @@ export interface ConfigParam__27 { export interface ConfigParam__28 { readonly kind: 'ConfigParam__28'; - readonly fundamental_smc_addr: HashmapE; + readonly fundamental_smc_addr: Dictionary; } export interface ConfigParam__29 { @@ -2507,7 +2492,7 @@ export interface ConfigParam__34 { export interface ConfigParam__35 { readonly kind: 'ConfigParam__35'; - readonly anon0: HashmapE; + readonly anon0: Dictionary; } export interface ConfigParam__36 { @@ -2621,7 +2606,7 @@ export interface ConfigProposalStatus { readonly expires: number; readonly proposal: ConfigProposal; readonly is_critical: boolean; - readonly voters: HashmapE; + readonly voters: Dictionary; readonly remaining_weight: number; readonly validator_set_id: bigint; readonly rounds_remaining: number; @@ -3050,7 +3035,7 @@ export interface SizeLimitsConfig_size_limits_config_v2 { export interface SuspendedAddressList { readonly kind: 'SuspendedAddressList'; - readonly addresses: HashmapE; + readonly addresses: Dictionary; readonly suspended_until: number; } @@ -3060,7 +3045,7 @@ export interface OracleBridgeParams { readonly kind: 'OracleBridgeParams'; readonly bridge_address: BitString; readonly oracle_mutlisig_address: BitString; - readonly oracles: HashmapE; + readonly oracles: Dictionary; readonly external_chain_address: BitString; } @@ -3092,7 +3077,7 @@ export interface JettonBridgeParams_jetton_bridge_params_v0 { readonly kind: 'JettonBridgeParams_jetton_bridge_params_v0'; readonly bridge_address: BitString; readonly oracles_address: BitString; - readonly oracles: HashmapE; + readonly oracles: Dictionary; readonly state_flags: number; readonly burn_bridge_fee: Coins; } @@ -3101,7 +3086,7 @@ export interface JettonBridgeParams_jetton_bridge_params_v1 { readonly kind: 'JettonBridgeParams_jetton_bridge_params_v1'; readonly bridge_address: BitString; readonly oracles_address: BitString; - readonly oracles: HashmapE; + readonly oracles: Dictionary; readonly state_flags: number; readonly prices: JettonBridgePrices; readonly external_chain_address: BitString; @@ -3116,7 +3101,7 @@ export interface BlockSignaturesPure { readonly kind: 'BlockSignaturesPure'; readonly sig_count: number; readonly sig_weight: number; - readonly signatures: HashmapE; + readonly signatures: Dictionary; } // block_signatures#11 validator_info:ValidatorBaseInfo pure_signatures:BlockSignaturesPure = BlockSignatures; @@ -3170,7 +3155,7 @@ export interface TopBlockDescr { export interface TopBlockDescrSet { readonly kind: 'TopBlockDescrSet'; - readonly collection: HashmapE; + readonly collection: Dictionary; } /* @@ -3223,7 +3208,7 @@ export interface ValidatorComplaint { export interface ValidatorComplaintStatus { readonly kind: 'ValidatorComplaintStatus'; readonly complaint: ValidatorComplaint; - readonly voters: HashmapE; + readonly voters: Dictionary; readonly vset_id: bigint; readonly weight_remaining: number; } @@ -3375,7 +3360,7 @@ export interface VmStackList_vm_stk_cons { export interface VmSaveList { readonly kind: 'VmSaveList'; - readonly cregs: HashmapE; + readonly cregs: Dictionary; } /* @@ -3395,7 +3380,7 @@ export interface VmGasLimits { export interface VmLibraries { readonly kind: 'VmLibraries'; - readonly libraries: HashmapE; + readonly libraries: Dictionary; } /* @@ -3502,7 +3487,7 @@ export interface VmCont_vmc_pushint { export interface DNS_RecordSet { readonly kind: 'DNS_RecordSet'; - readonly anon0: HashmapE; + readonly anon0: Dictionary; } // chunk_ref_empty$_ = TextChunkRef 0; @@ -4224,52 +4209,6 @@ export function storeUnary(unary: Unary): (builder: Builder) => void { throw new Error('Expected one of "Unary_unary_zero", "Unary_unary_succ" in loading "Unary", but data does not satisfy any constructor'); } -// hme_empty$0 {n:#} {X:Type} = HashmapE n X; - -// hme_root$1 {n:#} {X:Type} root:^(Hashmap n X) = HashmapE n X; - -export function loadHashmapE(slice: Slice, n: number, loadX: (slice: Slice) => X): HashmapE { - if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) { - slice.loadUint(1); - return { - kind: 'HashmapE_hme_empty', - n: n, - } - - } - if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) { - slice.loadUint(1); - let slice1 = slice.loadRef().beginParse(); - let root: Hashmap = loadHashmap(slice1, n, loadX); - return { - kind: 'HashmapE_hme_root', - n: n, - root: root, - } - - } - throw new Error('Expected one of "HashmapE_hme_empty", "HashmapE_hme_root" in loading "HashmapE", but data does not satisfy any constructor'); -} - -export function storeHashmapE(hashmapE: HashmapE, storeX: (x: X) => (builder: Builder) => void): (builder: Builder) => void { - if ((hashmapE.kind == 'HashmapE_hme_empty')) { - return ((builder: Builder) => { - builder.storeUint(0b0, 1); - }) - - } - if ((hashmapE.kind == 'HashmapE_hme_root')) { - return ((builder: Builder) => { - builder.storeUint(0b1, 1); - let cell1 = beginCell(); - storeHashmap(hashmapE.root, storeX)(cell1); - builder.storeRef(cell1); - }) - - } - throw new Error('Expected one of "HashmapE_hme_empty", "HashmapE_hme_root" in loading "HashmapE", but data does not satisfy any constructor'); -} - // _ {n:#} _:(Hashmap n True) = BitstringSet n; export function loadBitstringSet(slice: Slice, n: number): BitstringSet { @@ -4853,10 +4792,13 @@ extra_currencies$_ dict:(HashmapE 32 (VarUInteger 32)) */ export function loadExtraCurrencyCollection(slice: Slice): ExtraCurrencyCollection { - let dict: HashmapE = loadHashmapE(slice, 32, ((slice: Slice) => { + let dict: Dictionary = Dictionary.load(Dictionary.Keys.Uint(32), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { return slice.loadVarUintBig(bitLen((32 - 1))) - })); + }), + }, slice); return { kind: 'ExtraCurrencyCollection', dict: dict, @@ -4866,12 +4808,17 @@ export function loadExtraCurrencyCollection(slice: Slice): ExtraCurrencyCollecti export function storeExtraCurrencyCollection(extraCurrencyCollection: ExtraCurrencyCollection): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapE(extraCurrencyCollection.dict, ((arg: bigint) => { - return ((builder: Builder) => { - builder.storeVarUint(arg, bitLen((32 - 1))); - }) + builder.storeDict(extraCurrencyCollection.dict, Dictionary.Keys.Uint(32), { + serialize: ((arg: bigint, builder: Builder) => { + ((arg: bigint) => { + return ((builder: Builder) => { + builder.storeVarUint(arg, bitLen((32 - 1))); + }) - }))(builder); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -5224,7 +5171,10 @@ export function loadStateInitWithLibs(slice: Slice): StateInitWithLibs { return slice1 })); - let library: HashmapE = loadHashmapE(slice, 256, loadSimpleLib); + let library: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadSimpleLib, + }, slice); return { kind: 'StateInitWithLibs', split_depth: split_depth, @@ -5263,7 +5213,12 @@ export function storeStateInitWithLibs(stateInitWithLibs: StateInitWithLibs): (b }) }))(builder); - storeHashmapE(stateInitWithLibs.library, storeSimpleLib)(builder); + builder.storeDict(stateInitWithLibs.library, Dictionary.Keys.BigUint(256), { + serialize: ((arg: SimpleLib, builder: Builder) => { + storeSimpleLib(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -6214,7 +6169,10 @@ export function storeProcessedUpto(processedUpto: ProcessedUpto): (builder: Buil // _ (HashmapE 96 ProcessedUpto) = ProcessedInfo; export function loadProcessedInfo(slice: Slice): ProcessedInfo { - let anon0: HashmapE = loadHashmapE(slice, 96, loadProcessedUpto); + let anon0: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(96), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadProcessedUpto, + }, slice); return { kind: 'ProcessedInfo', anon0: anon0, @@ -6224,7 +6182,12 @@ export function loadProcessedInfo(slice: Slice): ProcessedInfo { export function storeProcessedInfo(processedInfo: ProcessedInfo): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapE(processedInfo.anon0, storeProcessedUpto)(builder); + builder.storeDict(processedInfo.anon0, Dictionary.Keys.BigUint(96), { + serialize: ((arg: ProcessedUpto, builder: Builder) => { + storeProcessedUpto(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -6250,7 +6213,10 @@ export function storeIhrPendingSince(ihrPendingSince: IhrPendingSince): (builder // _ (HashmapE 320 IhrPendingSince) = IhrPendingInfo; export function loadIhrPendingInfo(slice: Slice): IhrPendingInfo { - let anon0: HashmapE = loadHashmapE(slice, 320, loadIhrPendingSince); + let anon0: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(320), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadIhrPendingSince, + }, slice); return { kind: 'IhrPendingInfo', anon0: anon0, @@ -6260,7 +6226,12 @@ export function loadIhrPendingInfo(slice: Slice): IhrPendingInfo { export function storeIhrPendingInfo(ihrPendingInfo: IhrPendingInfo): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapE(ihrPendingInfo.anon0, storeIhrPendingSince)(builder); + builder.storeDict(ihrPendingInfo.anon0, Dictionary.Keys.BigUint(320), { + serialize: ((arg: IhrPendingSince, builder: Builder) => { + storeIhrPendingSince(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -6682,14 +6653,17 @@ export function loadTransaction(slice: Slice): Transaction { })) })); - let out_msgs: HashmapE> = loadHashmapE>(slice1, 15, ((slice: Slice) => { + let out_msgs: Dictionary> = Dictionary.load(Dictionary.Keys.Uint(15), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(); return loadMessage(slice1, ((slice: Slice) => { return slice })) - })); + }), + }, slice1); let total_fees: CurrencyCollection = loadCurrencyCollection(slice); let slice2 = slice.loadRef().beginParse(); let state_update: HASH_UPDATE = loadHASH_UPDATE(slice2, loadAccount); @@ -6742,20 +6716,25 @@ export function storeTransaction(transaction: Transaction): (builder: Builder) = }) }))(cell1); - storeHashmapE>(transaction.out_msgs, ((arg: Message) => { - return ((builder: Builder) => { - let cell1 = beginCell(); - storeMessage(arg, ((arg: Slice) => { - return ((builder: Builder) => { - builder.storeSlice(arg); - }) + cell1.storeDict(transaction.out_msgs, Dictionary.Keys.Uint(15), { + serialize: ((arg: Message, builder: Builder) => { + ((arg: Message) => { + return ((builder: Builder) => { + let cell1 = beginCell(); + storeMessage(arg, ((arg: Slice) => { + return ((builder: Builder) => { + builder.storeSlice(arg); + }) - }))(cell1); - builder.storeRef(cell1); + }))(cell1); + builder.storeRef(cell1); - }) + }) - }))(cell1); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); builder.storeRef(cell1); storeCurrencyCollection(transaction.total_fees)(builder); let cell2 = beginCell(); @@ -8180,7 +8159,10 @@ export function loadShardStateUnsplit(slice: Slice): ShardStateUnsplit { let underload_history: number = slice3.loadUint(64); let total_balance: CurrencyCollection = loadCurrencyCollection(slice3); let total_validator_fees: CurrencyCollection = loadCurrencyCollection(slice3); - let libraries: HashmapE = loadHashmapE(slice3, 256, loadLibDescr); + let libraries: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadLibDescr, + }, slice3); let master_ref: Maybe = loadMaybe(slice3, loadBlkMasterInfo); let custom: Maybe = loadMaybe(slice, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(); @@ -8234,7 +8216,12 @@ export function storeShardStateUnsplit(shardStateUnsplit: ShardStateUnsplit): (b cell3.storeUint(shardStateUnsplit.underload_history, 64); storeCurrencyCollection(shardStateUnsplit.total_balance)(cell3); storeCurrencyCollection(shardStateUnsplit.total_validator_fees)(cell3); - storeHashmapE(shardStateUnsplit.libraries, storeLibDescr)(cell3); + cell3.storeDict(shardStateUnsplit.libraries, Dictionary.Keys.BigUint(256), { + serialize: ((arg: LibDescr, builder: Builder) => { + storeLibDescr(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); storeMaybe(shardStateUnsplit.master_ref, storeBlkMasterInfo)(cell3); builder.storeRef(cell3); storeMaybe(shardStateUnsplit.custom, ((arg: McStateExtra) => { @@ -9094,11 +9081,14 @@ export function storeShardDescr(shardDescr: ShardDescr): (builder: Builder) => v // _ (HashmapE 32 ^(BinTree ShardDescr)) = ShardHashes; export function loadShardHashes(slice: Slice): ShardHashes { - let anon0: HashmapE> = loadHashmapE>(slice, 32, ((slice: Slice) => { + let anon0: Dictionary> = Dictionary.load(Dictionary.Keys.Uint(32), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(); return loadBinTree(slice1, loadShardDescr) - })); + }), + }, slice); return { kind: 'ShardHashes', anon0: anon0, @@ -9108,15 +9098,20 @@ export function loadShardHashes(slice: Slice): ShardHashes { export function storeShardHashes(shardHashes: ShardHashes): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapE>(shardHashes.anon0, ((arg: BinTree) => { - return ((builder: Builder) => { - let cell1 = beginCell(); - storeBinTree(arg, storeShardDescr)(cell1); - builder.storeRef(cell1); + builder.storeDict(shardHashes.anon0, Dictionary.Keys.Uint(32), { + serialize: ((arg: BinTree, builder: Builder) => { + ((arg: BinTree) => { + return ((builder: Builder) => { + let cell1 = beginCell(); + storeBinTree(arg, storeShardDescr)(cell1); + builder.storeRef(cell1); - }) + }) - }))(builder); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -9437,7 +9432,10 @@ export function storeCreatorStats(creatorStats: CreatorStats): (builder: Builder export function loadBlockCreateStats(slice: Slice): BlockCreateStats { if (((slice.remainingBits >= 8) && (slice.preloadUint(8) == 0x17))) { slice.loadUint(8); - let counters: HashmapE = loadHashmapE(slice, 256, loadCreatorStats); + let counters: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadCreatorStats, + }, slice); return { kind: 'BlockCreateStats_block_create_stats', counters: counters, @@ -9463,7 +9461,12 @@ export function storeBlockCreateStats(blockCreateStats: BlockCreateStats): (buil if ((blockCreateStats.kind == 'BlockCreateStats_block_create_stats')) { return ((builder: Builder) => { builder.storeUint(0x17, 8); - storeHashmapE(blockCreateStats.counters, storeCreatorStats)(builder); + builder.storeDict(blockCreateStats.counters, Dictionary.Keys.BigUint(256), { + serialize: ((arg: CreatorStats, builder: Builder) => { + storeCreatorStats(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -9762,7 +9765,10 @@ export function loadMcBlockExtra(slice: Slice): McBlockExtra { let shard_hashes: ShardHashes = loadShardHashes(slice); let shard_fees: ShardFees = loadShardFees(slice); let slice1 = slice.loadRef().beginParse(); - let prev_blk_signatures: HashmapE = loadHashmapE(slice1, 16, loadCryptoSignaturePair); + let prev_blk_signatures: Dictionary = Dictionary.load(Dictionary.Keys.Uint(16), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadCryptoSignaturePair, + }, slice1); let recover_create_msg: Maybe = loadMaybe(slice1, ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(); return loadInMsg(slice1) @@ -9796,7 +9802,12 @@ export function storeMcBlockExtra(mcBlockExtra: McBlockExtra): (builder: Builder storeShardHashes(mcBlockExtra.shard_hashes)(builder); storeShardFees(mcBlockExtra.shard_fees)(builder); let cell1 = beginCell(); - storeHashmapE(mcBlockExtra.prev_blk_signatures, storeCryptoSignaturePair)(cell1); + cell1.storeDict(mcBlockExtra.prev_blk_signatures, Dictionary.Keys.Uint(16), { + serialize: ((arg: CryptoSignaturePair, builder: Builder) => { + storeCryptoSignaturePair(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); storeMaybe(mcBlockExtra.recover_create_msg, ((arg: InMsg) => { return ((builder: Builder) => { let cell1 = beginCell(); @@ -9919,7 +9930,10 @@ export function loadValidatorSet(slice: Slice): ValidatorSet { let total: number = slice.loadUint(16); let main: number = slice.loadUint(16); let total_weight: number = slice.loadUint(64); - let list: HashmapE = loadHashmapE(slice, 16, loadValidatorDescr); + let list: Dictionary = Dictionary.load(Dictionary.Keys.Uint(16), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadValidatorDescr, + }, slice); if ((!(main <= total))) { throw new Error('Condition (main <= total) is not satisfied while loading "ValidatorSet_validators_ext" for type "ValidatorSet"'); } @@ -9966,7 +9980,12 @@ export function storeValidatorSet(validatorSet: ValidatorSet): (builder: Builder builder.storeUint(validatorSet.total, 16); builder.storeUint(validatorSet.main, 16); builder.storeUint(validatorSet.total_weight, 64); - storeHashmapE(validatorSet.list, storeValidatorDescr)(builder); + builder.storeDict(validatorSet.list, Dictionary.Keys.Uint(16), { + serialize: ((arg: ValidatorDescr, builder: Builder) => { + storeValidatorDescr(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); if ((!(validatorSet.main <= validatorSet.total))) { throw new Error('Condition (validatorSet.main <= validatorSet.total) is not satisfied while loading "ValidatorSet_validators_ext" for type "ValidatorSet"'); } @@ -10179,7 +10198,10 @@ export function loadConfigParam(slice: Slice, arg0: number): ConfigParam { } if ((arg0 == 12)) { - let workchains: HashmapE = loadHashmapE(slice, 32, loadWorkchainDescr); + let workchains: Dictionary = Dictionary.load(Dictionary.Keys.Uint(32), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadWorkchainDescr, + }, slice); return { kind: 'ConfigParam__12', workchains: workchains, @@ -10332,7 +10354,10 @@ export function loadConfigParam(slice: Slice, arg0: number): ConfigParam { } if ((arg0 == 31)) { - let fundamental_smc_addr: HashmapE = loadHashmapE(slice, 256, loadTrue); + let fundamental_smc_addr: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadTrue, + }, slice); return { kind: 'ConfigParam__28', fundamental_smc_addr: fundamental_smc_addr, @@ -10388,7 +10413,10 @@ export function loadConfigParam(slice: Slice, arg0: number): ConfigParam { } if ((arg0 == 39)) { - let anon0: HashmapE = loadHashmapE(slice, 256, loadValidatorSignedTempKey); + let anon0: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadValidatorSignedTempKey, + }, slice); return { kind: 'ConfigParam__35', anon0: anon0, @@ -10546,7 +10574,12 @@ export function storeConfigParam(configParam: ConfigParam): (builder: Builder) = } if ((configParam.kind == 'ConfigParam__12')) { return ((builder: Builder) => { - storeHashmapE(configParam.workchains, storeWorkchainDescr)(builder); + builder.storeDict(configParam.workchains, Dictionary.Keys.Uint(32), { + serialize: ((arg: WorkchainDescr, builder: Builder) => { + storeWorkchainDescr(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -10659,7 +10692,12 @@ export function storeConfigParam(configParam: ConfigParam): (builder: Builder) = } if ((configParam.kind == 'ConfigParam__28')) { return ((builder: Builder) => { - storeHashmapE(configParam.fundamental_smc_addr, storeTrue)(builder); + builder.storeDict(configParam.fundamental_smc_addr, Dictionary.Keys.BigUint(256), { + serialize: ((arg: True, builder: Builder) => { + storeTrue(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -10701,7 +10739,12 @@ export function storeConfigParam(configParam: ConfigParam): (builder: Builder) = } if ((configParam.kind == 'ConfigParam__35')) { return ((builder: Builder) => { - storeHashmapE(configParam.anon0, storeValidatorSignedTempKey)(builder); + builder.storeDict(configParam.anon0, Dictionary.Keys.BigUint(256), { + serialize: ((arg: ValidatorSignedTempKey, builder: Builder) => { + storeValidatorSignedTempKey(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -10982,7 +11025,10 @@ export function loadConfigProposalStatus(slice: Slice): ConfigProposalStatus { let slice1 = slice.loadRef().beginParse(); let proposal: ConfigProposal = loadConfigProposal(slice1); let is_critical: boolean = slice.loadBoolean(); - let voters: HashmapE = loadHashmapE(slice, 16, loadTrue); + let voters: Dictionary = Dictionary.load(Dictionary.Keys.Uint(16), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadTrue, + }, slice); let remaining_weight: number = slice.loadInt(64); let validator_set_id: bigint = slice.loadUintBig(256); let rounds_remaining: number = slice.loadUint(8); @@ -11013,7 +11059,12 @@ export function storeConfigProposalStatus(configProposalStatus: ConfigProposalSt storeConfigProposal(configProposalStatus.proposal)(cell1); builder.storeRef(cell1); builder.storeBit(configProposalStatus.is_critical); - storeHashmapE(configProposalStatus.voters, storeTrue)(builder); + builder.storeDict(configProposalStatus.voters, Dictionary.Keys.Uint(16), { + serialize: ((arg: True, builder: Builder) => { + storeTrue(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); builder.storeInt(configProposalStatus.remaining_weight, 64); builder.storeUint(configProposalStatus.validator_set_id, 256); builder.storeUint(configProposalStatus.rounds_remaining, 8); @@ -12185,7 +12236,10 @@ export function storeSizeLimitsConfig(sizeLimitsConfig: SizeLimitsConfig): (buil export function loadSuspendedAddressList(slice: Slice): SuspendedAddressList { if (((slice.remainingBits >= 8) && (slice.preloadUint(8) == 0x00))) { slice.loadUint(8); - let addresses: HashmapE = loadHashmapE(slice, 288, loadUnit); + let addresses: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(288), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadUnit, + }, slice); let suspended_until: number = slice.loadUint(32); return { kind: 'SuspendedAddressList', @@ -12200,7 +12254,12 @@ export function loadSuspendedAddressList(slice: Slice): SuspendedAddressList { export function storeSuspendedAddressList(suspendedAddressList: SuspendedAddressList): (builder: Builder) => void { return ((builder: Builder) => { builder.storeUint(0x00, 8); - storeHashmapE(suspendedAddressList.addresses, storeUnit)(builder); + builder.storeDict(suspendedAddressList.addresses, Dictionary.Keys.BigUint(288), { + serialize: ((arg: Unit, builder: Builder) => { + storeUnit(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); builder.storeUint(suspendedAddressList.suspended_until, 32); }) @@ -12211,10 +12270,13 @@ export function storeSuspendedAddressList(suspendedAddressList: SuspendedAddress export function loadOracleBridgeParams(slice: Slice): OracleBridgeParams { let bridge_address: BitString = slice.loadBits(256); let oracle_mutlisig_address: BitString = slice.loadBits(256); - let oracles: HashmapE = loadHashmapE(slice, 256, ((slice: Slice) => { + let oracles: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { return slice.loadUintBig(256) - })); + }), + }, slice); let external_chain_address: BitString = slice.loadBits(256); return { kind: 'OracleBridgeParams', @@ -12230,12 +12292,17 @@ export function storeOracleBridgeParams(oracleBridgeParams: OracleBridgeParams): return ((builder: Builder) => { builder.storeBits(oracleBridgeParams.bridge_address); builder.storeBits(oracleBridgeParams.oracle_mutlisig_address); - storeHashmapE(oracleBridgeParams.oracles, ((arg: bigint) => { - return ((builder: Builder) => { - builder.storeUint(arg, 256); - }) + builder.storeDict(oracleBridgeParams.oracles, Dictionary.Keys.BigUint(256), { + serialize: ((arg: bigint, builder: Builder) => { + ((arg: bigint) => { + return ((builder: Builder) => { + builder.storeUint(arg, 256); + }) - }))(builder); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); builder.storeBits(oracleBridgeParams.external_chain_address); }) @@ -12289,10 +12356,13 @@ export function loadJettonBridgeParams(slice: Slice): JettonBridgeParams { slice.loadUint(8); let bridge_address: BitString = slice.loadBits(256); let oracles_address: BitString = slice.loadBits(256); - let oracles: HashmapE = loadHashmapE(slice, 256, ((slice: Slice) => { + let oracles: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { return slice.loadUintBig(256) - })); + }), + }, slice); let state_flags: number = slice.loadUint(8); let burn_bridge_fee: Coins = loadCoins(slice); return { @@ -12309,10 +12379,13 @@ export function loadJettonBridgeParams(slice: Slice): JettonBridgeParams { slice.loadUint(8); let bridge_address: BitString = slice.loadBits(256); let oracles_address: BitString = slice.loadBits(256); - let oracles: HashmapE = loadHashmapE(slice, 256, ((slice: Slice) => { + let oracles: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { return slice.loadUintBig(256) - })); + }), + }, slice); let state_flags: number = slice.loadUint(8); let slice1 = slice.loadRef().beginParse(); let prices: JettonBridgePrices = loadJettonBridgePrices(slice1); @@ -12337,12 +12410,17 @@ export function storeJettonBridgeParams(jettonBridgeParams: JettonBridgeParams): builder.storeUint(0x00, 8); builder.storeBits(jettonBridgeParams.bridge_address); builder.storeBits(jettonBridgeParams.oracles_address); - storeHashmapE(jettonBridgeParams.oracles, ((arg: bigint) => { - return ((builder: Builder) => { - builder.storeUint(arg, 256); - }) + builder.storeDict(jettonBridgeParams.oracles, Dictionary.Keys.BigUint(256), { + serialize: ((arg: bigint, builder: Builder) => { + ((arg: bigint) => { + return ((builder: Builder) => { + builder.storeUint(arg, 256); + }) - }))(builder); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); builder.storeUint(jettonBridgeParams.state_flags, 8); storeCoins(jettonBridgeParams.burn_bridge_fee)(builder); }) @@ -12353,12 +12431,17 @@ export function storeJettonBridgeParams(jettonBridgeParams: JettonBridgeParams): builder.storeUint(0x01, 8); builder.storeBits(jettonBridgeParams.bridge_address); builder.storeBits(jettonBridgeParams.oracles_address); - storeHashmapE(jettonBridgeParams.oracles, ((arg: bigint) => { - return ((builder: Builder) => { - builder.storeUint(arg, 256); - }) + builder.storeDict(jettonBridgeParams.oracles, Dictionary.Keys.BigUint(256), { + serialize: ((arg: bigint, builder: Builder) => { + ((arg: bigint) => { + return ((builder: Builder) => { + builder.storeUint(arg, 256); + }) - }))(builder); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); builder.storeUint(jettonBridgeParams.state_flags, 8); let cell1 = beginCell(); storeJettonBridgePrices(jettonBridgeParams.prices)(cell1); @@ -12378,7 +12461,10 @@ block_signatures_pure#_ sig_count:uint32 sig_weight:uint64 export function loadBlockSignaturesPure(slice: Slice): BlockSignaturesPure { let sig_count: number = slice.loadUint(32); let sig_weight: number = slice.loadUint(64); - let signatures: HashmapE = loadHashmapE(slice, 16, loadCryptoSignaturePair); + let signatures: Dictionary = Dictionary.load(Dictionary.Keys.Uint(16), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadCryptoSignaturePair, + }, slice); return { kind: 'BlockSignaturesPure', sig_count: sig_count, @@ -12392,7 +12478,12 @@ export function storeBlockSignaturesPure(blockSignaturesPure: BlockSignaturesPur return ((builder: Builder) => { builder.storeUint(blockSignaturesPure.sig_count, 32); builder.storeUint(blockSignaturesPure.sig_weight, 64); - storeHashmapE(blockSignaturesPure.signatures, storeCryptoSignaturePair)(builder); + builder.storeDict(blockSignaturesPure.signatures, Dictionary.Keys.Uint(16), { + serialize: ((arg: CryptoSignaturePair, builder: Builder) => { + storeCryptoSignaturePair(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -12584,11 +12675,14 @@ export function storeTopBlockDescr(topBlockDescr: TopBlockDescr): (builder: Buil export function loadTopBlockDescrSet(slice: Slice): TopBlockDescrSet { if (((slice.remainingBits >= 32) && (slice.preloadUint(32) == 0x4ac789f3))) { slice.loadUint(32); - let collection: HashmapE = loadHashmapE(slice, 96, ((slice: Slice) => { + let collection: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(96), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(); return loadTopBlockDescr(slice1) - })); + }), + }, slice); return { kind: 'TopBlockDescrSet', collection: collection, @@ -12601,15 +12695,20 @@ export function loadTopBlockDescrSet(slice: Slice): TopBlockDescrSet { export function storeTopBlockDescrSet(topBlockDescrSet: TopBlockDescrSet): (builder: Builder) => void { return ((builder: Builder) => { builder.storeUint(0x4ac789f3, 32); - storeHashmapE(topBlockDescrSet.collection, ((arg: TopBlockDescr) => { - return ((builder: Builder) => { - let cell1 = beginCell(); - storeTopBlockDescr(arg)(cell1); - builder.storeRef(cell1); + builder.storeDict(topBlockDescrSet.collection, Dictionary.Keys.BigUint(96), { + serialize: ((arg: TopBlockDescr, builder: Builder) => { + ((arg: TopBlockDescr) => { + return ((builder: Builder) => { + let cell1 = beginCell(); + storeTopBlockDescr(arg)(cell1); + builder.storeRef(cell1); - }) + }) - }))(builder); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -12768,7 +12867,10 @@ export function loadValidatorComplaintStatus(slice: Slice): ValidatorComplaintSt slice.loadUint(8); let slice1 = slice.loadRef().beginParse(); let complaint: ValidatorComplaint = loadValidatorComplaint(slice1); - let voters: HashmapE = loadHashmapE(slice, 16, loadTrue); + let voters: Dictionary = Dictionary.load(Dictionary.Keys.Uint(16), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadTrue, + }, slice); let vset_id: bigint = slice.loadUintBig(256); let weight_remaining: number = slice.loadInt(64); return { @@ -12789,7 +12891,12 @@ export function storeValidatorComplaintStatus(validatorComplaintStatus: Validato let cell1 = beginCell(); storeValidatorComplaint(validatorComplaintStatus.complaint)(cell1); builder.storeRef(cell1); - storeHashmapE(validatorComplaintStatus.voters, storeTrue)(builder); + builder.storeDict(validatorComplaintStatus.voters, Dictionary.Keys.Uint(16), { + serialize: ((arg: True, builder: Builder) => { + storeTrue(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); builder.storeUint(validatorComplaintStatus.vset_id, 256); builder.storeInt(validatorComplaintStatus.weight_remaining, 64); }) @@ -13189,7 +13296,10 @@ export function storeVmStackList(vmStackList: VmStackList): (builder: Builder) = // _ cregs:(HashmapE 4 VmStackValue) = VmSaveList; export function loadVmSaveList(slice: Slice): VmSaveList { - let cregs: HashmapE = loadHashmapE(slice, 4, loadVmStackValue); + let cregs: Dictionary = Dictionary.load(Dictionary.Keys.Uint(4), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadVmStackValue, + }, slice); return { kind: 'VmSaveList', cregs: cregs, @@ -13199,7 +13309,12 @@ export function loadVmSaveList(slice: Slice): VmSaveList { export function storeVmSaveList(vmSaveList: VmSaveList): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapE(vmSaveList.cregs, storeVmStackValue)(builder); + builder.storeDict(vmSaveList.cregs, Dictionary.Keys.Uint(4), { + serialize: ((arg: VmStackValue, builder: Builder) => { + storeVmStackValue(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -13240,11 +13355,14 @@ export function storeVmGasLimits(vmGasLimits: VmGasLimits): (builder: Builder) = // _ libraries:(HashmapE 256 ^Cell) = VmLibraries; export function loadVmLibraries(slice: Slice): VmLibraries { - let libraries: HashmapE = loadHashmapE(slice, 256, ((slice: Slice) => { + let libraries: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(); return slice1 - })); + }), + }, slice); return { kind: 'VmLibraries', libraries: libraries, @@ -13254,15 +13372,20 @@ export function loadVmLibraries(slice: Slice): VmLibraries { export function storeVmLibraries(vmLibraries: VmLibraries): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapE(vmLibraries.libraries, ((arg: Slice) => { - return ((builder: Builder) => { - let cell1 = beginCell(); - cell1.storeSlice(arg); - builder.storeRef(cell1); + builder.storeDict(vmLibraries.libraries, Dictionary.Keys.BigUint(256), { + serialize: ((arg: Slice, builder: Builder) => { + ((arg: Slice) => { + return ((builder: Builder) => { + let cell1 = beginCell(); + cell1.storeSlice(arg); + builder.storeRef(cell1); - }) + }) - }))(builder); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -13576,11 +13699,14 @@ export function storeVmCont(vmCont: VmCont): (builder: Builder) => void { // _ (HashmapE 256 ^DNSRecord) = DNS_RecordSet; export function loadDNS_RecordSet(slice: Slice): DNS_RecordSet { - let anon0: HashmapE = loadHashmapE(slice, 256, ((slice: Slice) => { + let anon0: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(256), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { let slice1 = slice.loadRef().beginParse(); return loadDNSRecord(slice1) - })); + }), + }, slice); return { kind: 'DNS_RecordSet', anon0: anon0, @@ -13590,15 +13716,20 @@ export function loadDNS_RecordSet(slice: Slice): DNS_RecordSet { export function storeDNS_RecordSet(dNS_RecordSet: DNS_RecordSet): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapE(dNS_RecordSet.anon0, ((arg: DNSRecord) => { - return ((builder: Builder) => { - let cell1 = beginCell(); - storeDNSRecord(arg)(cell1); - builder.storeRef(cell1); + builder.storeDict(dNS_RecordSet.anon0, Dictionary.Keys.BigUint(256), { + serialize: ((arg: DNSRecord, builder: Builder) => { + ((arg: DNSRecord) => { + return ((builder: Builder) => { + let cell1 = beginCell(); + storeDNSRecord(arg)(cell1); + builder.storeRef(cell1); - }) + }) - }))(builder); + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } diff --git a/test/generated_files/generated_test.ts b/test/generated_files/generated_test.ts index 5818003..fc13bb9 100644 --- a/test/generated_files/generated_test.ts +++ b/test/generated_files/generated_test.ts @@ -5,6 +5,8 @@ import { BitString } from 'ton' import { Cell } from 'ton' import { Address } from 'ton' import { ExternalAddress } from 'ton' +import { Dictionary } from 'ton' +import { DictionaryValue } from 'ton' export function bitLen(n: number) { return n.toString(2).length;; } @@ -460,28 +462,11 @@ export interface HmLabel_hml_same { readonly n: number; } -// hme_empty$0 {n:#} {X:Type} = HashmapE n X; - -// hme_root$1 {n:#} {X:Type} root:^(Hashmap n X) = HashmapE n X; - -export type HashmapE = HashmapE_hme_empty | HashmapE_hme_root; - -export interface HashmapE_hme_empty { - readonly kind: 'HashmapE_hme_empty'; - readonly n: number; -} - -export interface HashmapE_hme_root { - readonly kind: 'HashmapE_hme_root'; - readonly n: number; - readonly root: Hashmap; -} - // a$_ x:(HashmapE 8 uint16) = HashmapEUser; export interface HashmapEUser { readonly kind: 'HashmapEUser'; - readonly x: HashmapE; + readonly x: Dictionary; } // _ a:(## 1) b:a?(## 32) = ConditionalField; @@ -719,6 +704,64 @@ export interface GramsUser { readonly g: bigint; } +// a$_ x:(HashmapE 100 VarUIntegerUser) = HashmapVUIUser; + +export interface HashmapVUIUser { + readonly kind: 'HashmapVUIUser'; + readonly x: Dictionary; +} + +// a$_ x:(HashmapE 100 ^TypedParam) = HashmapTPCell; + +export interface HashmapTPCell { + readonly kind: 'HashmapTPCell'; + readonly x: Dictionary; +} + +// a$_ {n:#} x:(HashmapE n uint5) = HashmapVarKey n; + +export interface HashmapVarKey { + readonly kind: 'HashmapVarKey'; + readonly n: number; + readonly x: Dictionary; +} + +// a$_ x:(HashmapVarKey 5) = HashmapVarKeyUser; + +export interface HashmapVarKeyUser { + readonly kind: 'HashmapVarKeyUser'; + readonly x: HashmapVarKey; +} + +// a$_ {n:#} x:(HashmapE (n+2) uint5) = HashmapExprKey n; + +export interface HashmapExprKey { + readonly kind: 'HashmapExprKey'; + readonly n: number; + readonly x: Dictionary; +} + +// a$_ x:(HashmapExprKey 5) = HashmapExprKeyUser; + +export interface HashmapExprKeyUser { + readonly kind: 'HashmapExprKeyUser'; + readonly x: HashmapExprKey; +} + +// a$_ {A: Type} x:(HashmapE 200 (OneComb A)) = HashmapOneComb A; + +export interface HashmapOneComb { + readonly kind: 'HashmapOneComb'; + readonly x: Dictionary>; +} + +// a$_ x:(HashmapOneComb uint5) = HashmapOneCombUser; + +export interface HashmapOneCombUser { + readonly kind: 'HashmapOneCombUser'; + readonly x: HashmapOneComb; +} + // tmpa$_ a:# b:# = Simple; export function loadSimple(slice: Slice): Simple { @@ -2140,59 +2183,16 @@ export function storeHmLabel(hmLabel: HmLabel): (builder: Builder) => void { throw new Error('Expected one of "HmLabel_hml_short", "HmLabel_hml_long", "HmLabel_hml_same" in loading "HmLabel", but data does not satisfy any constructor'); } -// hme_empty$0 {n:#} {X:Type} = HashmapE n X; - -// hme_root$1 {n:#} {X:Type} root:^(Hashmap n X) = HashmapE n X; - -export function loadHashmapE(slice: Slice, n: number, loadX: (slice: Slice) => X): HashmapE { - if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) { - slice.loadUint(1); - return { - kind: 'HashmapE_hme_empty', - n: n, - } - - } - if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) { - slice.loadUint(1); - let slice1 = slice.loadRef().beginParse(); - let root: Hashmap = loadHashmap(slice1, n, loadX); - return { - kind: 'HashmapE_hme_root', - n: n, - root: root, - } - - } - throw new Error('Expected one of "HashmapE_hme_empty", "HashmapE_hme_root" in loading "HashmapE", but data does not satisfy any constructor'); -} - -export function storeHashmapE(hashmapE: HashmapE, storeX: (x: X) => (builder: Builder) => void): (builder: Builder) => void { - if ((hashmapE.kind == 'HashmapE_hme_empty')) { - return ((builder: Builder) => { - builder.storeUint(0b0, 1); - }) - - } - if ((hashmapE.kind == 'HashmapE_hme_root')) { - return ((builder: Builder) => { - builder.storeUint(0b1, 1); - let cell1 = beginCell(); - storeHashmap(hashmapE.root, storeX)(cell1); - builder.storeRef(cell1); - }) - - } - throw new Error('Expected one of "HashmapE_hme_empty", "HashmapE_hme_root" in loading "HashmapE", but data does not satisfy any constructor'); -} - // a$_ x:(HashmapE 8 uint16) = HashmapEUser; export function loadHashmapEUser(slice: Slice): HashmapEUser { - let x: HashmapE = loadHashmapE(slice, 8, ((slice: Slice) => { + let x: Dictionary = Dictionary.load(Dictionary.Keys.Uint(8), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { return slice.loadUint(16) - })); + }), + }, slice); return { kind: 'HashmapEUser', x: x, @@ -2202,12 +2202,17 @@ export function loadHashmapEUser(slice: Slice): HashmapEUser { export function storeHashmapEUser(hashmapEUser: HashmapEUser): (builder: Builder) => void { return ((builder: Builder) => { - storeHashmapE(hashmapEUser.x, ((arg: number) => { - return ((builder: Builder) => { - builder.storeUint(arg, 16); - }) - - }))(builder); + builder.storeDict(hashmapEUser.x, Dictionary.Keys.Uint(8), { + serialize: ((arg: number, builder: Builder) => { + ((arg: number) => { + return ((builder: Builder) => { + builder.storeUint(arg, 16); + }) + + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); }) } @@ -2889,3 +2894,233 @@ export function storeGramsUser(gramsUser: GramsUser): (builder: Builder) => void } +// a$_ x:(HashmapE 100 VarUIntegerUser) = HashmapVUIUser; + +export function loadHashmapVUIUser(slice: Slice): HashmapVUIUser { + let x: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(100), { + serialize: () => { throw new Error('Not implemented') }, + parse: loadVarUIntegerUser, + }, slice); + return { + kind: 'HashmapVUIUser', + x: x, + } + +} + +export function storeHashmapVUIUser(hashmapVUIUser: HashmapVUIUser): (builder: Builder) => void { + return ((builder: Builder) => { + builder.storeDict(hashmapVUIUser.x, Dictionary.Keys.BigUint(100), { + serialize: ((arg: VarUIntegerUser, builder: Builder) => { + storeVarUIntegerUser(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); + }) + +} + +// a$_ x:(HashmapE 100 ^TypedParam) = HashmapTPCell; + +export function loadHashmapTPCell(slice: Slice): HashmapTPCell { + let x: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(100), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { + let slice1 = slice.loadRef().beginParse(); + return loadTypedParam(slice1) + + }), + }, slice); + return { + kind: 'HashmapTPCell', + x: x, + } + +} + +export function storeHashmapTPCell(hashmapTPCell: HashmapTPCell): (builder: Builder) => void { + return ((builder: Builder) => { + builder.storeDict(hashmapTPCell.x, Dictionary.Keys.BigUint(100), { + serialize: ((arg: TypedParam, builder: Builder) => { + ((arg: TypedParam) => { + return ((builder: Builder) => { + let cell1 = beginCell(); + storeTypedParam(arg)(cell1); + builder.storeRef(cell1); + + }) + + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); + }) + +} + +// a$_ {n:#} x:(HashmapE n uint5) = HashmapVarKey n; + +export function loadHashmapVarKey(slice: Slice, n: number): HashmapVarKey { + let x: Dictionary = Dictionary.load(Dictionary.Keys.BigUint(n), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { + return slice.loadUint(5) + + }), + }, slice); + return { + kind: 'HashmapVarKey', + n: n, + x: x, + } + +} + +export function storeHashmapVarKey(hashmapVarKey: HashmapVarKey): (builder: Builder) => void { + return ((builder: Builder) => { + builder.storeDict(hashmapVarKey.x, Dictionary.Keys.BigUint(hashmapVarKey.n), { + serialize: ((arg: number, builder: Builder) => { + ((arg: number) => { + return ((builder: Builder) => { + builder.storeUint(arg, 5); + }) + + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); + }) + +} + +// a$_ x:(HashmapVarKey 5) = HashmapVarKeyUser; + +export function loadHashmapVarKeyUser(slice: Slice): HashmapVarKeyUser { + let x: HashmapVarKey = loadHashmapVarKey(slice, 5); + return { + kind: 'HashmapVarKeyUser', + x: x, + } + +} + +export function storeHashmapVarKeyUser(hashmapVarKeyUser: HashmapVarKeyUser): (builder: Builder) => void { + return ((builder: Builder) => { + storeHashmapVarKey(hashmapVarKeyUser.x)(builder); + }) + +} + +// a$_ {n:#} x:(HashmapE (n+2) uint5) = HashmapExprKey n; + +export function loadHashmapExprKey(slice: Slice, n: number): HashmapExprKey { + let x: Dictionary = Dictionary.load(Dictionary.Keys.BigUint((n + 2)), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { + return slice.loadUint(5) + + }), + }, slice); + return { + kind: 'HashmapExprKey', + n: n, + x: x, + } + +} + +export function storeHashmapExprKey(hashmapExprKey: HashmapExprKey): (builder: Builder) => void { + return ((builder: Builder) => { + builder.storeDict(hashmapExprKey.x, Dictionary.Keys.BigUint((hashmapExprKey.n + 2)), { + serialize: ((arg: number, builder: Builder) => { + ((arg: number) => { + return ((builder: Builder) => { + builder.storeUint(arg, 5); + }) + + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); + }) + +} + +// a$_ x:(HashmapExprKey 5) = HashmapExprKeyUser; + +export function loadHashmapExprKeyUser(slice: Slice): HashmapExprKeyUser { + let x: HashmapExprKey = loadHashmapExprKey(slice, 5); + return { + kind: 'HashmapExprKeyUser', + x: x, + } + +} + +export function storeHashmapExprKeyUser(hashmapExprKeyUser: HashmapExprKeyUser): (builder: Builder) => void { + return ((builder: Builder) => { + storeHashmapExprKey(hashmapExprKeyUser.x)(builder); + }) + +} + +// a$_ {A: Type} x:(HashmapE 200 (OneComb A)) = HashmapOneComb A; + +export function loadHashmapOneComb(slice: Slice, loadA: (slice: Slice) => A): HashmapOneComb { + let x: Dictionary> = Dictionary.load(Dictionary.Keys.BigUint(200), { + serialize: () => { throw new Error('Not implemented') }, + parse: ((slice: Slice) => { + return loadOneComb(slice, loadA) + + }), + }, slice); + return { + kind: 'HashmapOneComb', + x: x, + } + +} + +export function storeHashmapOneComb(hashmapOneComb: HashmapOneComb, storeA: (a: A) => (builder: Builder) => void): (builder: Builder) => void { + return ((builder: Builder) => { + builder.storeDict(hashmapOneComb.x, Dictionary.Keys.BigUint(200), { + serialize: ((arg: OneComb, builder: Builder) => { + ((arg: OneComb) => { + return ((builder: Builder) => { + storeOneComb(arg, storeA)(builder); + }) + + })(arg)(builder); + }), + parse: () => { throw new Error('Not implemented') }, + }); + }) + +} + +// a$_ x:(HashmapOneComb uint5) = HashmapOneCombUser; + +export function loadHashmapOneCombUser(slice: Slice): HashmapOneCombUser { + let x: HashmapOneComb = loadHashmapOneComb(slice, ((slice: Slice) => { + return slice.loadUint(5) + + })); + return { + kind: 'HashmapOneCombUser', + x: x, + } + +} + +export function storeHashmapOneCombUser(hashmapOneCombUser: HashmapOneCombUser): (builder: Builder) => void { + return ((builder: Builder) => { + storeHashmapOneComb(hashmapOneCombUser.x, ((arg: number) => { + return ((builder: Builder) => { + builder.storeUint(arg, 5); + }) + + }))(builder); + }) + +} + diff --git a/test/tlb/test.tlb b/test/tlb/test.tlb index f5707eb..e8aae12 100644 --- a/test/tlb/test.tlb +++ b/test/tlb/test.tlb @@ -158,4 +158,13 @@ a$_ v:(VarUInteger 5) = VarUIntegerUser; a$_ v:(VarInteger 5) = VarIntegerUser; nanograms$_ amount:(VarUInteger 16) = Grams; -a$_ g:Grams = GramsUser; \ No newline at end of file +a$_ g:Grams = GramsUser; + +a$_ x:(HashmapE 100 VarUIntegerUser) = HashmapVUIUser; +a$_ x:(HashmapE 100 ^TypedParam) = HashmapTPCell; +a$_ {n:#} x:(HashmapE n uint5) = HashmapVarKey n; +a$_ x:(HashmapVarKey 5) = HashmapVarKeyUser; +a$_ {n:#} x:(HashmapE (n+2) uint5) = HashmapExprKey n; +a$_ x:(HashmapExprKey 5) = HashmapExprKeyUser; +a$_ {A: Type} x:(HashmapE 200 (OneComb A)) = HashmapOneComb A; +a$_ x:(HashmapOneComb uint5) = HashmapOneCombUser; diff --git a/test/tlbgen.spec.ts b/test/tlbgen.spec.ts index fbd64ca..2fb20aa 100644 --- a/test/tlbgen.spec.ts +++ b/test/tlbgen.spec.ts @@ -1,16 +1,28 @@ import path from 'path'; -import { Address, BitString, Cell, ExternalAddress, Slice } from 'ton'; +import { Address, BitString, Cell, Dictionary, DictionaryKeyTypes, ExternalAddress, Slice } from 'ton'; import { describe, expect, test } from '@jest/globals'; import { beginCell } from 'ton'; import { loadBlock, storeBlock } from './generated_files/generated_block'; -import { AddressUser, AnonymousData, AnyAddressUser, BitLenArg, BitLenArgUser, BitSelection, BitUser, BoolUser, CellTypedField, CellsSimple, CheckCrc32, CheckKeyword, CombArgCellRefUser, ComplexTypedField, ConditionalField, ConditionalRef, ConstructorOrder, DollarTag, EmptyTag, EqualityExpression, ExprArgUser, ExtAddressUser, FalseAnonField, GramsUser, HashmapEUser, ImplicitCondition, IntBitsOutside, IntBitsParametrizedOutside, LessThan, LoadFromNegationOutsideExpr, ManyComb, MathExprAsCombArg, MultipleEmptyConstructor, NegationFromImplicit, ParamConst, ParamDifNames, ParamDifNamesUser, ParamNamedArgInSecondConstr, RefCombinatorAny, RefCombinatorInRef, SharpConstructor, SharpTag, Simple, True, TupleCheck, TwoConstructors, TypedField, TypedParam, Unary, UnaryUserCheckOrder, VarIntegerUser, VarUIntegerUser, loadAddressUser, loadAnonymousData, loadAnyAddressUser, loadBitLenArg, loadBitLenArgUser, loadBitSelection, loadBitUser, loadBoolUser, loadCellTypedField, loadCellsSimple, loadCheckCrc32, loadCheckKeyword, loadCombArgCellRefUser, loadComplexTypedField, loadConditionalField, loadConditionalRef, loadConstructorOrder, loadDollarTag, loadEmptyTag, loadEqualityExpression, loadExprArgUser, loadExtAddressUser, loadFalseAnonField, loadGramsUser, loadHashmapEUser, loadImplicitCondition, loadIntBitsOutside, loadIntBitsParametrizedOutside, loadLessThan, loadLoadFromNegationOutsideExpr, loadManyComb, loadMathExprAsCombArg, loadMultipleEmptyConstructor, loadNegationFromImplicit, loadParamConst, loadParamDifNames, loadParamDifNamesUser, loadParamNamedArgInSecondConstr, loadRefCombinatorAny, loadRefCombinatorInRef, loadSharpConstructor, loadSharpTag, loadSimple, loadTrue, loadTupleCheck, loadTwoConstructors, loadTypedField, loadTypedParam, loadUnary, loadUnaryUserCheckOrder, loadVarIntegerUser, loadVarUIntegerUser, storeAddressUser, storeAnonymousData, storeAnyAddressUser, storeBitLenArg, storeBitLenArgUser, storeBitSelection, storeBitUser, storeBoolUser, storeCellTypedField, storeCellsSimple, storeCheckCrc32, storeCheckKeyword, storeCombArgCellRefUser, storeComplexTypedField, storeConditionalField, storeConditionalRef, storeConstructorOrder, storeDollarTag, storeEmptyTag, storeEqualityExpression, storeExprArgUser, storeExtAddressUser, storeFalseAnonField, storeGramsUser, storeHashmapEUser, storeImplicitCondition, storeIntBitsOutside, storeIntBitsParametrizedOutside, storeLessThan, storeLoadFromNegationOutsideExpr, storeManyComb, storeMathExprAsCombArg, storeMultipleEmptyConstructor, storeNegationFromImplicit, storeParamConst, storeParamDifNames, storeParamDifNamesUser, storeParamNamedArgInSecondConstr, storeRefCombinatorAny, storeRefCombinatorInRef, storeSharpConstructor, storeSharpTag, storeSimple, storeTrue, storeTupleCheck, storeTwoConstructors, storeTypedField, storeTypedParam, storeUnary, storeUnaryUserCheckOrder, storeVarIntegerUser, storeVarUIntegerUser } from './generated_files/generated_test'; +import { AddressUser, AnonymousData, AnyAddressUser, BitLenArg, BitLenArgUser, BitSelection, BitUser, BoolUser, CellTypedField, CellsSimple, CheckCrc32, CheckKeyword, CombArgCellRefUser, ComplexTypedField, ConditionalField, ConditionalRef, ConstructorOrder, DollarTag, EmptyTag, EqualityExpression, ExprArgUser, ExtAddressUser, FalseAnonField, GramsUser, HashmapEUser, HashmapExprKeyUser, HashmapOneCombUser, HashmapTPCell, HashmapVUIUser, HashmapVarKeyUser, ImplicitCondition, IntBitsOutside, IntBitsParametrizedOutside, LessThan, LoadFromNegationOutsideExpr, ManyComb, MathExprAsCombArg, MultipleEmptyConstructor, NegationFromImplicit, OneComb, ParamConst, ParamDifNames, ParamDifNamesUser, ParamNamedArgInSecondConstr, RefCombinatorAny, RefCombinatorInRef, SharpConstructor, SharpTag, Simple, True, TupleCheck, TwoConstructors, TypedField, TypedParam, Unary, UnaryUserCheckOrder, VarIntegerUser, VarUIntegerUser, loadAddressUser, loadAnonymousData, loadAnyAddressUser, loadBitLenArg, loadBitLenArgUser, loadBitSelection, loadBitUser, loadBoolUser, loadCellTypedField, loadCellsSimple, loadCheckCrc32, loadCheckKeyword, loadCombArgCellRefUser, loadComplexTypedField, loadConditionalField, loadConditionalRef, loadConstructorOrder, loadDollarTag, loadEmptyTag, loadEqualityExpression, loadExprArgUser, loadExtAddressUser, loadFalseAnonField, loadGramsUser, loadHashmapEUser, loadHashmapExprKeyUser, loadHashmapOneCombUser, loadHashmapTPCell, loadHashmapVUIUser, loadHashmapVarKeyUser, loadImplicitCondition, loadIntBitsOutside, loadIntBitsParametrizedOutside, loadLessThan, loadLoadFromNegationOutsideExpr, loadManyComb, loadMathExprAsCombArg, loadMultipleEmptyConstructor, loadNegationFromImplicit, loadParamConst, loadParamDifNames, loadParamDifNamesUser, loadParamNamedArgInSecondConstr, loadRefCombinatorAny, loadRefCombinatorInRef, loadSharpConstructor, loadSharpTag, loadSimple, loadTrue, loadTupleCheck, loadTwoConstructors, loadTypedField, loadTypedParam, loadUnary, loadUnaryUserCheckOrder, loadVarIntegerUser, loadVarUIntegerUser, storeAddressUser, storeAnonymousData, storeAnyAddressUser, storeBitLenArg, storeBitLenArgUser, storeBitSelection, storeBitUser, storeBoolUser, storeCellTypedField, storeCellsSimple, storeCheckCrc32, storeCheckKeyword, storeCombArgCellRefUser, storeComplexTypedField, storeConditionalField, storeConditionalRef, storeConstructorOrder, storeDollarTag, storeEmptyTag, storeEqualityExpression, storeExprArgUser, storeExtAddressUser, storeFalseAnonField, storeGramsUser, storeHashmapEUser, storeHashmapExprKeyUser, storeHashmapOneCombUser, storeHashmapTPCell, storeHashmapVUIUser, storeHashmapVarKeyUser, storeImplicitCondition, storeIntBitsOutside, storeIntBitsParametrizedOutside, storeLessThan, storeLoadFromNegationOutsideExpr, storeManyComb, storeMathExprAsCombArg, storeMultipleEmptyConstructor, storeNegationFromImplicit, storeParamConst, storeParamDifNames, storeParamDifNamesUser, storeParamNamedArgInSecondConstr, storeRefCombinatorAny, storeRefCombinatorInRef, storeSharpConstructor, storeSharpTag, storeSimple, storeTrue, storeTupleCheck, storeTwoConstructors, storeTypedField, storeTypedParam, storeUnary, storeUnaryUserCheckOrder, storeVarIntegerUser, storeVarUIntegerUser } from './generated_files/generated_test'; import { randomInt } from 'crypto'; const fixturesDir = path.resolve(__dirname, 'fixtures'); -function deepEqual(object1: any, object2: any) { +function isPrimitive(input: any) { + if (input == null) { + // This is here to correctly handle document.all. + return input === null || input === undefined; + } + const type = typeof input; + return type !== "object" && type !== "function"; + } + +function deepEqual(object1: any, object2: any): boolean { + if (isPrimitive(object1) && isPrimitive(object2)) { + return object1 == object2; + } if (object1 instanceof BitString && object2 instanceof BitString) { return object1.equals(object2); } @@ -21,6 +33,25 @@ function deepEqual(object1: any, object2: any) { return object1.equals(object2); } + if (object1 instanceof Dictionary && object2 instanceof Dictionary) { + if (object1.size != object2.size) { + return false; + } + let ok = true; + object1.keys().forEach((key) => { + let value1 = object1.get(key); + if (!object2.has(key)) { + ok = false; + } + let value2 = object2.get(key); + let equal = deepEqual(value1, value2); + if (!equal) { + ok = false; + } + }) + return ok; + } + const keys1 = Object.keys(object1); const keys2 = Object.keys(object2); @@ -190,6 +221,40 @@ describe('Generating tlb code', () => { let varIntegerUser: VarIntegerUser = { kind: 'VarIntegerUser', v: BigInt(-6) } checkSameOnStoreLoad(varIntegerUser, loadVarIntegerUser, storeVarIntegerUser) + + let simpleDict: Dictionary = Dictionary.empty() + simpleDict.set(1, 6); + simpleDict.set(2, 7); + simpleDict.set(0, 5); + let hashmapEUser: HashmapEUser = { kind: 'HashmapEUser', x: simpleDict } + checkSameOnStoreLoad(hashmapEUser, loadHashmapEUser, storeHashmapEUser); + + let vuiDict: Dictionary = Dictionary.empty() + vuiDict.set(BigInt(6), {kind: 'VarUIntegerUser', v: BigInt(5)}) + vuiDict.set(BigInt(7), {kind: 'VarUIntegerUser', v: BigInt(3)}) + let hashmapVUIUser: HashmapVUIUser = { kind: 'HashmapVUIUser', 'x': vuiDict} + checkSameOnStoreLoad(hashmapVUIUser, loadHashmapVUIUser, storeHashmapVUIUser); + + let tpcDict: Dictionary = Dictionary.empty() + tpcDict.set(BigInt(5), {kind: 'TypedParam', x: {kind: 'Maybe_just', value: {kind: 'SharpConstructor', c: 3, y: {kind: 'FixedIntParam', y: 4}}}}) + tpcDict.set(BigInt(3), {kind: 'TypedParam', x: {kind: 'Maybe_just', value: {kind: 'SharpConstructor', c: 9, y: {kind: 'FixedIntParam', y: 8}}}}) + let hashmapTPCell: HashmapTPCell = { kind: 'HashmapTPCell', x: tpcDict} + checkSameOnStoreLoad(hashmapTPCell, loadHashmapTPCell, storeHashmapTPCell); + + let vkDict: Dictionary = Dictionary.empty() + vkDict.set(BigInt(3), 6) + vkDict.set(BigInt(7), 9) + let hashmapVarKeyUser: HashmapVarKeyUser = { kind: 'HashmapVarKeyUser', x: {kind: 'HashmapVarKey', n: 5, x: vkDict }} + checkSameOnStoreLoad(hashmapVarKeyUser, loadHashmapVarKeyUser, storeHashmapVarKeyUser); + + let hashmapExprKeyUser: HashmapExprKeyUser = { kind: 'HashmapExprKeyUser', x: {kind: 'HashmapExprKey', n: 5, x: vkDict }} + checkSameOnStoreLoad(hashmapExprKeyUser, loadHashmapExprKeyUser, storeHashmapExprKeyUser); + + let ocuDict: Dictionary> = Dictionary.empty() + ocuDict.set(BigInt(1), { kind: 'OneComb', t: 3, x: 6 }) + ocuDict.set(BigInt(19), { kind: 'OneComb', t: 5, x: 4 }) + let hashmapOneCombUser: HashmapOneCombUser = { kind: 'HashmapOneCombUser', x: {kind: 'HashmapOneComb', x: ocuDict }} + checkSameOnStoreLoad(hashmapOneCombUser, loadHashmapOneCombUser, storeHashmapOneCombUser); }) test('Combinators', () => { @@ -279,97 +344,6 @@ describe('Generating tlb code', () => { checkThrowOnStoreLoad(equalityExpressionIncorrect, loadEqualityExpression, storeEqualityExpression); }) - test('Builtins', () => { - expect.hasAssertions() - - let hashmapEUser: HashmapEUser = { - kind: 'HashmapEUser', - x: { - kind: 'HashmapE_hme_root', - n: 8, - root: { - kind: 'Hashmap', - l: 0, m: 8, n: 8, - label: { - kind: 'HmLabel_hml_short', - n: 0, m: 8, - len: { kind: 'Unary_unary_zero' }, - s: [] - }, - node: { - kind: 'HashmapNode_hmn_fork', - n: 7, - left: { - kind: 'Hashmap', - n: 7, - m: 5, - l: 2, - label: { - kind: 'HmLabel_hml_long', - m: 7, - n: 2, - s: getBooleanArray('00') - }, - node: { - kind: 'HashmapNode_hmn_fork', - n: 4, - left: { - kind: 'Hashmap', - n: 4, - m: 0, - l: 4, - label: { - kind: 'HmLabel_hml_long', - m: 4, - n: 4, - s: getBooleanArray('0001') - }, - node: { - kind: 'HashmapNode_hmn_leaf', - value: 777 - } - }, - right: { - kind: 'Hashmap', - n: 4, - m: 0, - l: 4, - label: { - kind: 'HmLabel_hml_long', - m: 4, - n: 4, - s: getBooleanArray('0001') - }, - node: { - kind: 'HashmapNode_hmn_leaf', - value: 111 - } - } - } - }, - right: { - kind: 'Hashmap', - n: 7, - m: 0, - l: 7, - label: { - kind: 'HmLabel_hml_long', - m: 7, - n: 7, - s: getBooleanArray('0000000') - }, - node: { - kind: 'HashmapNode_hmn_leaf', - value: 777 - } - } - } - } - } - } - checkSameOnStoreLoad(hashmapEUser, loadHashmapEUser, storeHashmapEUser); - }) - test('Constructor Tags', () => { expect.hasAssertions()