From b6dcb9f67a6d4019026a864ebb90c62ec2d2c85b Mon Sep 17 00:00:00 2001 From: tocariimaa Date: Thu, 6 Mar 2025 18:58:19 -0300 Subject: [PATCH] articles/bytecode.md: new article --- articles/bytecode.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 articles/bytecode.md diff --git a/articles/bytecode.md b/articles/bytecode.md new file mode 100644 index 0000000..47d21f2 --- /dev/null +++ b/articles/bytecode.md @@ -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