Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Dec 22, 2023
1 parent 9073dbb commit a5d3852
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/codegen/generators/typescript/handle_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function handleField(field: TLBField | undefined, fieldDefinition: FieldD
else {
throw new Error('')
}
let fieldInfo = handleType(field, thefield, true, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, tmpTypeName, 0, tlbCode);
let fieldInfo = handleType(field, thefield, true, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, 0, tlbCode);
if (fieldInfo.loadExpr) {
addLoadProperty(goodVariableName(fieldName), fieldInfo.loadExpr, fieldInfo.typeParamExpr, constructorLoadStatements, subStructLoadProperties);
}
Expand Down
15 changes: 9 additions & 6 deletions src/codegen/generators/typescript/handle_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function isBigInt(fieldType: TLBNumberType) {
return true;
}

export function handleType(field: TLBField, fieldType: TLBFieldType, isField: boolean, variableCombinatorName: string, variableSubStructName: string, currentSlice: string, currentCell: string, constructor: TLBConstructor, jsCodeFunctionsDeclarations: GenDeclaration[], fieldTypeName: string, argIndex: number, tlbCode: TLBCode): FieldInfoType {
export function handleType(field: TLBField, fieldType: TLBFieldType, isField: boolean, variableCombinatorName: string, variableSubStructName: string, currentSlice: string, currentCell: string, constructor: TLBConstructor, jsCodeFunctionsDeclarations: GenDeclaration[], argIndex: number, tlbCode: TLBCode): FieldInfoType {
let fieldName = field.name
let theSlice = 'slice'; // TODO: use slice from field
let theCell = 'builder';
Expand Down Expand Up @@ -83,7 +83,10 @@ export function handleType(field: TLBField, fieldType: TLBFieldType, isField: bo
result.storeExpr = tExpressionStatement(result.loadExpr)
} else if (fieldType.kind == 'TLBNegatedType') {
let getParameterFunctionId = tIdentifier(variableSubStructName + '_get_' + fieldType.variableName)
jsCodeFunctionsDeclarations.push(tFunctionDeclaration(getParameterFunctionId, tTypeParametersExpression([]), tIdentifier('number'), [tTypedIdentifier(tIdentifier(goodVariableName(fieldName)), tIdentifier(fieldTypeName))], getNegationDerivationFunctionBody(tlbCode, fieldTypeName, argIndex, fieldName)))
if (field.fieldType.kind == 'TLBNamedType') {
let fieldTypeName = field.fieldType.name
jsCodeFunctionsDeclarations.push(tFunctionDeclaration(getParameterFunctionId, tTypeParametersExpression([]), tIdentifier('number'), [tTypedIdentifier(tIdentifier(goodVariableName(fieldName)), tIdentifier(fieldTypeName))], getNegationDerivationFunctionBody(tlbCode, fieldTypeName, argIndex, fieldName)))
}
result.negatedVariablesLoads.push({ name: fieldType.variableName, expression: tFunctionCall(getParameterFunctionId, [tIdentifier(goodVariableName(fieldName))]) })
} else if (fieldType.kind == 'TLBNamedType' && fieldType.arguments.length == 0) {
let typeName = fieldType.name;
Expand All @@ -99,7 +102,7 @@ export function handleType(field: TLBField, fieldType: TLBFieldType, isField: bo
} else if (fieldType.kind == 'TLBCondType') {
let subExprInfo: FieldInfoType
let conditionExpr: Expression;
subExprInfo = handleType(field, fieldType.value, true, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, fieldTypeName, argIndex, tlbCode);
subExprInfo = handleType(field, fieldType.value, true, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, argIndex, tlbCode);
conditionExpr = convertToAST(fieldType.condition, constructor, true)
if (subExprInfo.typeParamExpr) {
result.typeParamExpr = tUnionTypeExpression([subExprInfo.typeParamExpr, tIdentifier('undefined')])
Expand All @@ -117,7 +120,7 @@ export function handleType(field: TLBField, fieldType: TLBFieldType, isField: bo
let arrayLength: Expression
let subExprInfo: FieldInfoType
arrayLength = convertToAST(fieldType.times, constructor, true);
subExprInfo = handleType(field, fieldType.value, false, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, fieldTypeName, argIndex, tlbCode);
subExprInfo = handleType(field, fieldType.value, false, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, argIndex, tlbCode);
let currentParam = insideStoreParameters[0]
let currentParam2 = insideStoreParameters2[0]
if (subExprInfo.loadExpr) {
Expand All @@ -137,7 +140,7 @@ export function handleType(field: TLBField, fieldType: TLBFieldType, isField: bo
let currentCell = getCurrentSlice([1, 0], 'cell');

let subExprInfo: FieldInfoType;
subExprInfo = handleType(field, fieldType.value, true, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, fieldTypeName, argIndex, tlbCode)
subExprInfo = handleType(field, fieldType.value, true, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, argIndex, tlbCode)
if (subExprInfo.loadExpr) {
result.typeParamExpr = subExprInfo.typeParamExpr;
result.storeExpr = subExprInfo.storeExpr;
Expand Down Expand Up @@ -169,7 +172,7 @@ export function handleType(field: TLBField, fieldType: TLBFieldType, isField: bo
if (fieldType.kind == 'TLBNamedType') {
fieldType.arguments.forEach(arg => {
argIndex++;
let subExprInfo = handleType(field, arg, false, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, fieldTypeName, argIndex, tlbCode);
let subExprInfo = handleType(field, arg, false, variableCombinatorName, variableSubStructName, currentSlice, currentCell, constructor, jsCodeFunctionsDeclarations, argIndex, tlbCode);
if (subExprInfo.typeParamExpr) {
typeExpression.typeParameters.push(subExprInfo.typeParamExpr);
}
Expand Down

0 comments on commit a5d3852

Please sign in to comment.