(function(r,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(r=typeof globalThis<"u"?globalThis:r||self,s(r.bf={}))})(this,function(r){"use strict";let s=[],f=[],o,l=!1;const b=e=>l=e,w=256;let t,d=()=>{};const c=(e,n=!1)=>d({operator:e,memory:t,pointer:o,input:s.join(""),output_buffer:f.join(""),exited:n}),p={"+":()=>{t[o]=t[o]||0,t[o]<255?t[o]++:t[o]=0,c("+"),l&&console.log("+",t[o],o,t)},"-":()=>{t[o]=t[o]||0,t[o]--,c("-"),l&&console.log("-",t[o],o,t)},"<":()=>{o>0&&(o--,c("<")),l&&console.log("<",o,t)},">":()=>{o++,c(">"),l&&console.log(">",o,t)},".":()=>{const e=String.fromCharCode(t[o]);f.push(e),c("."),l&&console.log(".",e,t[o],t)},",":()=>{const e=s.shift();typeof e=="string"&&(t[o]=e.charCodeAt(0),c(",")),l&&console.log(",",e,t[o],t)}},y=e=>n=>(t=new Uint8Array(w),o=0,f=[],s=n&&n.split("")||[],e.forEach(u=>u()),c(null,!0),f.join("")),x=e=>()=>{let n=0;for(;t[o]>0;){if(n++>2e4)throw new Error("Loop count exceeded");e.forEach(u=>u())}};let i=[];const g=()=>{const e=[];let n;for(;i.length>0;)if(n=i.shift(),p[n])e.push(p[n]);else if(n==="[")e.push(m());else if(n==="]")throw new Error("Unexpected closing bracket");return y(e)},m=()=>{const e=[];let n;for(;i[0]!=="]";){if(n=i.shift(),n===void 0)throw new Error("Unexpected end of program");p[n]?e.push(p[n]):n==="["&&e.push(m())}return i.shift(),x(e)},C=(e,n)=>new Promise((u,a)=>{i=e.split("");try{u(g()(n))}catch(h){a(h)}}),_=(e,n,u)=>new Promise((a,h)=>{i=e.split(""),d=u||(()=>{});try{a(g()(n))}catch(j){h(j)}});r.execute=C,r.executeCallbackly=_,r.setDebug=b,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});