diff --git a/generated_block.ts b/generated_block.ts index 6b0ac9f..fdba907 100644 --- a/generated_block.ts +++ b/generated_block.ts @@ -747,13 +747,13 @@ export type VarHashmapNode_vhmn_cont = { child: VarHashmap; value: X; }; -export function loadVarHashmapNode(slice: Slice, n: number, loadX: (slice: Slice) => X): VarHashmapNode { +export function loadVarHashmapNode(slice: Slice, arg0: number, loadX: (slice: Slice) => X): VarHashmapNode { if ((slice.preloadUint(2) == 0b00)) { slice.loadUint(2); let value: X = loadX(slice); return { kind: 'VarHashmapNode_vhmn_leaf', - n: n, + n: arg0, value: value }; }; @@ -919,13 +919,13 @@ export type PfxHashmapNode_phmn_fork = { left: PfxHashmap; right: PfxHashmap; }; -export function loadPfxHashmapNode(slice: Slice, n: number, loadX: (slice: Slice) => X): PfxHashmapNode { +export function loadPfxHashmapNode(slice: Slice, arg0: number, loadX: (slice: Slice) => X): PfxHashmapNode { if ((slice.preloadUint(1) == 0b0)) { slice.loadUint(1); let value: X = loadX(slice); return { kind: 'PfxHashmapNode_phmn_leaf', - n: n, + n: arg0, value: value }; }; @@ -8346,7 +8346,7 @@ export function loadVmStackList(slice: Slice, arg0: number): VmStackList { tos: tos }; }; - if ((n == 0)) { + if ((arg0 == 0)) { return { kind: 'VmStackList_vm_stk_nil' }; @@ -8775,7 +8775,7 @@ export function loadTextChunkRef(slice: Slice, arg0: number): TextChunkRef { ref: ref }; }; - if ((n == 0)) { + if ((arg0 == 0)) { return { kind: 'TextChunkRef_chunk_ref_empty' }; @@ -8821,7 +8821,7 @@ export function loadTextChunks(slice: Slice, arg0: number): TextChunks { next: next }; }; - if ((n == 0)) { + if ((arg0 == 0)) { return { kind: 'TextChunks_text_chunk_empty' }; diff --git a/generated_test.ts b/generated_test.ts index 2e74b02..eb5481e 100644 --- a/generated_test.ts +++ b/generated_test.ts @@ -1546,3 +1546,42 @@ export function storeTrue(true0: True): (builder: Builder) => void { }; } +export type ParamNamedArgInSecondConstr = ParamNamedArgInSecondConstr_a | ParamNamedArgInSecondConstr_b; +export type ParamNamedArgInSecondConstr_a = { + kind: 'ParamNamedArgInSecondConstr_a'; + n: number; + }; +export type ParamNamedArgInSecondConstr_b = { + kind: 'ParamNamedArgInSecondConstr_b'; + n: number; + }; +export function loadParamNamedArgInSecondConstr(slice: Slice, arg0: number): ParamNamedArgInSecondConstr { + if ((slice.preloadUint(1) == 0b0)) { + slice.loadUint(1); + return { + kind: 'ParamNamedArgInSecondConstr_a', + n: arg0 + }; + }; + if ((slice.preloadUint(1) == 0b1)) { + slice.loadUint(1); + return { + kind: 'ParamNamedArgInSecondConstr_b', + n: (arg0 - 1) + }; + }; + throw new Error(''); + } +export function storeParamNamedArgInSecondConstr(paramNamedArgInSecondConstr: ParamNamedArgInSecondConstr): (builder: Builder) => void { + if ((paramNamedArgInSecondConstr.kind == 'ParamNamedArgInSecondConstr_a')) { + return (builder: Builder) => { + builder.storeUint(0b0, 1); + }; + }; + if ((paramNamedArgInSecondConstr.kind == 'ParamNamedArgInSecondConstr_b')) { + return (builder: Builder) => { + builder.storeUint(0b1, 1); + }; + }; + throw new Error(''); + } diff --git a/src/codegen/util.ts b/src/codegen/util.ts index dbbd30a..be9d22b 100644 --- a/src/codegen/util.ts +++ b/src/codegen/util.ts @@ -233,10 +233,11 @@ export function fillParameterNames(tlbType: TLBType) { if (parameterName != undefined) { parameterNames[i] = parameterName; } - let argName = constructor.parameters[i]?.argName - if (argName) { - argNames[i] = argName - } + + } + let argName = constructor.parameters[i]?.argName + if (argName) { + argNames[i] = argName } } }); @@ -255,6 +256,10 @@ export function fillParameterNames(tlbType: TLBType) { let parameter = constructor.parameters[i] if (argName != undefined && parameter != undefined) { parameter.argName = argName; + if (parameter.paramExpr instanceof TLBVarExpr) { + parameter.variable.deriveExpr = new TLBVarExpr(parameter.argName) + parameter.paramExpr = parameter.variable.deriveExpr + } } } }) diff --git a/tests/fixtures/tlb/test.tlb b/tests/fixtures/tlb/test.tlb index 04904b1..e5d9295 100644 --- a/tests/fixtures/tlb/test.tlb +++ b/tests/fixtures/tlb/test.tlb @@ -98,3 +98,6 @@ _ b:(## 5) = MultipleEmptyConstructor 1; a$_ x:(## 6) = MultipleEmptyConstructor 2; true$_ = True; + +a$0 {n:#} = ParamNamedArgInSecondConstr n; +b$1 {n:#} = ParamNamedArgInSecondConstr (n + 1); \ No newline at end of file diff --git a/tests/tlbgen.spec.ts b/tests/tlbgen.spec.ts index d51b25c..212d902 100644 --- a/tests/tlbgen.spec.ts +++ b/tests/tlbgen.spec.ts @@ -8,7 +8,7 @@ import { generate } from '../src/codegen/main' import { Program } from '../src/ast/nodes' import { BitString, Slice, Builder } from 'ton' -import { TwoConstructors, Simple, loadTwoConstructors, loadSimple, storeTwoConstructors, storeSimple, TypedParam, loadTypedParam, storeTypedParam, TypedField, loadTypedField, storeTypedField, ExprArg, BitLenArg, loadBitLenArg, storeBitLenArg, BitLenArgUser, loadBitLenArgUser, storeBitLenArgUser, ExprArgUser, loadExprArgUser, storeExprArgUser, ComplexTypedField, loadComplexTypedField, storeComplexTypedField, CellTypedField, storeCellTypedField, loadCellTypedField, CellsSimple, loadCellsSimple, storeCellsSimple, IntBitsOutside, loadIntBitsOutside, storeIntBitsOutside, IntBitsParametrizedOutside, loadIntBitsParametrizedOutside, storeIntBitsParametrizedOutside, LessThan, loadLessThan, storeLessThan, Unary, loadUnary, storeUnary, ParamConst, loadParamConst, storeParamConst, ParamDifNames, loadParamDifNames, storeParamDifNames, NegationFromImplicit, loadNegationFromImplicit, storeNegationFromImplicit, loadManyComb, storeManyComb, ManyComb, ParamDifNamesUser, loadParamDifNamesUser, storeParamDifNamesUser, UnaryUserCheckOrder, loadUnaryUserCheckOrder, storeUnaryUserCheckOrder, CombArgCellRef, loadCombArgCellRef, storeCombArgCellRef, CombArgCellRefUser, loadCombArgCellRefUser, storeCombArgCellRefUser, MathExprAsCombArg, loadMathExprAsCombArg, storeMathExprAsCombArg, SharpConstructor, loadSharpConstructor, storeSharpConstructor, EmptyTag, loadEmptyTag, storeEmptyTag, SharpTag, loadSharpTag, storeSharpTag, DollarTag, loadDollarTag, storeDollarTag, TupleCheck, loadTupleCheck, storeTupleCheck, HashmapE, loadHashmapE, storeHashmapE, HashmapEUser, loadHashmapEUser, storeHashmapEUser, ConditionalField, loadConditionalField, storeConditionalField, BitSelection, loadBitSelection, storeBitSelection, ImplicitCondition, loadImplicitCondition, storeImplicitCondition, MultipleEmptyConstructor, loadMultipleEmptyConstructor, storeMultipleEmptyConstructor, True, loadTrue, storeTrue } from '../generated_test' +import { TwoConstructors, Simple, loadTwoConstructors, loadSimple, storeTwoConstructors, storeSimple, TypedParam, loadTypedParam, storeTypedParam, TypedField, loadTypedField, storeTypedField, ExprArg, BitLenArg, loadBitLenArg, storeBitLenArg, BitLenArgUser, loadBitLenArgUser, storeBitLenArgUser, ExprArgUser, loadExprArgUser, storeExprArgUser, ComplexTypedField, loadComplexTypedField, storeComplexTypedField, CellTypedField, storeCellTypedField, loadCellTypedField, CellsSimple, loadCellsSimple, storeCellsSimple, IntBitsOutside, loadIntBitsOutside, storeIntBitsOutside, IntBitsParametrizedOutside, loadIntBitsParametrizedOutside, storeIntBitsParametrizedOutside, LessThan, loadLessThan, storeLessThan, Unary, loadUnary, storeUnary, ParamConst, loadParamConst, storeParamConst, ParamDifNames, loadParamDifNames, storeParamDifNames, NegationFromImplicit, loadNegationFromImplicit, storeNegationFromImplicit, loadManyComb, storeManyComb, ManyComb, ParamDifNamesUser, loadParamDifNamesUser, storeParamDifNamesUser, UnaryUserCheckOrder, loadUnaryUserCheckOrder, storeUnaryUserCheckOrder, CombArgCellRef, loadCombArgCellRef, storeCombArgCellRef, CombArgCellRefUser, loadCombArgCellRefUser, storeCombArgCellRefUser, MathExprAsCombArg, loadMathExprAsCombArg, storeMathExprAsCombArg, SharpConstructor, loadSharpConstructor, storeSharpConstructor, EmptyTag, loadEmptyTag, storeEmptyTag, SharpTag, loadSharpTag, storeSharpTag, DollarTag, loadDollarTag, storeDollarTag, TupleCheck, loadTupleCheck, storeTupleCheck, HashmapE, loadHashmapE, storeHashmapE, HashmapEUser, loadHashmapEUser, storeHashmapEUser, ConditionalField, loadConditionalField, storeConditionalField, BitSelection, loadBitSelection, storeBitSelection, ImplicitCondition, loadImplicitCondition, storeImplicitCondition, MultipleEmptyConstructor, loadMultipleEmptyConstructor, storeMultipleEmptyConstructor, True, loadTrue, storeTrue, ParamNamedArgInSecondConstr, loadParamNamedArgInSecondConstr, storeParamNamedArgInSecondConstr } from '../generated_test' import { beginCell } from 'ton' const fixturesDir = path.resolve(__dirname, 'fixtures') @@ -127,6 +127,8 @@ describe('Generating tlb code', () => { checkThrowOnStoreLoad(lessThanIncorrectX, loadLessThan, storeLessThan); let lessThanIncorrectY: LessThan = {kind: 'LessThan', x: 3, y: 8} checkThrowOnStoreLoad(lessThanIncorrectY, loadLessThan, storeLessThan); + let paramNamedArgInSecondConstr: ParamNamedArgInSecondConstr = {kind: 'ParamNamedArgInSecondConstr_a', n: 3} + checkSameOnStoreLoad(paramNamedArgInSecondConstr, (slice: Slice) => { return loadParamNamedArgInSecondConstr(slice, 3) }, storeParamNamedArgInSecondConstr); }) test('Combinators', () => {