mirror of
https://github.com/Noratrieb/brainfuck.git
synced 2026-01-16 22:35:03 +01:00
works
This commit is contained in:
parent
e815fd8c66
commit
5f6d1d5b4b
8 changed files with 225 additions and 52 deletions
|
|
@ -1,33 +1,31 @@
|
|||
import './App.scss';
|
||||
import CodeInput from "./components/CodeInput";
|
||||
import ProgramOutput from "./components/ProgramOutput";
|
||||
import React, {useState} from "react";
|
||||
import Interpreter from "./brainfuck/Interpreter";
|
||||
import RunInfo from "./components/RunInfo";
|
||||
import React, {useCallback, useState} from "react";
|
||||
import Runner from "./components/Runner";
|
||||
|
||||
function App() {
|
||||
const [interpreter, setInterpreter] = useState<Interpreter | null>(null);
|
||||
|
||||
const [out, setOut] = useState("");
|
||||
const [input, setInput] = useState("");
|
||||
const [running, setRunning] = useState(false);
|
||||
|
||||
const outHandler = (char: number) => {
|
||||
const outHandler = useCallback((char: number) => {
|
||||
setOut(out => out + String.fromCharCode(char))
|
||||
}
|
||||
}, []);
|
||||
|
||||
const inHandler = (): number => {
|
||||
const inHandler = useCallback((): number => {
|
||||
return 65;
|
||||
}
|
||||
|
||||
const start = () => setInterpreter(new Interpreter(input, outHandler, inHandler));
|
||||
const next = () => interpreter?.next();
|
||||
const prev = () => interpreter?.prev();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="App-header">
|
||||
<CodeInput setInput={input => setInput(input)}/>
|
||||
<RunInfo nextHandler={next} prevHandler={prev} startHandler={start} interpreter={interpreter}/>
|
||||
<ProgramOutput text={out}/>
|
||||
{
|
||||
!running && <CodeInput setInput={input => setInput(input)}/>
|
||||
}
|
||||
<Runner running={running} setRunning={setRunning} input={input} outHandler={outHandler} inHandler={inHandler}/>
|
||||
{
|
||||
running && <ProgramOutput text={out}/>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue