Stream: general

Topic: Recommended flow for language transpiling?


view this post on Zulip Lander Brandt (Jul 26 2022 at 20:40):

Hey folks, I'm trying to write a transpiler in Rust for a custom C-like programming language that would either translate from the source language's text format to a .wat or WASM bytecode format (.wat would be easier for me to debug I think). Is there a recommended crate/library that provides high-level functions for such a task? I'm looking for something that provides utility functions like say:

    let mut func = scope.define_func("add", vec![ParamType::ConstI32, ParamType::ConstI32], ResultType::ConstI32)
    func.ops.push(Local::Get(0));
    func.ops.push(Local::Get(1));
    func.ops.push(I32::Add);

Which would generate:

    (func (export "add") (param i32 i32) (result i32)
        local.get 0
        local.get 1
        i32.add))

view this post on Zulip Dan Gohman (Jul 26 2022 at 20:43):

https://docs.rs/wasm-encoder/latest/wasm_encoder/ has an API which is very close to that.

view this post on Zulip Lander Brandt (Jul 26 2022 at 20:45):

@Dan Gohman thank you! This appears to be exactly what I need.

view this post on Zulip Peter Huene (Jul 26 2022 at 20:47):

wasm-encoder encodes to the binary format, but you can also use wasmprinter from that same repro to print the text format from the output of wasm-encoder

view this post on Zulip Lander Brandt (Jul 27 2022 at 01:07):

Just to make sure I'm not reinventing the wheel, there isn't something higher-level that let's me translate imperative language constructs and have it do the hard work for me is there? I came across this whistle-lang compiler which actually looks pretty good: https://github.com/whistle-lang/whistle/tree/main/compiler

(I understand I can't get everything for free, but path of least resistance etc. :p )

🕴 One hella programming language. Contribute to whistle-lang/whistle development by creating an account on GitHub.

view this post on Zulip Peter Huene (Jul 27 2022 at 05:52):

I'm personally not familiar with any.


Last updated: Dec 23 2024 at 12:05 UTC