Explorer

core.compile-boolean-match

description
The instructions of a match on a boolean with the arms true and false (or a boolean and _), as an if on the unboxed boolean, without keeping the target in a local and comparing it with each pattern. none for other matches. The function indices follow the order of the arms as written, as in core.compile-match-arms
type
Fn(
  target: @core.expression,
  arms: List<@core.match-arm>,
  env: List<Record{variable_id: Number, local: Number}>,
  depth: Number,
  fn_base: Number,
  ctx: Record{
    parts: List<Record{id: String, expression: @core.expression, base: Number}>,
    inlining: List<String>,
    part_index: List<List<Record{id: String, expression: @core.expression, base: Number}>>,
    strings: List<Record{value: String, address: Number}>
  },
  tail: Boolean
) -> Union{#none, #some(List<Number>)}
expression
fn(target$0, arms$1, env$2, depth$3, fn_base$4, ctx$5, tail$6) =>
  match @core.equal(left: @core.list-length(value: $1), right: 2) {
    false =>
      #none,
    true =>
      match @core.list-get(list: $1, index: 0) {
        #none(_) =>
          #none,
        #some(first$7) =>
          match @core.list-get(list: $1, index: 1) {
            #none(_) =>
              #none,
            #some(second$8) =>
              match $7.pattern {
                #boolean(first_value$9) =>
                  let second_ok$10 = match $8.pattern {
                      #boolean(second_value$11) =>
                        @core.not(value: @core.equal(left: $11, right: $9)),
                      #any(_) =>
                        true,
                      _ =>
                        false
                    };
                  match $10 {
                    false =>
                      #none,
                    true =>
                      let first_base$12 = @core.plus(left: $4, right: @core.count-functions(expr: $0));
                      let first_code$13 = @core.compile-boolean-match-arm-body(expr: $7.body, env: $2, depth: @core.plus(left: $3, right: 2), fn_base: $12, ctx: $5, tail: $6);
                      let second_code$14 = @core.compile-boolean-match-arm-body(
                          expr: $8.body,
                          env: $2,
                          depth: @core.plus(left: $3, right: 2),
                          fn_base: @core.plus(left: $12, right: @core.count-functions(expr: $7.body)),
                          ctx: $5,
                          tail: $6
                        );
                      #some(@core.list-concat(
                        left: @core.compile-unbox-bool(code: @core.compile-expr-instructions(expr: $0, env: $2, depth: $3, fn_base: $4, ctx: $5)),
                        right: @core.list-concat(
                          left: [@wasm.if, @wasm.value-type-ref-null, @core.wasm-type-value],
                          right: match $9 {
                            true =>
                              @core.list-concat(
                                left: $13,
                                right: @core.list-concat(left: [@wasm.else], right: @core.list-concat(left: $14, right: [@wasm.end]))
                              ),
                            false =>
                              @core.list-concat(
                                left: $14,
                                right: @core.list-concat(left: [@wasm.else], right: @core.list-concat(left: $13, right: [@wasm.end]))
                              )
                          }
                        )
                      ))
                  },
                _ =>
                  #none
              }
          }
      }
  }
visibility
public
core.compile-boolean-match (project definy, branch auto-release, snapshot oiQgPqhJm-TbM4kexXeRHBaJB_tS7gwBSewII64P-44)
id: qRkdv1sxzu-T66kINNBGmg5-sokiSjlewAGWs9bjWwc
content hash: xf1ik2kUZt5yj7BUMN68sfi1a5D3PskFzh3z6KWFLz0