witx-codegen icon indicating copy to clipboard operation
witx-codegen copied to clipboard

The way to dingtish which module I import?

Open sonder-joker opened this issue 3 years ago • 3 comments

I'm current implementation an cpp's backend and it work well. However, I wish split different module into different namespace (like rust's mod)

(module $wasi_ephemeral_crypto_symmetric
  (use * from $wasi_ephemeral_crypto_common)

into

namespace WasiEphemeralCryptoSymmetric {
using namespace WitxCodegenHeader; // import header
using namespace handle; //generate from resource, but seem not corrrespond to import module

I found module_witx's resource seem not correspond to the import module. How to achieve it?

sonder-joker avatar Sep 16 '21 08:09 sonder-joker

Hi!

Generator::generate() is called for each module, so you can use this to create each namespace.

See how it's done for the Zig backend, which is probably the best starting point for a C++ backend: https://github.com/jedisct1/witx-codegen/blob/4ee1bb22f8f800ccb1c0ca17978db1be59b19edb/src/zig/mod.rs#L72-L82

jedisct1 avatar Sep 19 '21 11:09 jedisct1

This is how functions then get in namespaces: https://github.com/jedisct1/witx-codegen/blob/4ee1bb22f8f800ccb1c0ca17978db1be59b19edb/example-output/zig.zig#L315

jedisct1 avatar Sep 19 '21 11:09 jedisct1

This is how functions then get in namespaces:

https://github.com/jedisct1/witx-codegen/blob/4ee1bb22f8f800ccb1c0ca17978db1be59b19edb/example-output/zig.zig#L315

Oh I have just read zip example, so only function in module and expose type alias to other module? I through alias type also in module(sorry I'm not familiar with zig).

sonder-joker avatar Sep 20 '21 12:09 sonder-joker