Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Dec 30, 2023
1 parent 3f49fad commit c1e07ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
8 changes: 4 additions & 4 deletions generated_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export interface LoadFromNegationOutsideExpr {
export interface AnonymousData {
readonly kind: 'AnonymousData';
readonly anon0: number;
readonly anon0: number;
readonly anon0_0: number;
}

export interface FalseAnonField {
Expand Down Expand Up @@ -2285,19 +2285,19 @@ export function storeLoadFromNegationOutsideExpr(loadFromNegationOutsideExpr: Lo

export function loadAnonymousData(slice: Slice): AnonymousData {
let anon0: number = slice.loadUint(1);
let anon0: number = slice.loadUint(32);
let anon0_0: number = slice.loadUint(32);
return {
kind: 'AnonymousData',
anon0: anon0,
anon0: anon0,
anon0_0: anon0_0,
}

}

export function storeAnonymousData(anonymousData: AnonymousData): (builder: Builder) => void {
return ((builder: Builder) => {
builder.storeUint(anonymousData.anon0, 1);
builder.storeUint(anonymousData.anon0, 32);
builder.storeUint(anonymousData.anon0_0, 32);
})

}
Expand Down
23 changes: 14 additions & 9 deletions src/codegen/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleExpr, NameExpr, NumberExpr, MathExpr, FieldBuiltinDef, NegateExpr, Declaration, CompareExpr, FieldCurlyExprDef, FieldNamedDef } from "../ast/nodes";
import { SimpleExpr, NameExpr, NumberExpr, MathExpr, FieldBuiltinDef, NegateExpr, Declaration, CompareExpr, FieldCurlyExprDef, FieldNamedDef, FieldAnonymousDef, FieldExprDef } from "../ast/nodes";
import { TLBMathExpr, TLBVarExpr, TLBNumberExpr, TLBBinaryOp, TLBCode, TLBType, TLBConstructorTag, TLBConstructor, TLBParameter, TLBVariable, TLBField } from "./ast"
import * as crc32 from "crc-32";
import { fillFields } from "./astbuilder/handle_field";
Expand Down Expand Up @@ -382,23 +382,22 @@ function opCodeSetsEqual(a: string[], b: string[]) {
return true;
}

export function fixCurrentVariableName(variable: TLBVariable, variablesSet: Set<string>) {
export function fixCurrentVariableName(field: TLBField, variablesSet: Set<string>) {
let index = 0;
while (variablesSet.has(variable.name)) {
variable.name = goodVariableName(variable.name + '_' + index)
field.name = goodVariableName(field.name)
while (variablesSet.has(field.name)) {
field.name = goodVariableName(field.name + '_' + index)
index++;
}
variablesSet.add(field.name)
}

export function fixVariablesNaming(tlbCode: TLBCode) {
tlbCode.types.forEach(tlbType => {
tlbType.constructors.forEach(constructor => {
let variablesSet = new Set<string>();
constructor.variables.forEach(variable => {
fixCurrentVariableName(variable, variablesSet)
})
constructor.parameters.forEach(parameter => {
fixCurrentVariableName(parameter.variable, variablesSet)
constructor.fields.forEach(field => {
fixCurrentVariableName(field, variablesSet)
})
})
})
Expand Down Expand Up @@ -453,13 +452,19 @@ export function fillConstructors(declarations: Declaration[], tlbCode: TLBCode,
typeDeclarations.get(tlbType.name)?.forEach((typeItem) => {
let declaration = typeItem.declaration;
let constructor = typeItem.constructor;

let fieldIndex = 0;
declaration.fields.forEach(field => {
if (field instanceof FieldBuiltinDef) {
constructor.variables.push({ name: field.name, const: false, negated: false, type: field.type, calculated: false, isField: false })
}
if (field instanceof FieldNamedDef) {
constructor.variables.push({ name: field.name, const: false, negated: false, type: '#', calculated: false, isField: true })
}
if (field instanceof FieldExprDef) {
constructor.variables.push({ name: 'anon' + fieldIndex, const: false, negated: false, type: '#', calculated: false, isField: true })
}
fieldIndex++;
})
constructor.variables.forEach(variable => {
constructor.variablesMap.set(variable.name, variable);
Expand Down
2 changes: 1 addition & 1 deletion tests/tlbgen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('Generating tlb code', () => {
checkThrowOnStoreLoad(lessThanIncorrectY, loadLessThan, storeLessThan);
let paramNamedArgInSecondConstr: ParamNamedArgInSecondConstr = {kind: 'ParamNamedArgInSecondConstr_a', n: 3}
checkSameOnStoreLoad(paramNamedArgInSecondConstr, (slice: Slice) => { return loadParamNamedArgInSecondConstr(slice, 3) }, storeParamNamedArgInSecondConstr);
let anonymousData: AnonymousData = {kind: 'AnonymousData', anon0: 1}
let anonymousData: AnonymousData = {kind: 'AnonymousData', anon0: 1, anon0_0: 3}
checkSameOnStoreLoad(anonymousData, loadAnonymousData, storeAnonymousData);
let falseAnonField: FalseAnonField = {kind: 'FalseAnonField', value: BigInt(3)}
checkSameOnStoreLoad(falseAnonField, loadFalseAnonField, storeFalseAnonField)
Expand Down

0 comments on commit c1e07ef

Please sign in to comment.