Skip to content

Commit

Permalink
fix arg name if it is in second constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Dec 9, 2023
1 parent bc466d4 commit 1f8e385
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
14 changes: 7 additions & 7 deletions generated_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,13 @@ export type VarHashmapNode_vhmn_cont<X> = {
child: VarHashmap<X>;
value: X;
};
export function loadVarHashmapNode<X>(slice: Slice, n: number, loadX: (slice: Slice) => X): VarHashmapNode<X> {
export function loadVarHashmapNode<X>(slice: Slice, arg0: number, loadX: (slice: Slice) => X): VarHashmapNode<X> {
if ((slice.preloadUint(2) == 0b00)) {
slice.loadUint(2);
let value: X = loadX(slice);
return {
kind: 'VarHashmapNode_vhmn_leaf',
n: n,
n: arg0,
value: value
};
};
Expand Down Expand Up @@ -919,13 +919,13 @@ export type PfxHashmapNode_phmn_fork<X> = {
left: PfxHashmap<X>;
right: PfxHashmap<X>;
};
export function loadPfxHashmapNode<X>(slice: Slice, n: number, loadX: (slice: Slice) => X): PfxHashmapNode<X> {
export function loadPfxHashmapNode<X>(slice: Slice, arg0: number, loadX: (slice: Slice) => X): PfxHashmapNode<X> {
if ((slice.preloadUint(1) == 0b0)) {
slice.loadUint(1);
let value: X = loadX(slice);
return {
kind: 'PfxHashmapNode_phmn_leaf',
n: n,
n: arg0,
value: value
};
};
Expand Down Expand Up @@ -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'
};
Expand Down Expand Up @@ -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'
};
Expand Down Expand Up @@ -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'
};
Expand Down
39 changes: 39 additions & 0 deletions generated_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
}
13 changes: 9 additions & 4 deletions src/codegen/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
});
Expand All @@ -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
}
}
}
})
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/tlb/test.tlb
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 3 additions & 1 deletion tests/tlbgen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 1f8e385

Please sign in to comment.