On a bytecode representation #9
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
My original intention with Sprite was to make the human-readable, C-like code that the current examples are written in the ONLY way of writing Sprite. However, the more I think about this, the less it makes sense. Here are some reasons I wanted to do this:
Let's look at some obvious consequences of the runtime having to execute only the "human-readable" representation:
JavaScript, like Sprite, was also intended to be human-readable, and it was intended to be a common language for both website developers and website users to understand what the code is doing. However, JavaScript is in its mid-20s now and has demonstrated some major pitfalls in these design goals:
The biggest reason to use bytecode is that the runtime can be made simpler. The compilation pipeline can be split into two distinct parts: a frontend (parsing/semantics), and a backend (monomorphization/JIT/execution), with the bytecode as an intermediate format. With this split model, parts of the compiler frontend could be modified, as long as it still emits valid bytecode. This could be used to make new authoring languages (like what Kotlin is to the JVM), or to rewrite compilation stages in other languages (like to replace the "canonical" frontend in Rust with a frontend in C, Python, Lua, JavaScript, whatever). The backend could also be modified in a similar way, for example to provide alternate compilation backends, like LLVM, specific ISAs, or an interpreter.
Source code availability must be encouraged and supported by the authors of source code, not the source code itself. Sprite is only a computer program, and is not capable of overthrowing proprietary software on its own. "Human-readability" and software freedom in Sprite scripts cannot be enforced, and should be a non-goal if it means that the runtime needs to sacrifice some of its own readability and flexibility (a la v8, Google's JavaScript runtime).
Ironically, supporting a "human-unreadable" Sprite bytecode enables the runtime itself to become much more accessible to a variety of audiences.
An immediate advantage of bytecode being the representation is that it would make it easier to deal with code generation; I can easily imagine doing stuff like having a node based visual editor that outputs sprite bytecode (that’d be possible with human readable code as well but the process would be simpler to develop tooling for).
Another advantage of bytecode's portability besides simple storage space / bandwidth / etc. is that it'd be easier to implement memory budgets / etc. (depending on implementation ofc); for instance, the host app could simply be like "oh, I see you're giving me a certain amount of Sprite bytecode, I can work with that" with far less analysis involved.