Explorer

core.compile-pattern

description
Instructions that push 1 if the value in local matches the pattern (0 otherwise), the env with the bound variables and the next free local variable
type
Fn(
  pattern: @core.pattern,
  local: Number,
  next: Number,
  env: List<Record{variable_id: Number, local: 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}>
  }
) -> Record{code: List<Number>, env: List<Record{variable_id: Number, local: Number}>, next: Number}
expression
fn(pattern$0, local$1, next$2, env$3, ctx$4) =>
  match $0 {
    #any(_) =>
      {code: [@wasm.i32-const, 1], env: $3, next: $2},
    #bind(bind$10) =>
      {
        code: [@wasm.i32-const, 1],
        env: @core.list-concat(left: [{variable_id: $10.variable_id, local: $1}], right: $3),
        next: $2
      },
    #boolean(literal$11) =>
      {
        code: @core.list-concat(
          left: @core.list-concat(left: [@wasm.local-get], right: @wasm.unsigned-leb128(n: $1)),
          right: @core.list-concat(
            left: [@wasm.call, 17, @wasm.i32-const],
            right: @core.list-concat(
              left: match $11 {
                true =>
                  [1],
                false =>
                  [0]
              },
              right: [@wasm.i32-eq]
            )
          )
        ),
        env: $3,
        next: $2
      },
    #number(literal$12) =>
      {
        code: @core.list-concat(
          left: @core.list-concat(left: [@wasm.local-get], right: @wasm.unsigned-leb128(n: $1)),
          right: @core.list-concat(
            left: [@wasm.call, 15, @wasm.i64-const],
            right: @core.list-concat(left: @wasm.signed-leb128(n: $12), right: [@wasm.i64-eq])
          )
        ),
        env: $3,
        next: $2
      },
    #string(literal$13) =>
      {
        code: @core.list-concat(
          left: @core.list-concat(left: [@wasm.local-get], right: @wasm.unsigned-leb128(n: $1)),
          right: @core.list-concat(
            left: @core.compile-string-literal(value: $13, local: $2, strings: $4.strings),
            right: [@wasm.call, 4]
          )
        ),
        env: $3,
        next: $2
      },
    #variant(variant$14) =>
      let inner$15 = @core.compile-pattern(pattern: $14.payload, local: $2, next: @core.plus(left: $2, right: 1), env: $3, ctx: $4);
      {
        code: @core.list-concat(
          left: @core.list-concat(left: [@wasm.local-get], right: @wasm.unsigned-leb128(n: $1)),
          right: @core.list-concat(
            left: [@wasm.call, 27],
            right: @core.list-concat(
              left: @core.compile-string-literal(value: $14.tag, local: $2, strings: $4.strings),
              right: @core.list-concat(
                left: [@wasm.call, 4, @wasm.if, 127],
                right: @core.list-concat(
                  left: @core.list-concat(left: [@wasm.local-get], right: @wasm.unsigned-leb128(n: $1)),
                  right: @core.list-concat(
                    left: [@wasm.call, 28],
                    right: @core.list-concat(
                      left: @core.list-concat(left: [@wasm.local-set], right: @wasm.unsigned-leb128(n: $2)),
                      right: @core.list-concat(left: $15.code, right: [@wasm.else, @wasm.i32-const, 0, @wasm.end])
                    )
                  )
                )
              )
            )
          )
        ),
        env: $15.env,
        next: $15.next
      }
  }
visibility
public
core.compile-pattern (project definy, branch auto-release, snapshot oiQgPqhJm-TbM4kexXeRHBaJB_tS7gwBSewII64P-44)
id: -0rHwXUFIokuFcClt9OrpsA1-RUx7RaUbfK9rAw97Ak
content hash: mm-3QRgWVAh9H1Mc6aQ_YpgMHsZQzfeblZx-PUQRm30