Explorer

core.max-local

description
An upper bound of the local variable index used by core.compile-expr-instructions(expr, depth, ctx). Each nesting level uses at most two more locals, function bodies are compiled into separate functions, and non-function parts are inlined at the same depth
type
Fn(
  expr: @core.expression,
  depth: 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}>
  }
) -> Number
expression
fn(expr$0, depth$1, ctx$2) =>
  match $0 {
    #function(f$3) =>
      @core.plus(left: $1, right: 2),
    #part_reference(e$4) =>
      let id$5 = $4.part_definition_event_hash;
      let found$6 = @core.compile-find-part(parts: $2.part_index, id: $5, index: 0);
      match @core.list-get(list: $6, index: 0) {
        #none(_) =>
          @core.plus(left: $1, right: 2),
        #some(item$8161) =>
          let target$7 = $8161;
          match @core.is-function-expression(expr: $7.expression) {
            true =>
              @core.plus(left: $1, right: 2),
            false =>
              match @core.list-contains-string(list: $2.inlining, target: $5, index: 0) {
                true =>
                  @core.plus(left: $1, right: 2),
                false =>
                  let own$8 = @core.plus(left: $1, right: 2);
                  let inner$10 = @core.max-local(
                      expr: $7.expression,
                      depth: $1,
                      ctx: {
                        parts: $2.parts,
                        inlining: @core.list-concat(left: [$5], right: $2.inlining),
                        strings: $2.strings,
                        part_index: $2.part_index
                      }
                    );
                  match @core.less-than(left: $8, right: $10) {
                    true =>
                      $10,
                    false =>
                      $8
                  }
              }
          }
      },
    #quote(quoted$7060) =>
      @core.max-local(expr: @core.quote-value(expression: $7060, parts: $2.parts), depth: $1, ctx: $2),
    #secret(secret$7160) =>
      @core.max-local(
        expr: #record<@core.expression>([
          {key: "id", value: #string<@core.expression>($7160.id)},
          {key: "label", value: #string<@core.expression>($7160.label)}
        ]),
        depth: $1,
        ctx: $2
      ),
    #match(match_e$97010) =>
      let target_max$97011 = @core.max-local(expr: $97010.target, depth: @core.plus(left: $1, right: 2), ctx: $2);
      let arms_max$97012 = @core.max-local-in-arms(arms: $97010.arms, index: 0, depth: $1, ctx: $2);
      match @core.less-than(left: $97011, right: $97012) {
        true =>
          $97012,
        false =>
          $97011
      },
    _ =>
      let children$9 = @core.expression-children(expr: $0);
      let own$8 = @core.plus(left: $1, right: 2);
      let inner$10 = @core.max-local-in-range(
          items: $9,
          lo: 0,
          hi: @core.list-length(value: $9),
          depth: @core.plus(left: $1, right: 2),
          ctx: $2
        );
      match @core.less-than(left: $8, right: $10) {
        true =>
          $10,
        false =>
          $8
      }
  }
visibility
public
core.max-local (project definy, branch main, snapshot CfIAXM725tR74SWd4aoTUz4-JJQfqnllblZbQ2Sv204)
id: 6gLG5P6mrWF_55LMgCo7nJ_GjqgI2xhJFqUV5z-wzMQ
content hash: Z5OC9r13J-rN8auYCgl4PS-m9Buxcwf2jOnpvjgh5Qc