Skip to content

Simplify bindings implementation #56

@syrusakbary

Description

@syrusakbary

After taking a quick look on the project, I realized there was a bit of shared logic between the binding generators that could be simplified.
Eg: https://github.com/bytecodealliance/witx-bindgen/blob/main/crates/gen-wasmtime/src/lib.rs / https://github.com/bytecodealliance/witx-bindgen/blob/main/crates/gen-wasmtime-py/src/lib.rs

As more bindings get implemented this might become more challenging to maintain. I was wondering if there can be an implementation based on the visitor pattern.

Visitor pattern

GraphQL designed a very simple pattern (visitor pattern) to walk through the AST in a simple an succinct way.
Some overview: https://www.graphql-code-generator.com/docs/custom-codegen/using-visitor
Reference implementation in Python: https://github.com/graphql-python/graphql-core/blob/main/src/graphql/language/visitor.py

Example of schema printer based on the Visitor pattern: https://github.com/graphql-python/graphql-core/blob/main/src/graphql/utilities/print_schema.py

Candid's approach

Candid (Dfinity's version of Interface Types), also follows a similar pattern where it's bindings are simple and concise to define:
https://github.com/dfinity/candid/blob/master/rust/candid/src/bindings/typescript.rs

I was wondering if it could make sense to refactor some of the codebase to allow easy maintainability of the generators while repeating as minimum as possible in the bindings generator code.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions