Explorer

core.compile-function-body

description
Wasm function body (with its size) for the function expression at the index in the function table. Parameters are read from the argument array (param 1) and captured variables from the closure environment (param 0)
type
Fn(
  function: @core.expression,
  index: 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(function$0, index$1, ctx$2) =>
  match $0 {
    #function(f$3) =>
      let parameter_ids$4 = @core.function-parameter-ids-by-name(parameters: $3.parameters, rank: 0);
      let captured$5 = @core.unique-numbers(list: @core.free-variables(expr: $0, bound: []), index: 0, result: []);
      let parameter_count$6 = @core.list-length(value: $4);
      let first_captured$7 = @core.plus(left: 2, right: $6);
      let env$8 = @core.list-concat(
          left: @core.compile-slot-env(variables: $4, index: 0, first_local: 2),
          right: @core.compile-slot-env(variables: $5, index: 0, first_local: $7)
        );
      let body$9 = @core.list-concat(
          left: @core.list-concat(
            left: [1],
            right: @core.list-concat(
              left: @wasm.unsigned-leb128(
                n: @core.plus(
                  left: @core.max-local(expr: $3.body, depth: @core.plus(left: $7, right: @core.list-length(value: $5)), ctx: $2),
                  right: 1
                )
              ),
              right: [@wasm.value-type-ref-null, @core.wasm-type-value]
            )
          ),
          right: @core.list-concat(
            left: @core.compile-load-slots(count: $6, index: 0, pointer_local: 1, first_local: 2),
            right: @core.list-concat(
              left: @core.compile-load-slots(count: @core.list-length(value: $5), index: 0, pointer_local: 0, first_local: $7),
              right: @core.list-concat(
                left: @core.compile-tail-instructions(
                  expr: $3.body,
                  env: $8,
                  depth: @core.plus(left: $7, right: @core.list-length(value: $5)),
                  fn_base: @core.plus(left: $1, right: 1),
                  ctx: $2
                ),
                right: [11]
              )
            )
          )
        );
      @core.list-concat(left: @wasm.unsigned-leb128(n: @core.list-length(value: $9)), right: $9),
    _$10 =>
      [3, 0, 0, 11]
  }
visibility
public
core.compile-function-body (project definy, branch compiled-tests, snapshot i6TqClmqVS9FK8rKOvJ43l6Tevx8pvYJ5-zaQqNwemc)
id: TMtYkM1JmCCXEXKWiLqouOzawAQZkkNchVwdcSwU7xY
content hash: RhxIiVkeuP9BQCs5bG7sEAbUKhlezUwWNcAt78PQlS8