diff --git a/bfi-rust/.gitignore b/bfi-rust/.gitignore index 1d65d27..5180a2e 100644 --- a/bfi-rust/.gitignore +++ b/bfi-rust/.gitignore @@ -1,5 +1,3 @@ /target .idea # brainfuck testing code, get your own -*.b -*.bf \ No newline at end of file diff --git a/ibfi-ts/src/App.scss b/ibfi-ts/src/App.scss index 82e8143..9fa2117 100644 --- a/ibfi-ts/src/App.scss +++ b/ibfi-ts/src/App.scss @@ -34,6 +34,10 @@ $medium-color: #78787f; height: 400px; font-size: 100px; } + + .code-options-wrapper > * { + margin: 10px; + } } .code-display-wrapper { @@ -67,12 +71,18 @@ $medium-color: #78787f; } } +.run-button { + height: 50px; + width: 200px; + +} + .bf-run { margin: 20px; - button { - height: 50px; - width: 200px; + + .speed-control-wrapper > * { + margin: 10px; } .small-speed-button { diff --git a/ibfi-ts/src/App.tsx b/ibfi-ts/src/components/App.tsx similarity index 86% rename from ibfi-ts/src/App.tsx rename to ibfi-ts/src/components/App.tsx index 6ebc276..13aaad3 100644 --- a/ibfi-ts/src/App.tsx +++ b/ibfi-ts/src/components/App.tsx @@ -1,11 +1,12 @@ -import './App.scss'; -import CodeInput, {CodeOptions} from "./components/CodeInput"; -import ProgramOutput from "./components/ProgramOutput"; +import '../App.scss'; +import CodeInput, {CodeOptions} from "./CodeInput"; +import ProgramOutput from "./ProgramOutput"; import React, {useCallback, useState} from "react"; -import Runner from "./components/Runner"; +import Runner from "./Runner"; export const OptionContext = React.createContext({}); + function App() { const [out, setOut] = useState(""); const [input, setInput] = useState<[string, CodeOptions]>(["", {}]); diff --git a/ibfi-ts/src/components/CodeInput.tsx b/ibfi-ts/src/components/CodeInput.tsx index 90492f6..afa4285 100644 --- a/ibfi-ts/src/components/CodeInput.tsx +++ b/ibfi-ts/src/components/CodeInput.tsx @@ -4,6 +4,7 @@ import presets from "../presets.json"; export interface CodeOptions { minify?: boolean, directStart?: boolean, + startSuperSpeed?: boolean, enableBreakpoints?: boolean asciiView?: boolean } @@ -26,7 +27,7 @@ const CodeInput = ({input: [code, options], setInput}: CodeInputProps) => { return (
-
+
setFontSize(+v.target.value)}/> @@ -35,6 +36,8 @@ const CodeInput = ({input: [code, options], setInput}: CodeInputProps) => { + void, - running: boolean + code: string, outHandler: (char: number) => void, } @@ -41,7 +42,11 @@ const Runner = ({setRunning, running, outHandler, code}: RunInfoProps) => { const startHandler = useCallback(() => { if (options.directStart) { - setSpeed(100); + if (options.startSuperSpeed) { + setSpeed(-1); + } else { + setSpeed(100); + } } else { setSpeed(0); } @@ -72,20 +77,35 @@ const Runner = ({setRunning, running, outHandler, code}: RunInfoProps) => { rerender(); }, [interpreter, startTime]); + const runBlocking = useCallback(() => { + try { + while (speed === -1 && !interpreter?.reachedEnd) { + interpreter?.next(); + } + setSpeed(0); + setInfo(`Finished Execution. Took ${(Date.now() - startTime) / 1000}s`) + } catch (e) { + setInfo(e.message); + setSpeed(0); + } + }, [speed, interpreter, startTime]); + + useEffect(() => { if (running) { if (speed === 0) { return; } - const interval = setInterval(() => { - nextHandler(); - }, 1000 / (speed * 10)); - - return () => clearInterval(interval); + if (speed > 0) { + const interval = setInterval(() => { + nextHandler(); + }, 1000 / (speed * 10)); + return () => clearInterval(interval); + } + runBlocking(); } - }, [running, nextHandler, speed]); - + }, [runBlocking, running, nextHandler, speed]); return (
@@ -96,9 +116,9 @@ const Runner = ({setRunning, running, outHandler, code}: RunInfoProps) => { }
- {running && } - - {running && } + {running && } + + {running && }
{ running && interpreter && @@ -126,7 +146,7 @@ interface SpeedControlProps { const SpeedControl = ({speed, setSpeed}: SpeedControlProps) => { return ( -
+
setSpeed(+e.target.value)}/> @@ -139,6 +159,10 @@ const SpeedControl = ({speed, setSpeed}: SpeedControlProps) => { + + + setSpeed(-1)}/> +
) } diff --git a/ibfi-ts/src/index.tsx b/ibfi-ts/src/index.tsx index c15f402..7008621 100644 --- a/ibfi-ts/src/index.tsx +++ b/ibfi-ts/src/index.tsx @@ -1,7 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; -import App from './App'; +import App from './components/App'; ReactDOM.render(