Explorer

core.compile-tail-instructions

description
Instructions for an expression in tail position of a function body. Calls become return_call_indirect (definy has no exceptions and needs no stack traces, so every tail call can reuse the frame); let bodies and match arm bodies stay in tail position, and other expressions use core.compile-expr-instructions
type
Fn(
  expr: @core.expression,
  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}>
  }
) -> List<Number>
expression
fn(expr$0, env$1, depth$2, fn_base$3, ctx$4) =>
  match @core.less-than(left: $2, right: 508) {
    true =>
      match $0 {
        #call(e$43) =>
          match @core.equal(left: @core.compile-builtin-name(function: $43.function, parts: $4.part_index), right: "") {
            true =>
              @core.compile-call(e: $43, env: $1, depth: $2, fn_base: $3, ctx: $4, opcode: @wasm.return-call-indirect),
            false =>
              @core.compile-expr-instructions(expr: $0, env: $1, depth: $2, fn_base: $3, ctx: $4)
          },
        #let(e$27) =>
          @core.list-concat(
            left: @core.compile-expr-instructions(expr: $27.value, env: $1, depth: @core.plus(left: $2, right: 1), fn_base: $3, ctx: $4),
            right: @core.list-concat(
              left: @core.list-concat(left: [@wasm.local-set], right: @wasm.unsigned-leb128(n: $2)),
              right: @core.compile-tail-instructions(
                expr: $27.body,
                env: @core.list-concat(left: [{variable_id: $27.variable_id, local: $2}], right: $1),
                depth: @core.plus(left: $2, right: 1),
                fn_base: @core.plus(left: $3, right: @core.count-functions(expr: $27.value)),
                ctx: $4
              )
            )
          ),
        #match(e$41) =>
          match @core.compile-boolean-match(target: $41.target, arms: $41.arms, env: $1, depth: $2, fn_base: $3, ctx: $4, tail: true) {
            #some(code$9600) =>
              $9600,
            #none(_) =>
              @core.list-concat(
                left: @core.compile-expr-instructions(expr: $41.target, env: $1, depth: $2, fn_base: $3, ctx: $4),
                right: @core.list-concat(
                  left: @core.list-concat(left: [@wasm.local-set], right: @wasm.unsigned-leb128(n: $2)),
                  right: @core.compile-match-arms-tail(
                    arms: $41.arms,
                    index: 0,
                    env: $1,
                    depth: $2,
                    fn_base: @core.plus(left: $3, right: @core.count-functions(expr: $41.target)),
                    ctx: $4
                  )
                )
              )
          },
        _ =>
          @core.compile-expr-instructions(expr: $0, env: $1, depth: $2, fn_base: $3, ctx: $4)
      },
    false =>
      @core.compile-expr-instructions(expr: $0, env: $1, depth: $2, fn_base: $3, ctx: $4)
  }
visibility
public
core.compile-tail-instructions (project definy, branch main, snapshot CfIAXM725tR74SWd4aoTUz4-JJQfqnllblZbQ2Sv204)
id: DBIMwt8bpRaJ8_d9CURa9a0pXttdzSZeqe_t00D3nhg
content hash: DQHRsHVgkKB_oEwVHwxb27k1aaqYnLRLc9x-Xrr-su4