mtth / avsc

Avro for JavaScript :zap:
MIT License
1.28k stars 148 forks source link

Can this be used for bytecode? #407

Closed mattfysh closed 2 years ago

mattfysh commented 2 years ago

Hi there, I'm looking at generating bytecode for a toy language and searched for a while to find a binary packing/unpacking library written in JS but there are not that many great options.

So I started using avsc and it seems to be outputting what I need, e.g. I have a type Instruction which is a union type of all possible instruction set types.

Has Avro been used in this way before, and do you see any issues using it this way? My compiler and tooling is all written in javascript but the goal of producing bytecode is to write interpreters in other languages (e.g. Python) that can use Avro to decode the binary into a program structure and execute

mtth commented 2 years ago

Hi @mattfysh. I don't have any concrete examples to point to but this usage seems reasonable. Avro supports unions which are convenient for modeling ASTs (as you're doing for instructions). Logical types can be handy as well. If Avro supports all the languages you target, this sounds like a good fit.

mattfysh commented 2 years ago

Great, thanks @mtth. Let me know if you do happen to come across any other examples of Avro generating bytecode

The only two things I've stumbled on so far are: