Skip to content

Commit

Permalink
Add comment for LiteralExpander select (#12926)
Browse files Browse the repository at this point in the history
Co-authored-by: Beta Ziliani <[email protected]>
  • Loading branch information
straight-shoota and beta-ziliani authored Jan 13, 2023
1 parent c4e8c21 commit c6e3116
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/compiler/crystal/semantic/literal_expander.cr
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,48 @@ module Crystal
final_exp
end

# Convert a `select` statement into a `case` statement based on `Channel.select`
#
# From:
#
# select
# when foo then body
# when x = bar then x.baz
# end
#
# To:
#
# %index, %value = ::Channel.select({foo_select_action, bar_select_action})
# case %index
# when 0
# body
# when 1
# x = value.as(typeof(foo))
# x.baz
# else
# ::raise("BUG: invalid select index")
# end
#
#
# If there's an `else` branch, use `Channel.non_blocking_select`.
#
# From:
#
# select
# when foo then body
# else qux
# end
#
# To:
#
# %index, %value = ::Channel.non_blocking_select({foo_select_action})
# case %index
# when 0
# body
# else
# qux
# end
#
def expand(node : Select)
index_name = @program.new_temp_var_name
value_name = @program.new_temp_var_name
Expand Down

0 comments on commit c6e3116

Please sign in to comment.