Skip to content

Commit

Permalink
feat: conditional expressions (#97)
Browse files Browse the repository at this point in the history
The ternary conditional operator `? :` is right-associative as common in languages
with C-like syntax

---------

Co-authored-by: Anton Trunov <[email protected]>
  • Loading branch information
Gusarich and anton-trunov authored Feb 15, 2024
1 parent 23452a8 commit 4ff1bb6
Show file tree
Hide file tree
Showing 32 changed files with 1,770 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/generator/writers/writeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,14 @@ export function writeExpression(f: ASTExpression, ctx: WriterContext): string {
return `${ops.contractInitChild(f.name, ctx)}(${['__tact_context_sys', ...f.args.map((a, i) => writeCastedExpression(a, type.init!.args[i].type, ctx))].join(', ')})`;
}

//
// Ternary operator
//

if (f.kind === 'conditional') {
return `(${writeExpression(f.condition, ctx)} ? ${writeExpression(f.thenBranch, ctx)} : ${writeExpression(f.elseBranch, ctx)})`;
}

//
// Unreachable
//
Expand Down
Loading

0 comments on commit 4ff1bb6

Please sign in to comment.