mirror of
https://github.com/Noratrieb/brainfuck.git
synced 2026-01-14 21:35:02 +01:00
2 lines
No EOL
7 KiB
JavaScript
2 lines
No EOL
7 KiB
JavaScript
(this["webpackJsonpibfi-ts"]=this["webpackJsonpibfi-ts"]||[]).push([[0],{12:function(t,e,n){},13:function(t,e,n){},15:function(t,e,n){"use strict";n.r(e);var r=n(1),i=n.n(r),c=n(5),a=n.n(c),s=(n(12),n(2)),o=(n(13),n(4)),u=n(0),l=function(t){var e=t.code,n=t.setInput,i=Object(r.useState)(40),c=Object(s.a)(i,2),a=c[0],l=c[1],d=Object(r.useState)({}),h=Object(s.a)(d,2),j=h[0],b=h[1];return Object(u.jsx)("div",{children:Object(u.jsxs)("div",{className:"bf-input",children:[Object(u.jsxs)("div",{children:[Object(u.jsxs)("span",{children:[Object(u.jsx)("label",{htmlFor:"bf-input-fontsize-range",children:"Font Size"}),Object(u.jsx)("input",{type:"range",id:"bf-input-fontsize-range",onChange:function(t){return l(+t.target.value)}})]}),Object(u.jsx)("input",{type:"checkbox",checked:j.minify,id:"input-options-minify",onChange:function(t){b((function(e){return Object(o.a)(Object(o.a)({},e),{},{minify:t.target.checked})})),n(e,j)}}),Object(u.jsx)("label",{htmlFor:"input-options-minify",children:"Minify Code"})]}),Object(u.jsx)("textarea",{value:e,onChange:function(t){return n(t.target.value,j)},style:{fontSize:a},className:"code-input",placeholder:"Input your code here..."}),Object(u.jsx)("div",{children:Object(u.jsx)("button",{onClick:function(){n("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.",j)},children:"Set Hello World"})})]})})},d=function(t){var e=t.text;return Object(u.jsx)("div",{className:"bf-output",children:Object(u.jsx)("textarea",{readOnly:!0,className:"output-area",value:e})})},h=n(6),j=n(7),b=function(){function t(e,n,r,i){Object(h.a)(this,t),this._array=void 0,this._pointer=void 0,this._code=void 0,this._programCounter=void 0,this._inHandler=void 0,this._outHandler=void 0,this._errorHandler=void 0;var c=new ArrayBuffer(32e3);this._array=new Uint8Array(c),this._pointer=0,e[1].minify?this._code=f(e[0]):this._code=e[0],this._programCounter=0,this._inHandler=r,this._outHandler=n,this._errorHandler=i}return Object(j.a)(t,[{key:"next",value:function(){switch(this._code[this._programCounter++]){case"+":this._array[this._pointer]++;break;case"-":this._array[this._pointer]--;break;case">":this._pointer++;break;case"<":if(0===this._pointer){this._errorHandler("Cannot wrap left");break}this._pointer--;break;case".":this._outHandler(this.value);break;case",":try{this._array[this._pointer]=this._inHandler()}catch(n){this._programCounter--,this._errorHandler("Could not read input, trying again next time.")}break;case"[":if(0===this.value)for(var t=0;"]"!==this.lastInstruction||t>-1;)this._programCounter++,"["===this.lastInstruction?t++:"]"===this.lastInstruction&&t--;break;case"]":if(0!==this.value)for(var e=0;"["!==this.lastInstruction||e>-1;)this._programCounter--,"["===this.lastInstruction?e--:"]"===this.lastInstruction&&e++;break;case void 0:this._pointer=this._code.length,console.warn("reached end")}console.log("char: ".concat(this.code[this.programCounter-1]," pointer: ").concat(this.pointer," value: ").concat(this.array[this.pointer]))}},{key:"prev",value:function(){}},{key:"reachedEnd",get:function(){return this._programCounter===this._code.length}},{key:"lastInstruction",get:function(){return this._code[this._programCounter-1]}},{key:"value",get:function(){return this._array[this._pointer]}},{key:"array",get:function(){return this._array}},{key:"pointer",get:function(){return this._pointer}},{key:"code",get:function(){return this._code}},{key:"programCounter",get:function(){return this._programCounter}}]),t}(),p=["+","-","<",">",".",",","[","]"],f=function(t){return t.split("").filter((function(t){return p.includes(t)})).join("")},O=function(t){var e=t.code,n=t.index,r=e.substr(0,n),i=e.substr(n+1,e.length-n+1);return Object(u.jsxs)("div",{className:"code-display-wrapper",children:[Object(u.jsx)("span",{children:r}),Object(u.jsx)("span",{style:{backgroundColor:"red"},children:e[n]||" "}),Object(u.jsx)("span",{children:i})]})},x=function(t){var e,n=t.interpreter,r=n.pointer;e=r<10?0:r-10;var i=Array(20).fill(0).map((function(t,n){return n+e}));return Object(u.jsx)("div",{children:Object(u.jsxs)("table",{className:"memory-display-table",children:[Object(u.jsx)("thead",{children:Object(u.jsx)("tr",{children:i.map((function(t){return Object(u.jsx)("th",{children:t},t)}))})}),Object(u.jsxs)("tbody",{children:[Object(u.jsx)("tr",{children:i.map((function(t){return Object(u.jsx)("td",{className:"cell",children:n.array[t]},t)}))}),Object(u.jsx)("tr",{children:i.map((function(t){return Object(u.jsx)("td",{className:"pointer",children:n.pointer===t&&"^"},t)}))})]})]})})},v=function(t){var e=t.setRunning,n=t.running,i=t.outHandler,c=t.input,a=Object(r.useState)(0),o=Object(s.a)(a,2),l=o[0],d=o[1],h=Object(r.useState)(null),j=Object(s.a)(h,2),p=j[0],f=j[1],v=Object(r.useState)(null),g=Object(s.a)(v,2),m=g[0],_=g[1],y=Object(r.useState)(0),k=Object(s.a)(y,2)[1],C=Object(r.useRef)(null),S=function(){if(!C.current)throw new Error("Could not read input");var t=C.current.value;if(t.length<1)throw new Error("No input found");var e=t.charCodeAt(0);return C.current.value=t.substr(1),e},I=function(t){return _(t)},N=Object(r.useCallback)((function(){d(0),f(new b(c,i,S,I)),e(!1),e(!0)}),[c,i,e]),w=Object(r.useCallback)((function(){_(null),null===p||void 0===p||p.next(),(null===p||void 0===p?void 0:p.reachedEnd)&&d(0),k((function(t){return t+1}))}),[p]);return Object(r.useEffect)((function(){if(n){if(0===l)return;var t=setInterval((function(){w()}),1e3/l);return function(){return clearInterval(t)}}}),[n,w,l]),Object(u.jsxs)("div",{className:"bf-run",children:[n&&p&&Object(u.jsxs)(u.Fragment,{children:[Object(u.jsx)(O,{code:p.code,index:p.programCounter}),Object(u.jsx)(x,{interpreter:p})]}),Object(u.jsxs)("div",{children:[Object(u.jsx)("button",{onClick:function(){return e(!1)},children:"Back"}),Object(u.jsx)("button",{onClick:N,children:"Start"}),Object(u.jsx)("button",{onClick:w,children:"Next"})]}),n&&Object(u.jsx)(u.Fragment,{children:Object(u.jsxs)("div",{children:[Object(u.jsx)("label",{htmlFor:"run-info-speed-range",children:"Speed"}),Object(u.jsx)("input",{type:"range",id:"run-info-speed-range",value:l,onChange:function(t){return d(+t.target.value)}}),Object(u.jsxs)("span",{children:[" ",l]})]})}),m&&Object(u.jsx)("div",{className:"error",children:m}),n&&Object(u.jsxs)("div",{children:[Object(u.jsx)("div",{children:"Input:"}),Object(u.jsx)("textarea",{className:"program-input-area",ref:C})]})]})};var g=function(){var t=Object(r.useState)(""),e=Object(s.a)(t,2),n=e[0],i=e[1],c=Object(r.useState)(["",{}]),a=Object(s.a)(c,2),o=a[0],h=a[1],j=Object(r.useState)(!1),b=Object(s.a)(j,2),p=b[0],f=b[1],O=Object(r.useCallback)((function(t){i((function(e){return e+String.fromCharCode(t)}))}),[]);return Object(u.jsxs)("div",{className:"App-header",children:[!p&&Object(u.jsx)(l,{code:o[0],setInput:function(t,e){return h([t,e])}}),Object(u.jsx)(v,{running:p,setRunning:function(t){f(t),t||i("")},input:o,outHandler:O}),p&&Object(u.jsx)(d,{text:n})]})};a.a.render(Object(u.jsx)(i.a.StrictMode,{children:Object(u.jsx)(g,{})}),document.getElementById("root"))}},[[15,1,2]]]);
|
|
//# sourceMappingURL=main.cb19c05d.chunk.js.map
|