From 2afb23928e1984d475cc460e1672e8f6fa0e4dbe Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 11 Aug 2021 17:21:31 -0400 Subject: Allow clicking on header to get fragment link --- docs/implementation/vm.html | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'docs/implementation/vm.html') diff --git a/docs/implementation/vm.html b/docs/implementation/vm.html index 1ecac46c..b7dd287f 100644 --- a/docs/implementation/vm.html +++ b/docs/implementation/vm.html @@ -4,14 +4,14 @@ The BQN virtual machine and runtime -

The BQN virtual machine and runtime

+

The BQN virtual machine and runtime

BQN's self-hosted compiler and runtime mean that only a small amount of native code is needed to run BQN on any given platform. The Javascript environment requires about 500 lines of Javascript code including system functions and performance improvements; probably around 250 would be required just to run the core language. This makes it fairly easy to port BQN to new platforms, allowing BQN to be embedded within other programming languages and interact with arrays or functions in those languages.

The way data is represented is part of the VM implementation: it can use native arrays or a custom data structure, depending on what the language supports. An initial implementation will be very slow, but can be improved by replacing functions from the BQN-based runtime with native code. As the VM system can be hard to work with if you're not familiar with it, I advise you to contact me to discuss implementing a VM if you are interested.

-

Bytecode

+

Bytecode

The BQN implementation here and dzaima/BQN share a stack-based object code format used to represent compiled code. This format is a list of numbers of unspecified precision (small precision will limit the length of list literals and number of locals per block, blocks, and constants). Previously it was encoded as bytes with the LEB128 format; while it no longer has anything to do with bytes it's called a "bytecode" because this is shorter than "object code".

The self-hosted compiler uses a simpler, and less capable, format for block and variable data than dzaima/BQN. Only this format is described here; dc.bqn adapts it to be compatible with dzaima/BQN.

dzaima/BQN can interpret bytecode or convert it to JVM bytecode, while the Javascript VM previously interpreted bytecode but now always compiles it. Since interpretation is a simpler strategy, it may be helpful to use the old Javascript bytecode interpreter as a reference (for bytecode execution only) when implementing a BQN virtual machine.

-

Components

+

Components

The complete bytecode for a program consists of the following:

-

Blocks

+

Blocks

Each entry in blocks is a list of the following properties: