articles/bytecode.md: new article

This commit is contained in:
tocariimaa 2025-03-06 18:58:19 -03:00
parent ca88f673be
commit b6dcb9f67a

28
articles/bytecode.md Normal file
View file

@ -0,0 +1,28 @@
# Bytecode
Bytecode, also known as *p-code* (for *portable code*) is a machine language-like representation
of a program. Unlike actual machine code, it has a higher-abstraction level, since commonly
bytecode is bespoke to the [language](programming_language.md) that it's meant to be used with, supporting high-level
operations such as closures, memory management, dynamic typing, etc..
Usually bytecode is meant to be run in a [virtual machine](virtual_machine.md); this is common for scripting
languages in order to achieve an usable performance, bytecode being a compact representation
is more cache friendly than an [AST](abstract_syntax_tree.md) so it allows for faster execution.
In other cases, bytecode is used as an intermediate representation for compiled languages,
before lowering down to more machine-specific code.
## Examples
### PL/0 p-code
- `lit` (load constant)
- `opr` (operation, this opcode packs multiple arithmetic ops.)
- `lod` (load variable)
- `sto` (store variable)
- `cal` (call procedure)
- `int` (increment register)
- `jmp` (unconditional jump)
- `jpc` (conditional jump)
TODO more info
### Lua bytecode
TODO