Uneasy for custom non-std high-level target

How can I use a rustc backend to generate ActionScript bytecode from high-level Rust? I can't use Rust HIR or LLVM IR because I want to have the types of, say, the variables.

Crosspost: How to translate HIR to ActionScript bytecode? - #4 by hydroper1 - compiler - Rust Internals

Does ActionScript bytecode support pointers? And does it allow casting a pointer to a different type and then reading the underlying memory as this different type? If not, you will either have to use a large array and use integer indexes as "pointers" and forgo high level types entirely, or you have to hack around and accept that some code may not work. Rust doesn't have typed memory, unlike for example C. (although even in C it is common for programmers to assume C doesn't have typed memory either and -fno-strict-aliasing may be used to disable typed memory) See GitHub - EmbarkStudios/rust-gpu: 🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧 for an example that takes the later route.

HIR is before typechecking. HIR is combined with the types infered by typechecking into THIR (typed HIR) which then gets lowered into MIR which is also typed. All backends use MIR as it is significantly simpler than HIR and THIR (and THIR is dropped almost immediately. It is mostly as abstraction to make MIR building easier) I did recommend basing your backend on MIR too.

2 Likes

ActionScript is mostly EcmaScript, but AVM2 added instructions for fast operations over an application-domain static ByteArray (which are undocumented). I think it doesn't support pointers.

But the point is, I want to compile Rust to ActionScript bytecode and put certain restrictions on what features of the Rust language can be used. So it'd be used like a dialect, but still reusing the same Rust compiler, so that I don't have to parse Rust and create a symbol solver (aka. type checker) for it myself. I'd scaffold projects with a #![no_std] attribute.

I'll give a look at that rust-gpu project though, thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.