Skip to content

Conversation

@ianks
Copy link
Contributor

@ianks ianks commented Dec 20, 2023

It's ugly, but the basics work. Meaning, you can now do:

    def test_creating_basic_module_with_binaryen
      mod = BinaryenModuleCreate()
      params = BinaryenTypeCreate([BinaryenTypeInt32(), BinaryenTypeInt32()])
      results = BinaryenTypeInt32()
      x = BinaryenLocalGet(mod, 0, BinaryenTypeInt32())
      y = BinaryenLocalGet(mod, 1, BinaryenTypeInt32())
      add = BinaryenBinary(mod, BinaryenAddInt32(), x, y)
      BinaryenAddFunction(mod, "adder", params, results, nil, 0, add)

      write_result = BinaryenModuleAllocateAndWrite(mod, nil)
      text_result = BinaryenModuleAllocateAndWriteText(mod)

      assert(write_result.to_s.start_with?("\x00asm"))
      assert_equal(<<~WAT, text_result)
        (module
         (type $0 (func (param i32 i32) (result i32)))
         (func $adder (param $0 i32) (param $1 i32) (result i32)
          (i32.add
           (local.get $0)
           (local.get $1)
          )
         )
        )
      WAT
    ensure
      BinaryenModuleDispose(mod)
    end

It's very low-level. You even have to deal with freeing resources manually. But enough is there that I think someone can at least design a more ergonomic API now.

@ianks ianks force-pushed the capi branch 4 times, most recently from a940221 to cab3e19 Compare December 20, 2023 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant