visitTernaryExpr method

  1. @override
Uint8List visitTernaryExpr(
  1. TernaryExpr expr
)
override

Implementation

@override
Uint8List visitTernaryExpr(TernaryExpr expr) {
  final bytesBuilder = BytesBuilder();
  final condition = compileAST(expr.condition);
  bytesBuilder.add(condition);
  bytesBuilder.addByte(HTOpCode.ifStmt);
  final thenBranch = compileAST(expr.thenBranch);
  final elseBranch = compileAST(expr.elseBranch);
  bytesBuilder.add(_uint16(thenBranch.length + 3));
  bytesBuilder.add(thenBranch);
  bytesBuilder.addByte(HTOpCode.skip); // 执行完 then 之后,直接跳过 else block
  bytesBuilder.add(_int16(elseBranch.length));
  bytesBuilder.add(elseBranch);
  return bytesBuilder.toBytes();
}