1// Package bf is a Brainfuck machine for gno.land, and the measuring stick the2// rest of the guest-VM work is calibrated against.3//4// It ships two things that look alike and are not:5//6// - [Execute], the naive interpreter: a switch over the source bytes, a7// brace matcher that rescans the program on every loop edge. It is kept
Functions
not supported for pure packages by the node (vm/qfuncs)
Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.
8// verbatim as rung 0 of the optimization ladder, because a baseline you
9// have edited is not a baseline.
10// - [Compile] plus [Machine], the real one: the program is compiled to an
11// op array with resolved jumps, runs of identical operators are fused,
12// the common loop idioms become single ops, and execution is metered by
13// a caller-supplied fuel budget against a
14// [vmkit](/p/moul/x/vm/vmkit/v0) Host, so a program can pause when it
15// runs out and resume in a later transaction.
16//
17// The ladder between them is measured, not asserted: see the README for the
18// table, and ladder_test.gno for the harness that produces it.
19//
20// Live demo: [r/moul/x/vm/bfdemo](/r/moul/x/vm/bfdemo/v0).
21package bf
22
23import"strings"
24
25// NaiveTapeSize is the tape length used by [Execute]. It is 30,000 because
26// that is what the original had, and rung 0 is not allowed to drift.
27const NaiveTapeSize = 30000
28
29// Execute runs code on a fresh tape and returns everything it wrote, using
30// the original 2023 implementation: no compilation step, one switch per
31// source byte, and a brace matcher that rescans the source every time a loop
32// opens or closes.
33//
34// It is rung 0 of the ladder and exists to be measured. Two of its properties
35// are bugs that are deliberately preserved, and are the reason nothing should
36// call it on untrusted input:
37//
38// - `,` panics with "unsupported": there is no input.
39// - unbalanced brackets run the scan off the end of the source and panic
40// with an index out of range.
41//
42// Use [Compile] and [Machine] for anything real: they reject a malformed
43// program up front, read input from the host, and cannot run unbounded.