Skip to content

Commit

Permalink
Switch slice to cell
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyProgrammist committed Feb 14, 2024
1 parent 731a7b5 commit bde2d9d
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 157 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/generators/typescript/complex_expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function bitlenFunctionDecl(): GenDeclaration {
export function typedSlice() {
return [tTypedIdentifier(id("slice"), id("Slice"))];
}

export function sliceLoad(slicePrefix: number[], currentSlice: string) {
return tExpressionStatement(
tDeclareVariable(
Expand Down Expand Up @@ -141,7 +142,7 @@ export function storeExprForParam(theCell: string, exprForParam: ExprForParam, i
}
export function returnSliceFunc(): Expression {
return tArrowFunctionExpression(typedSlice(), [
tReturnStatement(id("slice")),
tReturnStatement(tFunctionCall(tMemberExpression(id("slice"), id("asCell")), [])),
]);
}
export function loadExprForParam(currentSlice: string, exprForParam: ExprForParam): Expression {
Expand Down
18 changes: 13 additions & 5 deletions src/generators/typescript/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,18 @@ export class TypescriptGenerator implements CodeGenerator {
exprForParam = {
argLoadExpr: id(theSlice),
argStoreExpr: id(theSlice),
paramType: "Slice",
fieldLoadSuffix: "Slice",
paramType: "Cell",
fieldLoadSuffix: "Ref",
fieldStoreSuffix: "Slice",
};
storeParametersOutside[0] = tFunctionCall(
tMemberExpression(storeParametersOutside[0], id("beginParse")),
[id("true")]
)
storeParametersInside[0] = tFunctionCall(
tMemberExpression(storeParametersInside[0], id("beginParse")),
[id("true")]
)
} else if (fieldType.kind == "TLBBoolType") {
exprForParam = {
argLoadExpr: undefined,
Expand Down Expand Up @@ -994,16 +1002,16 @@ export class TypescriptGenerator implements CodeGenerator {
if (exprForParam) {
if (
exprForParam.paramType != "BitString" &&
exprForParam.paramType != "Slice"
exprForParam.paramType != "Cell"
) {
if (exprForParam.argStoreExpr) {
storeParametersOutside.push(exprForParam.argStoreExpr);
storeParametersInside.push(exprForParam.argStoreExpr);
}
}
result.loadExpr = loadExprForParam(currentSlice, exprForParam);
if (exprForParam.paramType == "Slice") {
result.loadExpr = id(currentSlice);
if (exprForParam.paramType == "Cell") {
result.loadExpr = tFunctionCall(tMemberExpression(id(currentSlice), id('asCell')), []);
result.loadFunctionExpr = returnSliceFunc();
}
result.typeParamExpr = id(exprForParam.paramType);
Expand Down
Loading

0 comments on commit bde2d9d

Please sign in to comment.