Skip to content

Commit 70260e1

Browse files
Updated interfaces (getTLBCode, getTLBCodeByAST, add initial expression to TLBExprMathType and other utils), release v1.1.0
1 parent e28897d commit 70260e1

8 files changed

Lines changed: 392 additions & 10 deletions

File tree

index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { generateCode } from "./src/main";
2-
export { generateCode, generateCodeByAST, generateCodeWithGenerator } from "./src/main";
2+
export * from "./src/ast";
3+
export { generateCode, getTLBCode, getTLBCodeByAST, generateCodeByAST, generateCodeWithGenerator } from "./src/main";
4+
export { isBigInt as isBigIntForJson, isBigIntExpr as isBigIntExprForJson } from "./src/generators/typescript/utils";
35
export { CodeGenerator } from "./src/generators/generator";
46
export { TypescriptGenerator } from "./src/generators/typescript/generator";

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ton-community/tlb-codegen",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "",
55
"main": "build/index.js",
66
"scripts": {

src/ast.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export type TLBNamedType = {
7070
export type TLBMathExprType = {
7171
kind: "TLBExprMathType";
7272
expr: TLBMathExpr;
73+
initialExpr: TLBMathExpr;
7374
};
7475

7576
export type TLBBoolType = {

src/astbuilder/handle_type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,14 @@ export function getType(
278278
return {
279279
kind: "TLBExprMathType",
280280
expr: getCalculatedExpression(new TLBVarExpr(expr.name), constructor),
281+
initialExpr: new TLBVarExpr(expr.name),
281282
};
282283
} else {
283284
return { kind: "TLBNamedType", name: expr.name, arguments: [] };
284285
}
285286
}
286287
} else if (expr instanceof NumberExpr) {
287-
return { kind: "TLBExprMathType", expr: new TLBNumberExpr(expr.num) };
288+
return { kind: "TLBExprMathType", expr: new TLBNumberExpr(expr.num), initialExpr: new TLBNumberExpr(expr.num) };
288289
} else if (expr instanceof NegateExpr && expr.expr instanceof NameExpr) {
289290
return { kind: "TLBNegatedType", variableName: expr.expr.name };
290291
} else if (expr instanceof CellRefExpr) {
@@ -309,6 +310,7 @@ export function getType(
309310
return {
310311
kind: "TLBExprMathType",
311312
expr: getCalculatedExpression(convertToMathExpr(expr), constructor),
313+
initialExpr: convertToMathExpr(expr),
312314
};
313315
}
314316
} else if (expr instanceof CondExpr) {

src/main.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,29 @@ import { CodeGenerator, CommonGenDeclaration } from "./generators/generator";
1111
import { TypescriptGenerator } from "./generators/typescript/generator";
1212
import fs from 'fs'
1313

14-
15-
export function generateCodeByAST(tree: Program, input: string, getGenerator: (tlbCode: TLBCode) => CodeGenerator) {
14+
export function getTLBCodeByAST(tree: Program, input: string) {
1615
let oldTlbCode: TLBCodeBuild = { types: new Map<string, TLBTypeBuild>() };
17-
1816
let splittedInput = input.split("\n");
19-
2017
fillConstructors(tree.declarations, oldTlbCode, splittedInput);
2118
let tlbCode: TLBCode = convertCodeToReadonly(oldTlbCode);
2219

20+
return tlbCode;
21+
}
22+
23+
export function getTLBCode(inputPath: string) {
24+
const input = fs.readFileSync(
25+
inputPath,
26+
'utf-8',
27+
)
28+
29+
const tree = ast(input)
30+
31+
return getTLBCodeByAST(tree, input);
32+
}
33+
34+
35+
export function generateCodeByAST(tree: Program, input: string, getGenerator: (tlbCode: TLBCode) => CodeGenerator) {
36+
let tlbCode = getTLBCodeByAST(tree, input)
2337
let codeGenerator: CodeGenerator = getGenerator(tlbCode);
2438

2539
codeGenerator.addTonCoreClassUsage("Builder");

0 commit comments

Comments
 (0)