/ebqn

A BQN virtual machine in Erlang

Primary LanguageErlangApache License 2.0Apache-2.0

EBQN

EBQN is an experimental implementation of a BQN virtual machine in Erlang. It can interpret BQN bytecode, and compile source expressions to bytecode via the BQN self-hosted compiler.

It is extremely slow! This seems due to BQN heap operations and Erlang mutability constraints. Using the JIT-enabled OTP 24 release is highly recommended.

There are several mitigations in consideration:

  1. Implement some (or all) of the BQN runtime in Erlang.
  2. Change from bytecode interpretation to AST generation via erl_syntax
  3. Implement as a NIF via rustler

Each of these strategies have pros and cons, and further investigation will happen.

For more information on the rationale behind this project, see the following blog post by Gordon Guthrie:

The BEAM needs an APL-y language

Installation

It is recommended to use EBQN by generating BQN bytecode with DBQN.

  1. Setup BQN
  2. Setup DBQN
  3. Setup dbqn as outlined in DBQN documentation.

Usage

  1. Generate BQN bytecode:
$ ./misc/cerl /path/to/mlochbaum/bqn '{𝕩×10}'
  1. From EBQN root directory:
$ rebar3 shell
  1. Load the bytecode (using the bytecode from step 1):
1> rr(ebqn).
2> {St0,Rt} = ebqn:runtime().
3> {St1,F} = ebqn:run(St0,[[15,1,25,0,1,0,0,21,0,1,17,25],[ebqn_array:get(2,Rt#a.r),10],[[0,1,0,0],[0,0,3,3]]]).
4> ebqn:call(St1,F,1,undefined).

Build

$ rebar3 compile

Test

1> {St0,Rt} = ebqn:runtime().
2> ebqn_test:test(St0,Rt).