All Projects → ashermancinelli → cxbqn

ashermancinelli / cxbqn

Licence: GPL-3.0 license
BQN virtual machine

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to cxbqn

valkyrie
🔮 A UNIX-like toy kernel built from scratch (for AArch64) with preemptive multi-threading, VM, CoW fork(), buddy, slob, VFS, FAT32.
Stars: ✭ 57 (+185%)
Mutual labels:  cpp20
opzioni
The wanna-be-simplest command line arguments library for C++
Stars: ✭ 29 (+45%)
Mutual labels:  cpp20
Project-Template
A template for modern C++ projects with useful features for developing cross-platform products.
Stars: ✭ 44 (+120%)
Mutual labels:  cpp20
USmallFlat
Ubpa small flat containers based on C++20
Stars: ✭ 20 (+0%)
Mutual labels:  cpp20
BackportCpp
Library of backported modern C++ types to work with C++11
Stars: ✭ 53 (+165%)
Mutual labels:  cpp20
Script
Script is an object-oriented interpreted programming language. Being migrated to CppUtils
Stars: ✭ 18 (-10%)
Mutual labels:  cpp20
zab
C++20 liburing backed coroutine executor and event loop framework.
Stars: ✭ 54 (+170%)
Mutual labels:  cpp20
so stupid search
It's my honor to drive you fucking fire faster, to have more time with your Family and Sunshine.This tool is for those who often want to search for a string Deeply into a directory in Recursive mode, but not with the great tools: grep, ack, ripgrep .........every thing should be Small, Thin, Fast, Lazy....without Think and Remember too much ...一…
Stars: ✭ 135 (+575%)
Mutual labels:  cpp20
gal
Geometric Algebra Library
Stars: ✭ 78 (+290%)
Mutual labels:  cpp20
RavEngine
A fast, easy to use C++20 3D game library for modern computers
Stars: ✭ 122 (+510%)
Mutual labels:  cpp20
MeetixOS
An hobby OS written in modern C++20 which aims to be Unix-like. Currently based on EvangelionNG, a GhostOS derived kernel
Stars: ✭ 179 (+795%)
Mutual labels:  cpp20
RTX-Mesh-Shaders
Different mesh shading techniques using the NVIDIA RTX (Turing) technology.
Stars: ✭ 84 (+320%)
Mutual labels:  cpp20
json5
Header only JSON/JSON5 parser and serializer for C++
Stars: ✭ 22 (+10%)
Mutual labels:  cpp20
among-us-replay-mod
Replay mod for Among Us
Stars: ✭ 48 (+140%)
Mutual labels:  cpp20
doctest
The fastest feature-rich C++11/14/17/20 single-header testing framework
Stars: ✭ 4,434 (+22070%)
Mutual labels:  cpp20
tau
A Micro (1k lines of code) Unit Test Framework for C/C++
Stars: ✭ 121 (+505%)
Mutual labels:  cpp20
photon mapping
minimal but extensible header only implementation of photon mapping in C++
Stars: ✭ 65 (+225%)
Mutual labels:  cpp20
engine
A personal game engine project, with development focus towards 2D/2.5D games.
Stars: ✭ 32 (+60%)
Mutual labels:  cpp20
sycl
SYCL for Vitis: Experimental fusion of triSYCL with Intel SYCL oneAPI DPC++ up-streaming effort into Clang/LLVM
Stars: ✭ 80 (+300%)
Mutual labels:  cpp20
bbai-lib
C++ library for getting the most out of polymorphic allocators
Stars: ✭ 41 (+105%)
Mutual labels:  cpp20

CXBQN

VM for BQN.

See CONTRIBUTING.md for information on contributing.

Building

Requires a compiler capable of C++20. GCC 9.3.1 is the oldest compiler I have tested it with.

mkdir build
cd build
# Use CXX to choose your compiler
CXX=g++-11 cmake ..
make -j12
./BQN -v
CXBQN 0.11.0 compiled on Dec 25 2021

Or if you want to use nix, CXBQN has a flake:

$ nix shell github:ashermancinelli/cxbqn
$ BQN -v
CXBQN 0.11.0 compiled on Jan  1 1980

Using

$ ./BQN -h
Usage: BQN [options] args

Positional arguments:
args                   	all remaining arguments are passed into the BQN program as •args [default: {}]

Optional arguments:
-h --help              	shows help message and exits [default: false]
-e --execute           	execute a string as BQN code
-v --version           	prints version information and exits [default: false]
-p --execute-and-print 	execute a string as BQN code, pretty print the result
-x --dump-cu           	dump compilation units after compiling [default: false]
-r --repl              	enter REPL [default: false]
-f --file              	execute a string as BQN code
$ ./BQN -e '•Show 5+5'
10
$ ./BQN -p ↕10
⟨ 0 1 2 3 4 5 6 7 8 9 ⟩
$ ./BQN
   foo←5
5
$ echo '•Show 3‿3⥊↕9' > foo.bqn && ./BQN -f foo.bqn
┌─
╵ 0 1 2
  3 4 5
  6 7 8
        ┘

See the values of •listSys to see what system functions are available in your build of CXBQN.

The REPL also has Readline support if you enable that option at configure time. When you run cmake, pass the argument -DCXBQN_READLINE=ON like so:

mkdir build && cd build
cmake .. -DCXBQN_READLINE=ON

If you have a readline library and development headers installed, this will use them and provide a much nicer REPL environment with variable name completion like so:

$ ./BQN -r
   foo←5
5
   foobar←10
10
   # Tab once for attempted completion
   fo<TAB>
   foo

   # Tab twice for all options if there is no single completion available
   foo<TAB><TAB>
foo     foobar
   foo

Configuring Options

CMake Option Notes
CXBQN_READLINE Enable Readline support in the BQN repl (recommended)
CXBQN_MEM_STRATEGY Possible values include "shared_ptr", "leak", and "gc". "gc" has not been implemented yet. For best performance, select "leak"
CXBQN_BUILD_TESTS Build test suite. Builds take much longer.
CXBQN_LOG Enable logging. You will have to set the log level above level::off to get output. See log file cxbqn-debug.log after running BQN or a test runner.
CXBQN_LOGLEVEL Wrapper around spdlog's log levels. level::debug will produce an extremely large amount of data (~10-15gib for executing "2+2").
CXBQN_DEBUG_VM Output VM debugging information, including the opcode being executed, the program counter, and any opcode arguments.
CXBQN_DEEPCHECKS Enable deeper checks which may produce more helpful errors but will hurt performance.
CXBQN_CUDA Enable CUDA execution via •_CUDAFor
CXBQN_FFI Enable loading dynamic libraries and calling user functions from them.
CXBQN_NATIVE_R0 Enable native C++ implementation of some runtime functions from r0.
CXBQN_NATIVE_R1 Enable native C++ implementation of some runtime functions from r1.
CXBQN_PLOT Enable matplotlib bindings and the namespace •cxbqn.plot. See doc/plot.md for more information.

Specification Feature Support

Spec Item Compliance Notes
Bytecode Full
Runtime BQN-native and r0 Almost all of r0 has a native implementation. We plan to replace elements of r1 with native functions as well
System Functions Partial See •listsys for the supported system values. Good candidate for first contribution.
Namespaces Partial Using fields of a namespace and destructuring without aliasing work, however mutable namespace fields are not supported. System-provided namespace •file has support for •file.List and •file.Lines.

Nonstandard Extensions

GPU Execution

To build with CUDA, enable the CMake option CXBQN_CUDA at configure time. Support for CUDA execution is limited, but it exists! The primary function for CUDA execution is •_CUDAFor, which is a 1-modifier that performs the primitive 𝕗 on array 𝕩 and optionally 𝕨. If you give this functionality a try, feel free to open an issue for any bugs you encounter (there will be many). Here's an example:

$ cmake .. -DCXBQN_CUDA=ON
$ make -j 12
$ ./BQN -r
   (↕10) × •_CUDAFor ⌽↕10
⟨ 0 8 14 18 20 20 18 14 8 0 ⟩
   10 + •_CUDAFor ↕15
⟨ 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ⟩

See the WIP design document for parallel execution here.

Plotting

CXBQN supports bindings to matplotlib via the matplotlib-cpp library. To enable plotting, enable the CMake option CXBQN_PLOT. You must have Python, matplotlib, and numpy installed.

See doc/plot.md for more information.

BQN -e '•cxbqn.plot.Plot ↕10⋄•cxbqn.plot.Show@'

Simple Plotting Example

FFI

See the documentation for FFI here.

Libraries and Packaging

There has been discussion on this topic on the Matrix server, but no consensus has been reached. CXBQN supports importing from locations defined in the environment variable BQNPATH, a :-delimited path just like $PATH.

The order in which •Import searches for files is:

  1. Current working directory
  2. The BQNPATH environment variable (: delimited)
  3. <prefix>/share/bqn where <prefix> is the installation prefix of CXBQN
  4. /usr/share/bqn

Custom Namespace •cxbqn

Everything under the namespace •cxbqn is specific to the CXBQN implementation of BQN. As of v0.10.4, only the value •cxbqn.config is available under this namespace:

$ ./BQN -p '•cxbqn.config'
⟨ ⟨ "CXBQN_READLINE" 1 ⟩ ⟨ "CXBQN_CUDA" 0 ⟩ ⟨ "CXBQN_FFI" 0 ⟩ ⟨ "CXBQN_PLOT" 0 ⟩ ⟩
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].