Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Jan 13, 2024
1 parent 47b8496 commit d8628a3
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export type TLBVarIntegerType = {

export type TLBHashmapType = {
kind: "TLBHashmapType";
key: TLBFieldType,
key: TLBMathExprType,
value: TLBFieldType
}

Expand Down
3 changes: 3 additions & 0 deletions src/astbuilder/handle_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export function getType(
}
let key = getType(expr.args[0], constructor, fieldTypeName)
let value = getType(expr.args[1], constructor, fieldTypeName)
if (key.kind != 'TLBExprMathType') {
throw new Error('Hashmap key should be number')
}
return { kind: "TLBHashmapType", key: key, value: value };
} else if (
expr.name == "VarUInteger" &&
Expand Down
15 changes: 3 additions & 12 deletions src/generators/typescript/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import {
getParamVarExpr,
getTypeParametersExpression,
isBigInt,
isBigIntExpr,
} from "./utils";

/*
Expand Down Expand Up @@ -589,9 +590,6 @@ export class TypescriptGenerator implements CodeGenerator {
);
});
} else if (field.subFields.length == 0) {
if (field == undefined) {
throw new Error("");
}
let fieldInfo = this.handleType(
field,
field.fieldType,
Expand Down Expand Up @@ -762,12 +760,7 @@ export class TypescriptGenerator implements CodeGenerator {
throw new Error("Address has type other than ['Internal', 'External', 'Any']")
}
} else if (fieldType.kind == "TLBHashmapType") {
let key: Expression
if (fieldType.key.kind == 'TLBExprMathType') {
key = tFunctionCall(tMemberExpression(id('Dictionary.Keys'), id('Uint')), [convertToAST(fieldType.key.expr, ctx.constructor)]);
} else {
throw new Error('')
}
let key: Expression = tFunctionCall(tMemberExpression(id('Dictionary.Keys'), (isBigIntExpr(fieldType.key) ? id('BigUint') : id('Uint'))), [convertToAST(fieldType.key.expr, ctx.constructor)]);
let subExprInfo = this.handleType(
field,
fieldType.value,
Expand Down Expand Up @@ -799,14 +792,12 @@ export class TypescriptGenerator implements CodeGenerator {
)
]))]
))
result.typeParamExpr = tTypeWithParameters(id('Dictionary'), tTypeParametersExpression([id('number'), subExprInfo.typeParamExpr]))
result.typeParamExpr = tTypeWithParameters(id('Dictionary'), tTypeParametersExpression([ (isBigIntExpr(fieldType.key) ? id('bigint') : id('number')), subExprInfo.typeParamExpr]))
}
storeParametersInside = storeParametersInside.concat([key, value])
storeParametersOutside = storeParametersOutside.concat([key, value])
result.storeStmtInside = tExpressionStatement(tFunctionCall(tMemberExpression(id(currentCell), id('storeDict')), storeParametersInside))
result.storeStmtOutside = tExpressionStatement(tFunctionCall(tMemberExpression(id(currentCell), id('storeDict')), storeParametersOutside))
if (subExprInfo.loadExpr)
console.log(toCode(subExprInfo.loadExpr).code)
} else if (fieldType.kind == "TLBExprMathType") {
result.loadExpr = convertToAST(fieldType.expr, ctx.constructor);
result.storeStmtOutside = tExpressionStatement(result.loadExpr);
Expand Down
8 changes: 8 additions & 0 deletions src/generators/typescript/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TLBCode,
TLBConstructor,
TLBMathExpr,
TLBMathExprType,
TLBNumberExpr,
TLBNumberType,
TLBParameter,
Expand Down Expand Up @@ -215,6 +216,13 @@ export function getCondition(conditions: Array<BinaryExpression>): Expression {
}
}

export function isBigIntExpr(fieldType: TLBMathExprType) {
if (fieldType.expr instanceof TLBNumberExpr && fieldType.expr.n <= 64) {
return false;
}
return true;
}

export function isBigInt(fieldType: TLBNumberType) {
if (fieldType.bits instanceof TLBNumberExpr) {
if (fieldType.bits.n <= 64) {
Expand Down
Loading

0 comments on commit d8628a3

Please sign in to comment.