Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Dec 21, 2023
1 parent 892591e commit 2bb9f39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/codegen/astbuilder/handle_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export function getType(expr: ParserExpression, fieldName: string, isField: bool
// }

// result.storeExpr2 = storeExpr2
return {name: 'hello', arguments: []}// {new TLBNumberExpr(3)};
return {kind: 'TLBNamedType', name: 'hello', arguments: []}// {new TLBNumberExpr(3)};
}


Expand Down
36 changes: 18 additions & 18 deletions src/codegen/generators/typescript/field_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { handleType } from './type_handler'
import { addLoadProperty, getNegationDerivationFunctionBody, getParamVarExpr, sliceLoad } from './utils'
import { goodVariableName } from '../../utils'

export function handleField(field: FieldDefinition, slicePrefix: Array<number>, tlbCode: TLBCode, constructor: TLBConstructor, constructorLoadStatements: Statement[], subStructStoreStatements: Statement[], subStructProperties: TypedIdentifier[], subStructLoadProperties: ObjectProperty[], variableCombinatorName: string, variableSubStructName: string, jsCodeFunctionsDeclarations: GenDeclaration[], fieldIndex: string) {
export function handleField(fieldDefinition: FieldDefinition, slicePrefix: Array<number>, tlbCode: TLBCode, constructor: TLBConstructor, constructorLoadStatements: Statement[], subStructStoreStatements: Statement[], subStructProperties: TypedIdentifier[], subStructLoadProperties: ObjectProperty[], variableCombinatorName: string, variableSubStructName: string, jsCodeFunctionsDeclarations: GenDeclaration[], fieldIndex: string) {
let currentSlice = getCurrentSlice(slicePrefix, 'slice');
let currentCell = getCurrentSlice(slicePrefix, 'cell');

if (field instanceof FieldAnonymousDef) {
if (fieldDefinition instanceof FieldAnonymousDef) {
slicePrefix[slicePrefix.length - 1]++;
slicePrefix.push(0)

constructorLoadStatements.push(sliceLoad(slicePrefix, currentSlice))
subStructStoreStatements.push(tExpressionStatement(tDeclareVariable(tIdentifier(getCurrentSlice(slicePrefix, 'cell')), tFunctionCall(tIdentifier('beginCell'), []))))

field.fields.forEach(field => {
fieldDefinition.fields.forEach(field => {
handleField(field, slicePrefix, tlbCode, constructor, constructorLoadStatements, subStructStoreStatements, subStructProperties, subStructLoadProperties, variableCombinatorName, variableSubStructName, jsCodeFunctionsDeclarations, fieldIndex)
});

Expand All @@ -27,28 +27,28 @@ export function handleField(field: FieldDefinition, slicePrefix: Array<number>,
slicePrefix.pop();
}

if (field instanceof FieldBuiltinDef && field.type != 'Type') {
subStructProperties.push(tTypedIdentifier(tIdentifier(goodVariableName(field.name)), tIdentifier('number')));
let parameter = constructor.parametersMap.get(field.name)
if (fieldDefinition instanceof FieldBuiltinDef && fieldDefinition.type != 'Type') {
subStructProperties.push(tTypedIdentifier(tIdentifier(goodVariableName(fieldDefinition.name)), tIdentifier('number')));
let parameter = constructor.parametersMap.get(fieldDefinition.name)
if (parameter && !parameter.variable.const && !parameter.variable.negated) {
subStructLoadProperties.push(tObjectProperty(tIdentifier(goodVariableName(field.name)), getParamVarExpr(parameter, constructor)))
subStructLoadProperties.push(tObjectProperty(tIdentifier(goodVariableName(fieldDefinition.name)), getParamVarExpr(parameter, constructor)))
}
}

if (field instanceof FieldNamedDef || field instanceof FieldExprDef) {
if (fieldDefinition instanceof FieldNamedDef || fieldDefinition instanceof FieldExprDef) {
let fieldName: string;
if (field instanceof FieldNamedDef) {
fieldName = field.name;
if (fieldDefinition instanceof FieldNamedDef) {
fieldName = fieldDefinition.name;
} else {
fieldName = 'anon' + fieldIndex;
}
if (field instanceof FieldExprDef && field.expr instanceof NameExpr && field.expr.name == '_') {
if (fieldDefinition instanceof FieldExprDef && fieldDefinition.expr instanceof NameExpr && fieldDefinition.expr.name == '_') {
return;
}

if (field.expr instanceof CellRefExpr) {
if (fieldDefinition.expr instanceof CellRefExpr) {

if (field.expr.expr instanceof CombinatorExpr && (field.expr.expr.name == 'MERKLE_UPDATE' || field.expr.expr.name == 'MERKLE_ROOT')) {
if (fieldDefinition.expr.expr instanceof CombinatorExpr && (fieldDefinition.expr.expr.name == 'MERKLE_UPDATE' || fieldDefinition.expr.expr.name == 'MERKLE_ROOT')) {
slicePrefix[slicePrefix.length - 1]++;
slicePrefix.push(0);
constructorLoadStatements.push(
Expand All @@ -68,21 +68,21 @@ export function handleField(field: FieldDefinition, slicePrefix: Array<number>,
slicePrefix.push(0)
constructorLoadStatements.push(sliceLoad(slicePrefix, currentSlice))
subStructStoreStatements.push(tExpressionStatement(tDeclareVariable(tIdentifier(getCurrentSlice(slicePrefix, 'cell')), tFunctionCall(tIdentifier('beginCell'), []))))
handleField(new FieldNamedDef(fieldName, field.expr.expr), slicePrefix, tlbCode, constructor, constructorLoadStatements, subStructStoreStatements, subStructProperties, subStructLoadProperties, variableCombinatorName, variableSubStructName, jsCodeFunctionsDeclarations, fieldIndex)
handleField(new FieldNamedDef(fieldName, fieldDefinition.expr.expr), slicePrefix, tlbCode, constructor, constructorLoadStatements, subStructStoreStatements, subStructProperties, subStructLoadProperties, variableCombinatorName, variableSubStructName, jsCodeFunctionsDeclarations, fieldIndex)
subStructStoreStatements.push(tExpressionStatement(tFunctionCall(tMemberExpression(tIdentifier(currentCell), tIdentifier('storeRef')), [tIdentifier(getCurrentSlice(slicePrefix, 'cell'))])))
slicePrefix.pop();
}
}

if (field.expr instanceof CombinatorExpr || field.expr instanceof NameExpr || field.expr instanceof BuiltinZeroArgs || field.expr instanceof BuiltinOneArgExpr || field.expr instanceof MathExpr || field.expr instanceof CondExpr) {
if (fieldDefinition.expr instanceof CombinatorExpr || fieldDefinition.expr instanceof NameExpr || fieldDefinition.expr instanceof BuiltinZeroArgs || fieldDefinition.expr instanceof BuiltinOneArgExpr || fieldDefinition.expr instanceof MathExpr || fieldDefinition.expr instanceof CondExpr) {
let tmpTypeName: string;
if (field.expr instanceof MathExpr || field.expr instanceof CondExpr) {
if (fieldDefinition.expr instanceof MathExpr || fieldDefinition.expr instanceof CondExpr) {
tmpTypeName = ''
} else {
tmpTypeName = field.expr.name;
tmpTypeName = fieldDefinition.expr.name;
}

let fieldInfo = handleType(field.expr, fieldName, true, false, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, tmpTypeName, 0, tlbCode, subStructLoadProperties);
let fieldInfo = handleType(fieldDefinition.expr, fieldName, true, false, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, tmpTypeName, 0, tlbCode, subStructLoadProperties);
if (fieldInfo.loadExpr) {
addLoadProperty(goodVariableName(fieldName), fieldInfo.loadExpr, fieldInfo.typeParamExpr, constructorLoadStatements, subStructLoadProperties);
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export function fillConstructors(declarations: Declaration[], tlbCode: TLBCode,
fixNaming(tlbType);
tlbType.constructors.sort(compareConstructors)
});
// fillFields(tlbCode);
fillFields(tlbCode);
checkAndRemovePrimitives(tlbCode, input);
}
export function isBadVarName(name: string): boolean {
Expand Down

0 comments on commit 2bb9f39

Please sign in to comment.