Explorer

core.compile-to-wasm

description
Compile an expression into a Wasm module (Wasm GC) whose evaluate function returns the result value (a reference to a struct of the GC heap, read by src/stage1_compiler.ts through the exported runtime functions). parts are the parts the expression references (transitively)
type
Fn(expr: @core.expression, parts: List<Record{id: String, expression: @core.expression}>) -> List<Number>
expression
fn(expr$0, parts$1) =>
  let strings$20 = @core.compile-collect-part-strings(
      parts: $1,
      index: 0,
      strings: @core.compile-collect-strings(expr: $0, strings: ["true", "false", "none", "some"])
    );
  let string_table$23 = @core.compile-string-table(strings: $20, index: 0, address: 2);
  let string_data$21 = @core.compile-string-data(strings: $20, index: 0);
  let runtime_count$22 = @core.list-length(value: @core.wasm-runtime-function-types);
  let main_functions$2 = @core.collect-functions(expr: $0);
  let functions$3 = @core.list-concat(left: $2, right: @core.compile-collect-part-functions(parts: $1, index: 0));
  let part_entries$4 = @core.compile-assign-part-bases(parts: $1, index: 0, base: @core.list-length(value: $2));
  let part_index$26 = @core.list-hash-index(list: $4, field: "id");
  let function_count$5 = @core.list-length(value: $3);
  let evaluate_body$6 = @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: $0, depth: 0, ctx: {parts: $4, inlining: [], strings: $23, part_index: $26}),
              right: 1
            )
          ),
          right: [@wasm.value-type-ref-null, @core.wasm-type-value]
        )
      ),
      right: @core.list-concat(
        left: @core.compile-expr-instructions(
          expr: $0,
          env: [],
          depth: 0,
          fn_base: 0,
          ctx: {parts: $4, inlining: [], strings: $23, part_index: $26}
        ),
        right: [@wasm.end]
      )
    );
  let init_body$24 = @core.list-concat(
      left: [0],
      right: @core.list-concat(left: @core.compile-string-init(strings: $20, index: 0, offset: 0), right: [@wasm.end])
    );
  let function_section$7 = @core.list-concat(
      left: @wasm.unsigned-leb128(n: @core.plus(left: $22, right: $5)),
      right: @core.list-concat(
        left: @core.wasm-runtime-function-types,
        right: @core.repeat-number(value: @core.wasm-type-closure-function, count: $5)
      )
    );
  let table_section$8 = @core.list-concat(
      left: [1, 112, 0],
      right: @wasm.unsigned-leb128(
        n: match @core.less-than(left: $5, right: 1) {
          true =>
            1,
          false =>
            $5
        }
      )
    );
  let element_section$9 = match @core.less-than(left: 0, right: $5) {
      true =>
        @wasm.section(
          id: @wasm.section-element,
          payload: @core.list-concat(
            left: [1, 0, @wasm.i32-const, 0, @wasm.end],
            right: @core.list-concat(left: @wasm.unsigned-leb128(n: $5), right: @wasm.uleb-range(start: $22, count: $5))
          )
        ),
      false =>
        []
    };
  let global_section$25 = @core.list-concat(
      left: @wasm.unsigned-leb128(n: @core.plus(left: 2, right: @core.list-length(value: $20))),
      right: @core.list-concat(
        left: [
          @wasm.value-type-ref-null,
          @core.wasm-type-boolean,
          0,
          @wasm.i32-const,
          1,
          @wasm.i32-const,
          1,
          @wasm.gc-prefix,
          @wasm.struct-new,
          @core.wasm-type-boolean,
          @wasm.end,
          @wasm.value-type-ref-null,
          @core.wasm-type-boolean,
          0,
          @wasm.i32-const,
          1,
          @wasm.i32-const,
          0,
          @wasm.gc-prefix,
          @wasm.struct-new,
          @core.wasm-type-boolean,
          @wasm.end
        ],
        right: @core.compile-string-globals(strings: $20, index: 0)
      )
    );
  let code_payload$10 = @core.list-concat(
      left: @wasm.unsigned-leb128(n: @core.plus(left: $22, right: $5)),
      right: @core.list-concat(
        left: @wasm.code-entry(function: $6),
        right: @core.list-concat(
          left: @core.wasm-runtime-functions,
          right: @core.list-concat(
            left: @wasm.code-entry(function: $24),
            right: @core.compile-function-bodies(functions: $3, index: 0, ctx: {parts: $4, inlining: [], strings: $23, part_index: $26})
          )
        )
      )
    );
  @core.list-concat(
    left: @wasm.module-header,
    right: @core.list-concat(
      left: @wasm.section(id: @wasm.section-type, payload: @core.wasm-runtime-types),
      right: @core.list-concat(
        left: @wasm.section(id: @wasm.section-function, payload: $7),
        right: @core.list-concat(
          left: @wasm.section(id: @wasm.section-table, payload: $8),
          right: @core.list-concat(
            left: @wasm.section(id: @wasm.section-memory, payload: [1, 0, 1]),
            right: @core.list-concat(
              left: @wasm.section(id: @wasm.section-global, payload: $25),
              right: @core.list-concat(
                left: @wasm.section(id: @wasm.section-export, payload: @core.wasm-runtime-exports),
                right: @core.list-concat(
                  left: @wasm.section(id: @wasm.section-start, payload: @wasm.unsigned-leb128(n: @core.minus(left: $22, right: 1))),
                  right: @core.list-concat(
                    left: $9,
                    right: @core.list-concat(
                      left: @wasm.section(id: @wasm.section-data-count, payload: [1]),
                      right: @core.list-concat(
                        left: @wasm.section(id: @wasm.section-code, payload: $10),
                        right: @wasm.section(
                          id: @wasm.section-data,
                          payload: @core.list-concat(
                            left: [1, 1],
                            right: @core.list-concat(left: @wasm.unsigned-leb128(n: @core.list-length(value: $21)), right: $21)
                          )
                        )
                      )
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  )
visibility
public
core.compile-to-wasm (project definy, branch compiled-tests, snapshot i6TqClmqVS9FK8rKOvJ43l6Tevx8pvYJ5-zaQqNwemc)
id: qa22gxxdhfOt256rc_LSu3zqtiBlyNiZAUzdjfjj2ks
content hash: CShENiKxcKcgDm3lJgBN4KViDjDRT0MBQ65qOEpvKZw