Skip to content

Commit

Permalink
refactor expression writer
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov committed Feb 16, 2024
1 parent 738b6f8 commit 51abcff
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions src/generator/writers/writeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,36 +261,12 @@ export function writeExpression(f: ASTExpression, ctx: WriterContext): string {
return `__tact_cell_${op}(${writeExpression(f.right, ctx)}, ${writeExpression(f.left, ctx)})`;
}

// Case for slices equality
// Case for slices and strings equality
if (
lt.kind === 'ref' &&
rt.kind === 'ref' &&
lt.name === 'Slice' &&
rt.name === 'Slice'
) {
let op = f.op === '==' ? 'eq' : 'neq';
if (lt.optional && rt.optional) {
ctx.used(`__tact_slice_${op}_nullable`);
return `__tact_slice_${op}_nullable(${writeExpression(f.left, ctx)}, ${writeExpression(f.right, ctx)})`;
}
if (lt.optional && !rt.optional) {
ctx.used(`__tact_slice_${op}_nullable_one`);
return `__tact_slice_${op}_nullable_one(${writeExpression(f.left, ctx)}, ${writeExpression(f.right, ctx)})`;
}
if (!lt.optional && rt.optional) {
ctx.used(`__tact_slice_${op}_nullable_one`);
return `__tact_slice_${op}_nullable_one(${writeExpression(f.right, ctx)}, ${writeExpression(f.left, ctx)})`;
}
ctx.used(`__tact_slice_${op}`);
return `__tact_slice_${op}(${writeExpression(f.right, ctx)}, ${writeExpression(f.left, ctx)})`;
}

// Case for strings equality
if (
lt.kind === 'ref' &&
rt.kind === 'ref' &&
lt.name === 'String' &&
rt.name === 'String'
lt.name === rt.name &&
(lt.name === 'Slice' || lt.name === 'String')
) {
let op = f.op === '==' ? 'eq' : 'neq';
if (lt.optional && rt.optional) {
Expand Down

0 comments on commit 51abcff

Please sign in to comment.