diff --git a/src/ast.ts b/src/ast.ts index 95bbced..9af8410 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -138,8 +138,14 @@ export type TLBExoticType = { kind: "TLBExoticType"; }; +export type TLBBoolType = { + kind: "TLBBoolType"; + value: boolean | undefined; +} + export type TLBFieldType = | TLBNumberType + | TLBBoolType | TLBBitsType | TLBNamedType | TLBCoinsType diff --git a/src/astbuilder/fill_constructors.ts b/src/astbuilder/fill_constructors.ts index 596cf1d..2c84a46 100644 --- a/src/astbuilder/fill_constructors.ts +++ b/src/astbuilder/fill_constructors.ts @@ -434,7 +434,8 @@ function checkAndRemovePrimitives( typesToDelete.set("VarInteger", ["d466ed5"]) typesToDelete.set("HashmapE", ["32bae5cb", "28fa3979"]) typesToDelete.set("HashmapAugE", ["36820dce", "5f71ac75"]) - typesToDelete.set("Coins", ["258097e8"]) + typesToDelete.set("BoolTrue", ["943ebb5"]) + typesToDelete.set("BoolFalse", ["1f5e497d"]) 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 2cd7d98..215f25b 100644 --- a/src/astbuilder/handle_type.ts +++ b/src/astbuilder/handle_type.ts @@ -280,8 +280,14 @@ export function getType( return { kind: "TLBAddressType", addrType: "Any" }; } else if (expr.name == "Bit") { return { kind: "TLBBitsType", bits: new TLBNumberExpr(1) }; - } else if (expr.name == "Grams") { + } else if (expr.name == "Grams" || expr.name == "Coins") { return { kind: "TLBCoinsType" }; + } else if (expr.name == "Bool") { + return { kind: "TLBBoolType", value: undefined }; + } else if (expr.name == "BoolFalse") { + return { kind: "TLBBoolType", value: false }; + } else if (expr.name == "BoolTrue") { + return { kind: "TLBBoolType", value: true }; } else { if (constructor.variablesMap.get(expr.name)?.type == "#") { return { diff --git a/src/generators/typescript/generator.ts b/src/generators/typescript/generator.ts index 8d42ff6..9ea2e9a 100644 --- a/src/generators/typescript/generator.ts +++ b/src/generators/typescript/generator.ts @@ -284,25 +284,30 @@ export function storeBool(bool: Bool): (builder: Builder) => void { } -export interface Coins { - readonly kind: 'Coins'; - readonly grams: bigint; -} -export function loadCoins(slice: Slice): Coins { - let grams: bigint = slice.loadCoins(); - return { - kind: 'Coins', - grams: grams, - } +export function loadBoolFalse(slice: Slice): Bool { + if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) { + slice.loadUint(1); + return { + kind: 'Bool', + value: false + } + + } + throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor'); } -export function storeCoins(coins: Coins): (builder: Builder) => void { - return ((builder: Builder) => { - builder.storeCoins(coins.grams); - }) +export function loadBoolTrue(slice: Slice): Bool { + if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) { + slice.loadUint(1); + return { + kind: 'Bool', + value: true + } + } + throw new Error('Expected one of "BoolTrue" in loading "BoolTrue", but data does not satisfy any constructor'); } `)) } @@ -986,6 +991,12 @@ export function storeCoins(coins: Coins): (builder: Builder) => void { if (subExprInfo.storeStmtInside) { result.storeStmtInside = storeInNewCell(currentCell, subExprInfo.storeStmtInside); } + } else if (fieldType.kind == "TLBBoolType") { + let loadFunction = 'load' + (fieldType.value === undefined ? 'Bool': (fieldType.value ? 'BoolTrue': 'BoolFalse')); + result.loadExpr = tFunctionCall(id(loadFunction), [id("slice")]); + result.typeParamExpr = id('Bool'); + result.storeStmtInside = tExpressionStatement(tFunctionCall(tFunctionCall(id('storeBool'), storeParametersInside), [id('builder')])); + result.storeStmtOutside = tExpressionStatement(tFunctionCall(tFunctionCall(id('storeBool'), storeParametersOutside), [id('builder')])); } else if (fieldType.kind == "TLBHashmapType") { let keyForLoad: Expression = dictKeyExpr(fieldType.key, ctx); let keyForStore: Expression = dictKeyExpr(fieldType.key, ctx, ctx.typeName); diff --git a/test/generated_files/generated_block.ts b/test/generated_files/generated_block.ts index 32bb5ca..172aa56 100644 --- a/test/generated_files/generated_block.ts +++ b/test/generated_files/generated_block.ts @@ -38,25 +38,30 @@ export function storeBool(bool: Bool): (builder: Builder) => void { } -export interface Coins { - readonly kind: 'Coins'; - readonly grams: bigint; -} -export function loadCoins(slice: Slice): Coins { - let grams: bigint = slice.loadCoins(); - return { - kind: 'Coins', - grams: grams, - } +export function loadBoolFalse(slice: Slice): Bool { + if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) { + slice.loadUint(1); + return { + kind: 'Bool', + value: false + } + + } + throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor'); } -export function storeCoins(coins: Coins): (builder: Builder) => void { - return ((builder: Builder) => { - builder.storeCoins(coins.grams); - }) +export function loadBoolTrue(slice: Slice): Bool { + if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) { + slice.loadUint(1); + return { + kind: 'Bool', + value: true + } + } + throw new Error('Expected one of "BoolTrue" in loading "BoolTrue", but data does not satisfy any constructor'); } export function copyCellToBuilder(from: Cell, to: Builder): void { @@ -78,18 +83,6 @@ export interface True { readonly kind: 'True'; } -// bool_false$0 = BoolFalse; - -export interface BoolFalse { - readonly kind: 'BoolFalse'; -} - -// bool_true$1 = BoolTrue; - -export interface BoolTrue { - readonly kind: 'BoolTrue'; -} - // nothing$0 {X:Type} = Maybe X; // just$1 {X:Type} value:X = Maybe X; @@ -396,6 +389,13 @@ export interface Anycast { readonly rewrite_pfx: BitString; } +// _ grams:Grams = Coins; + +export interface Coins { + readonly kind: 'Coins'; + readonly grams: bigint; +} + /* extra_currencies$_ dict:(HashmapE 32 (VarUInteger 32)) = ExtraCurrencyCollection; @@ -3082,12 +3082,12 @@ jetton_bridge_prices#_ bridge_burn_fee:Coins bridge_mint_fee:Coins export interface JettonBridgePrices { readonly kind: 'JettonBridgePrices'; - readonly bridge_burn_fee: Coins; - readonly bridge_mint_fee: Coins; - readonly wallet_min_tons_for_storage: Coins; - readonly wallet_gas_consumption: Coins; - readonly minter_min_tons_for_storage: Coins; - readonly discover_gas_consumption: Coins; + readonly bridge_burn_fee: bigint; + readonly bridge_mint_fee: bigint; + readonly wallet_min_tons_for_storage: bigint; + readonly wallet_gas_consumption: bigint; + readonly minter_min_tons_for_storage: bigint; + readonly discover_gas_consumption: bigint; } // jetton_bridge_params_v0#00 bridge_address:bits256 oracles_address:bits256 oracles:(HashmapE 256 uint256) state_flags:uint8 burn_bridge_fee:Coins = JettonBridgeParams; @@ -3102,7 +3102,7 @@ export interface JettonBridgeParams_jetton_bridge_params_v0 { readonly oracles_address: Buffer; readonly oracles: Dictionary; readonly state_flags: number; - readonly burn_bridge_fee: Coins; + readonly burn_bridge_fee: bigint; } export interface JettonBridgeParams_jetton_bridge_params_v1 { @@ -3825,46 +3825,6 @@ export function storeTrue(true0: True): (builder: Builder) => void { } -// bool_false$0 = BoolFalse; - -export function loadBoolFalse(slice: Slice): BoolFalse { - if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) { - slice.loadUint(1); - return { - kind: 'BoolFalse', - } - - } - throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor'); -} - -export function storeBoolFalse(boolFalse: BoolFalse): (builder: Builder) => void { - return ((builder: Builder) => { - builder.storeUint(0b0, 1); - }) - -} - -// bool_true$1 = BoolTrue; - -export function loadBoolTrue(slice: Slice): BoolTrue { - if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) { - slice.loadUint(1); - return { - kind: 'BoolTrue', - } - - } - throw new Error('Expected one of "BoolTrue" in loading "BoolTrue", but data does not satisfy any constructor'); -} - -export function storeBoolTrue(boolTrue: BoolTrue): (builder: Builder) => void { - return ((builder: Builder) => { - builder.storeUint(0b1, 1); - }) - -} - // nothing$0 {X:Type} = Maybe X; // just$1 {X:Type} value:X = Maybe X; @@ -4741,6 +4701,24 @@ export function storeAnycast(anycast: Anycast): (builder: Builder) => void { } +// _ grams:Grams = Coins; + +export function loadCoins(slice: Slice): Coins { + let grams: bigint = slice.loadCoins(); + return { + kind: 'Coins', + grams: grams, + } + +} + +export function storeCoins(coins: Coins): (builder: Builder) => void { + return ((builder: Builder) => { + builder.storeCoins(coins.grams); + }) + +} + /* extra_currencies$_ dict:(HashmapE 32 (VarUInteger 32)) = ExtraCurrencyCollection; @@ -9663,7 +9641,7 @@ export function loadMcStateExtra(slice: Slice): McStateExtra { let flags: number = slice1.loadUint(16); let validator_info: ValidatorInfo = loadValidatorInfo(slice1); let prev_blocks: OldMcBlocksInfo = loadOldMcBlocksInfo(slice1); - let after_key_block: Bool = loadBool(slice1); + let after_key_block: Bool = loadBool(slice); let last_key_block: Maybe = loadMaybe(slice1, loadExtBlkRef); let block_create_stats: BlockCreateStats | undefined = ((flags & (1 << 0)) ? loadBlockCreateStats(slice1) : undefined); let global_balance: CurrencyCollection = loadCurrencyCollection(slice); @@ -9693,7 +9671,7 @@ export function storeMcStateExtra(mcStateExtra: McStateExtra): (builder: Builder cell1.storeUint(mcStateExtra.flags, 16); storeValidatorInfo(mcStateExtra.validator_info)(cell1); storeOldMcBlocksInfo(mcStateExtra.prev_blocks)(cell1); - storeBool(mcStateExtra.after_key_block)(cell1); + storeBool(mcStateExtra.after_key_block)(builder); storeMaybe(mcStateExtra.last_key_block, storeExtBlkRef)(cell1); if ((mcStateExtra.block_create_stats != undefined)) { storeBlockCreateStats(mcStateExtra.block_create_stats)(cell1); @@ -12504,12 +12482,12 @@ jetton_bridge_prices#_ bridge_burn_fee:Coins bridge_mint_fee:Coins */ export function loadJettonBridgePrices(slice: Slice): JettonBridgePrices { - let bridge_burn_fee: Coins = loadCoins(slice); - let bridge_mint_fee: Coins = loadCoins(slice); - let wallet_min_tons_for_storage: Coins = loadCoins(slice); - let wallet_gas_consumption: Coins = loadCoins(slice); - let minter_min_tons_for_storage: Coins = loadCoins(slice); - let discover_gas_consumption: Coins = loadCoins(slice); + let bridge_burn_fee: bigint = slice.loadCoins(); + let bridge_mint_fee: bigint = slice.loadCoins(); + let wallet_min_tons_for_storage: bigint = slice.loadCoins(); + let wallet_gas_consumption: bigint = slice.loadCoins(); + let minter_min_tons_for_storage: bigint = slice.loadCoins(); + let discover_gas_consumption: bigint = slice.loadCoins(); return { kind: 'JettonBridgePrices', bridge_burn_fee: bridge_burn_fee, @@ -12524,12 +12502,12 @@ export function loadJettonBridgePrices(slice: Slice): JettonBridgePrices { export function storeJettonBridgePrices(jettonBridgePrices: JettonBridgePrices): (builder: Builder) => void { return ((builder: Builder) => { - storeCoins(jettonBridgePrices.bridge_burn_fee)(builder); - storeCoins(jettonBridgePrices.bridge_mint_fee)(builder); - storeCoins(jettonBridgePrices.wallet_min_tons_for_storage)(builder); - storeCoins(jettonBridgePrices.wallet_gas_consumption)(builder); - storeCoins(jettonBridgePrices.minter_min_tons_for_storage)(builder); - storeCoins(jettonBridgePrices.discover_gas_consumption)(builder); + builder.storeCoins(jettonBridgePrices.bridge_burn_fee); + builder.storeCoins(jettonBridgePrices.bridge_mint_fee); + builder.storeCoins(jettonBridgePrices.wallet_min_tons_for_storage); + builder.storeCoins(jettonBridgePrices.wallet_gas_consumption); + builder.storeCoins(jettonBridgePrices.minter_min_tons_for_storage); + builder.storeCoins(jettonBridgePrices.discover_gas_consumption); }) } @@ -12551,7 +12529,7 @@ export function loadJettonBridgeParams(slice: Slice): JettonBridgeParams { }), }, slice); let state_flags: number = slice.loadUint(8); - let burn_bridge_fee: Coins = loadCoins(slice); + let burn_bridge_fee: bigint = slice.loadCoins(); return { kind: 'JettonBridgeParams_jetton_bridge_params_v0', bridge_address: bridge_address, @@ -12609,7 +12587,7 @@ export function storeJettonBridgeParams(jettonBridgeParams: JettonBridgeParams): parse: () => { throw new Error('Not implemented') }, }); builder.storeUint(jettonBridgeParams.state_flags, 8); - storeCoins(jettonBridgeParams.burn_bridge_fee)(builder); + builder.storeCoins(jettonBridgeParams.burn_bridge_fee); }) } diff --git a/test/generated_files/generated_test.ts b/test/generated_files/generated_test.ts index 11e8ed1..e304184 100644 --- a/test/generated_files/generated_test.ts +++ b/test/generated_files/generated_test.ts @@ -38,25 +38,30 @@ export function storeBool(bool: Bool): (builder: Builder) => void { } -export interface Coins { - readonly kind: 'Coins'; - readonly grams: bigint; -} -export function loadCoins(slice: Slice): Coins { - let grams: bigint = slice.loadCoins(); - return { - kind: 'Coins', - grams: grams, - } +export function loadBoolFalse(slice: Slice): Bool { + if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b0))) { + slice.loadUint(1); + return { + kind: 'Bool', + value: false + } + + } + throw new Error('Expected one of "BoolFalse" in loading "BoolFalse", but data does not satisfy any constructor'); } -export function storeCoins(coins: Coins): (builder: Builder) => void { - return ((builder: Builder) => { - builder.storeCoins(coins.grams); - }) +export function loadBoolTrue(slice: Slice): Bool { + if (((slice.remainingBits >= 1) && (slice.preloadUint(1) == 0b1))) { + slice.loadUint(1); + return { + kind: 'Bool', + value: true + } + } + throw new Error('Expected one of "BoolTrue" in loading "BoolTrue", but data does not satisfy any constructor'); } export function copyCellToBuilder(from: Cell, to: Builder): void { @@ -1227,6 +1232,20 @@ export interface VMStackUser { readonly t: TupleItem[]; } +// bool_false_user$_ x:BoolFalse = BoolFalseUser; + +export interface BoolFalseUser { + readonly kind: 'BoolFalseUser'; + readonly x: Bool; +} + +// bool_true_user$_ x:BoolTrue = BoolTrueUser; + +export interface BoolTrueUser { + readonly kind: 'BoolTrueUser'; + readonly x: Bool; +} + // tmpa$_ a:# b:# = Simple; export function loadSimple(slice: Slice): Simple { @@ -4813,3 +4832,39 @@ export function storeVMStackUser(vMStackUser: VMStackUser): (builder: Builder) = } +// bool_false_user$_ x:BoolFalse = BoolFalseUser; + +export function loadBoolFalseUser(slice: Slice): BoolFalseUser { + let x: Bool = loadBoolFalse(slice); + return { + kind: 'BoolFalseUser', + x: x, + } + +} + +export function storeBoolFalseUser(boolFalseUser: BoolFalseUser): (builder: Builder) => void { + return ((builder: Builder) => { + storeBool(boolFalseUser.x)(builder); + }) + +} + +// bool_true_user$_ x:BoolTrue = BoolTrueUser; + +export function loadBoolTrueUser(slice: Slice): BoolTrueUser { + let x: Bool = loadBoolTrue(slice); + return { + kind: 'BoolTrueUser', + x: x, + } + +} + +export function storeBoolTrueUser(boolTrueUser: BoolTrueUser): (builder: Builder) => void { + return ((builder: Builder) => { + storeBool(boolTrueUser.x)(builder); + }) + +} + diff --git a/test/tlb/test.tlb b/test/tlb/test.tlb index 863c5f8..4f995b1 100644 --- a/test/tlb/test.tlb +++ b/test/tlb/test.tlb @@ -244,4 +244,10 @@ vmc_while_body$110011 cond:^VmCont body:^VmCont after:^VmCont = VmCont; vmc_pushint$1111 value:int32 next:^VmCont = VmCont; -_ t:VmStack = VMStackUser; \ No newline at end of file +_ t:VmStack = VMStackUser; + +bool_false$0 = BoolFalse; +bool_true$1 = BoolTrue; + +bool_false_user$_ x:BoolFalse = BoolFalseUser; +bool_true_user$_ x:BoolTrue = BoolTrueUser;