This commit is contained in:
nora 2021-07-15 11:44:33 +02:00
parent db362072b7
commit d5520e1f42
5 changed files with 18 additions and 23 deletions

View file

@ -105,7 +105,6 @@ export default class Interpreter {
} }
} }
private input() { private input() {
try { try {
this._array[this._pointer] = this._inHandler(); this._array[this._pointer] = this._inHandler();

View file

@ -6,7 +6,6 @@ import Runner from "./Runner";
export const OptionContext = React.createContext<CodeOptions>({}); export const OptionContext = React.createContext<CodeOptions>({});
function App() { function App() {
const [out, setOut] = useState(""); const [out, setOut] = useState("");
const [input, setInput] = useState<[string, CodeOptions]>(["", {}]); const [input, setInput] = useState<[string, CodeOptions]>(["", {}]);
@ -23,7 +22,6 @@ function App() {
} }
} }
const inputHandler = (code: string, options: CodeOptions) => setInput([code, options]); const inputHandler = (code: string, options: CodeOptions) => setInput([code, options]);
return ( return (
<div className="App-header"> <div className="App-header">

View file

@ -14,6 +14,14 @@ interface CodeInputProps {
input: [string, CodeOptions] input: [string, CodeOptions]
} }
const codeOptions: Array<[string, keyof CodeOptions]> = [
["Minify Code", "minify"],
["Start directly", "directStart"],
["Start in blocking mode", "startSuperSpeed"],
["Breakpoints (•)", "enableBreakpoints"],
["Show ASCII in memory", "asciiView"]
]
const CodeInput = ({input: [code, options], setInput}: CodeInputProps) => { const CodeInput = ({input: [code, options], setInput}: CodeInputProps) => {
const [fontSize, setFontSize] = useState(40); const [fontSize, setFontSize] = useState(40);
@ -33,15 +41,9 @@ const CodeInput = ({input: [code, options], setInput}: CodeInputProps) => {
<input type="range" id="bf-input-fontsize-range" onChange={v => setFontSize(+v.target.value)}/> <input type="range" id="bf-input-fontsize-range" onChange={v => setFontSize(+v.target.value)}/>
</div> </div>
<CodeOption displayName="Minify Code" name="minify" options={options} onChange={changeHandler}/> {codeOptions.map(([display, id]) =>
<CodeOption displayName="Start Directly" name="directStart" options={options} <CodeOption displayName={display} name={id} options={options} onChange={changeHandler}/>
onChange={changeHandler}/> )}
<CodeOption displayName="Start in blocking mode" name="startSuperSpeed" options={options}
onChange={changeHandler}/>
<CodeOption displayName="Breakpoints (•)" name="enableBreakpoints" options={options}
onChange={changeHandler}/>
<CodeOption displayName="Show ASCII in memory" name="asciiView" options={options}
onChange={changeHandler}/>
</div> </div>
<textarea value={code} onChange={e => setInput(e.target.value, options)} style={{fontSize}} <textarea value={code} onChange={e => setInput(e.target.value, options)} style={{fontSize}}
@ -69,14 +71,13 @@ interface CodeOptionProps {
onChange: (name: keyof CodeOptions) => (event: ChangeEvent<HTMLInputElement>) => void, onChange: (name: keyof CodeOptions) => (event: ChangeEvent<HTMLInputElement>) => void,
} }
const CodeOption = ({displayName, name, options, onChange}: CodeOptionProps) => { const CodeOption = ({displayName, name, options, onChange}: CodeOptionProps) => (
return (
<span> <span>
<input type="checkbox" checked={options[name]} id={`input-options-${name}`} <input type="checkbox" checked={options[name]} id={`input-options-${name}`}
onChange={onChange(name)}/> onChange={onChange(name)}/>
<label htmlFor={`input-options-${name}`}>{displayName}</label> <label htmlFor={`input-options-${name}`}>{displayName}</label>
</span> </span>
); );
}
export default CodeInput; export default CodeInput;

View file

@ -19,13 +19,11 @@ const Runner = ({setRunning, running, outHandler, code}: RunInfoProps) => {
const [startTime, setStartTime] = useState(0); const [startTime, setStartTime] = useState(0);
const [, setRerenderNumber] = useState(0); const [, setRerenderNumber] = useState(0);
const options = useContext(OptionContext);
const rerender = () => setRerenderNumber(n => n + 1); const rerender = () => setRerenderNumber(n => n + 1);
const inputArea = useRef<HTMLTextAreaElement>(null); const options = useContext(OptionContext);
const inputArea = useRef<HTMLTextAreaElement>(null);
const inputHandler = () => { const inputHandler = () => {
if (!inputArea.current) { if (!inputArea.current) {

View file

@ -5,5 +5,4 @@
"gameoflife": "\n Linus Akesson presents:\n The Game Of Life implemented in Brainfuck\n +>>++++[<++++>-]<[<++++++>-]+[<[>>>>+<<<<-]>>>>[<<<<+>>>>>>+<<-]<+\n +++[>++++++++<-]>.[-]<+++[>+++<-]>+[>>.+<<-]>>[-]<<<++[<+++++>-]<.<<[>>>>+\n <<<<-]>>>>[<<<<+>>>>>>+<<-]<<[>>>>.+<<<++++++++++[<[>>+<<-]>>[<<+>>>>>++++++++\n +++<<<-]<[>+<-]>[<+>>>>+<<<-]>>>[>>>>>>>>>>>>+>+<< <<<<<<<<<<<-]>>>>>>>>>>\n>>[-[>>>>+<<<<-]>[>>>>+<<<<-]>>>]> >>[<<<+>> >- ]<<<[>>+>+<<<-]>[->[<<<\n<+>>>>-]<[<<< <+> >>>-]<<<< ]< ++++++ ++ +[>+++++<-]>>[<<+>>-]<\n<[>---<-]>.[- ] <<<<<<<<< < <<<<<< < -]++++++++++.[-]<-]>>>\n>[-]<[-]+++++ +++[>++++ ++++< - ]>--.[-]<,----------[<+\n>-]>>>>>>+<<<<< < <[>+>>>>>+>[ -]<<< << <<-]>++++++++++>>>>>[[-]\n<<,<<<<<<<->>>> > >>[<<<<+>>>>-]<<<<[>>>>+ >+<<<<<-]>>>>>----------[<<<<\n<<<<+<[>>>>+<<< <-]>>>>[<<<<+>>>>>>+<<- ]>[>-<-]>++++++++++[>+++++++++\n++<-]<<<<<<[>>> >+<<<<-]>>>>[<<<<+>>>>> >+<<-]>>>>[<<->>-]<<++++++++++\n[>+<-]>[>>>>>>> >>>>>+>+<<<< <<<<< <<<<-]>>> >> >>>>>>>[-[>>>\n>+<<<<-]>[>>>> +<<<<-]>> > ]>> > [<< < +>>>-]+<<<[>\n>>-<<<-]>[->[< <<<+>>>>-] <[ < < < <+>>>>-]<<<\n<]<<<<<<<<<<<, [ -]]>]>[-+++ ++ + +++ ++[>+++++++\n++++>+++++++++ + +<<-]>[-[>>> +<<<- ]>>>[ < <<+ >>>>>>>+>+<\n<<<<-]>>>>[-[> > >>+<<<<-]>[> >>>+< < <<-]> > >]> >>[<<<+>>>-\n]<<<[>>+>+<<< - ]>[->[<<<<+> >>>-] < [<<< < +>> >>-]<<<<]<<\n<<<<<<[>>>+<< < -]>>>[<<<+>> >>>>> + >+<< < <<-]<<[>>+<<\n-]>>[<<+>>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>>> >>-]<<<<<<<----[>>>>>>>+<<<<<<<+[>>>>>\n >>-<<<<<<<[-]]<<<<<<<[>>>>>>>>>>>>+>+<<<<<<<<<<<<<-][ lft@df.lth.se ]>>>>>\n >>>>>>>[-[>>>>+<<<<-]>[>>>>+<<<<-]>[>>>>+<<<<-]>>]>>>[-]<[>+<-]<[-[<<<<+>>\n >>-]<<<<]<<<<<<[-]]<<<<<<<[-]<<<<-]<-]>>>>>>>>>>>[-]<<]<<<<<<<<<<]\n Type for instance \"fg\" to toggle the cell at row f and column g\n Hit enter to calculate the next generation\n Type q to quit", "gameoflife": "\n Linus Akesson presents:\n The Game Of Life implemented in Brainfuck\n +>>++++[<++++>-]<[<++++++>-]+[<[>>>>+<<<<-]>>>>[<<<<+>>>>>>+<<-]<+\n +++[>++++++++<-]>.[-]<+++[>+++<-]>+[>>.+<<-]>>[-]<<<++[<+++++>-]<.<<[>>>>+\n <<<<-]>>>>[<<<<+>>>>>>+<<-]<<[>>>>.+<<<++++++++++[<[>>+<<-]>>[<<+>>>>>++++++++\n +++<<<-]<[>+<-]>[<+>>>>+<<<-]>>>[>>>>>>>>>>>>+>+<< <<<<<<<<<<<-]>>>>>>>>>>\n>>[-[>>>>+<<<<-]>[>>>>+<<<<-]>>>]> >>[<<<+>> >- ]<<<[>>+>+<<<-]>[->[<<<\n<+>>>>-]<[<<< <+> >>>-]<<<< ]< ++++++ ++ +[>+++++<-]>>[<<+>>-]<\n<[>---<-]>.[- ] <<<<<<<<< < <<<<<< < -]++++++++++.[-]<-]>>>\n>[-]<[-]+++++ +++[>++++ ++++< - ]>--.[-]<,----------[<+\n>-]>>>>>>+<<<<< < <[>+>>>>>+>[ -]<<< << <<-]>++++++++++>>>>>[[-]\n<<,<<<<<<<->>>> > >>[<<<<+>>>>-]<<<<[>>>>+ >+<<<<<-]>>>>>----------[<<<<\n<<<<+<[>>>>+<<< <-]>>>>[<<<<+>>>>>>+<<- ]>[>-<-]>++++++++++[>+++++++++\n++<-]<<<<<<[>>> >+<<<<-]>>>>[<<<<+>>>>> >+<<-]>>>>[<<->>-]<<++++++++++\n[>+<-]>[>>>>>>> >>>>>+>+<<<< <<<<< <<<<-]>>> >> >>>>>>>[-[>>>\n>+<<<<-]>[>>>> +<<<<-]>> > ]>> > [<< < +>>>-]+<<<[>\n>>-<<<-]>[->[< <<<+>>>>-] <[ < < < <+>>>>-]<<<\n<]<<<<<<<<<<<, [ -]]>]>[-+++ ++ + +++ ++[>+++++++\n++++>+++++++++ + +<<-]>[-[>>> +<<<- ]>>>[ < <<+ >>>>>>>+>+<\n<<<<-]>>>>[-[> > >>+<<<<-]>[> >>>+< < <<-]> > >]> >>[<<<+>>>-\n]<<<[>>+>+<<< - ]>[->[<<<<+> >>>-] < [<<< < +>> >>-]<<<<]<<\n<<<<<<[>>>+<< < -]>>>[<<<+>> >>>>> + >+<< < <<-]<<[>>+<<\n-]>>[<<+>>>>> >+>+<<<<<-]>> >>[-[ > >>>+ < <<<-]>[>>>>+<\n<<<-]>[>>>>+< <<<-]>>]>>>[ - ]<[>+< - ]<[ - [<<<<+>>>>-]<<<\n<]<<<<<<<<]<< <<<<<<<<++++ + +++++ [ >+++ + ++++++[<[>>+<<-]>>[<<+\n>>>>>++++++++ + ++<<< -] < [>+<- ] >[<+ > >>>+<<<-]>>>[<<<+>>>-]\n<<<[>>>+>>>> > +<<<< << <<-]> > >>>> >>>[>>+<<-]>>[<<+<+>>\n>-]<<<------ - -----[ >> >+<<< - ]>>> [<<<+> > >>>>>+>+<<<<\n<-]>>>>[-[>> > >+<<<< -] > [>>>> + <<<<- ]>>> ] >>>[<<<+>>>-\n]<<<[>>+>+<< < -]>>> >> > > [<<<+ >>>-]<<<[>>>\n+<<<<<+>>- ]> > >>>>>[< <<+>>>-]<<<[>\n>>+<<<<<<< <<+ > >>>>>-]< <<<<<<[->[<<<<+\n>>>>-]<[<<<<+>>>>-]<<<<]>[<<<<<< <+>>> >>>>-]<<<< <<<<<+++++++++++[>\n>>+<<<-]>>>[<<<+>>>>>>>+>+<<<<<-]>>>>[-[> >>>+<<<<-]>[>>>>+<<<<-]>>>]>>>[<<<\n+>>>-]<<<[>>+>+<<<-]>>>>>>>[<<<+>>>-]<<<[ >>>+<<<<<+>>-]>>>>>>>[<<<+>>>-]<<<\n[>>>+<<<<<<<<<+>>>>>>-]<<<<<<<[->[< < < <+>>>>-]<[<<<<+>>>>-]<<<<]>[<<<<<<<\n+>>>>>>>-]<<<<<<<<<+++++++++++[>>> > >>>+>+<<<<<<<<-]>>>>>>>[-[>>>>+<<<<-\n]>[>>>>+<<<<-]>>>]>>>[<<<+>>>-]<<< [ >>+>+<<<-]>>>>>>>[<<<+>>>-]<<<[>>>+<<\n<<<+>>-]>>>>>>>[<<<+>>>-]<<<[>>>+< <<<<<<<<+>>>>>>-]<<<<<<<[->[<<<<+>>>>-\n ]<[<<<<+>>>>-]<<<<]>[<<<<<<<+>>>>> >>-]<<<<<<<----[>>>>>>>+<<<<<<<+[>>>>>\n >>-<<<<<<<[-]]<<<<<<<[>>>>>>>>>>>>+>+<<<<<<<<<<<<<-][ lft@df.lth.se ]>>>>>\n >>>>>>>[-[>>>>+<<<<-]>[>>>>+<<<<-]>[>>>>+<<<<-]>>]>>>[-]<[>+<-]<[-[<<<<+>>\n >>-]<<<<]<<<<<<[-]]<<<<<<<[-]<<<<-]<-]>>>>>>>>>>>[-]<<]<<<<<<<<<<]\n Type for instance \"fg\" to toggle the cell at row f and column g\n Hit enter to calculate the next generation\n Type q to quit",
"benchmark": ">+>+>+>+>++<[>[<+++>-\n >>>>>\n >+>+>+>+>++<[>[<+++>-\n >>>>>\n >+>+>+>+>++<[>[<+++>-\n >>>>>\n >+>+>+>+>++<[>[<+++>-\n >>>>>\n +++[->+++++<]>[-]<\n <<<<<\n ]<<]>[-]\n <<<<<\n ]<<]>[-]\n <<<<<\n ]<<]>[-]\n <<<<<\n]<<]>.", "benchmark": ">+>+>+>+>++<[>[<+++>-\n >>>>>\n >+>+>+>+>++<[>[<+++>-\n >>>>>\n >+>+>+>+>++<[>[<+++>-\n >>>>>\n >+>+>+>+>++<[>[<+++>-\n >>>>>\n +++[->+++++<]>[-]<\n <<<<<\n ]<<]>[-]\n <<<<<\n ]<<]>[-]\n <<<<<\n ]<<]>[-]\n <<<<<\n]<<]>.",
"fizzbuzz": "++++++++++[>++++++++++<-]>>++++++++++>->>>>>>>>>>>>>>>>-->+++++++[->++\n++++++++<]>[->+>+>+>+<<<<]+++>>+++>>>++++++++[-<++++<++++<++++>>>]++++\n+[-<++++<++++>>]>>-->++++++[->+++++++++++<]>[->+>+>+>+<<<<]+++++>>+>++\n++++>++++++>++++++++[-<++++<++++<++++>>>]++++++[-<+++<+++<+++>>>]>>-->\n---+[-<+]-<[+[->+]-<<->>>+>[-]++[-->++]-->+++[---++[--<++]---->>-<+>[+\n+++[----<++++]--[>]++[-->++]--<]>++[--+[-<+]->>[-]+++++[---->++++]-->[\n->+<]>>[.>]++[-->++]]-->+++]---+[-<+]->>-[+>>>+[-<+]->>>++++++++++<<[-\n>+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>\n+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->+++\n+++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]+[-<+]->>]+[-]<<<.>>>+[\n-<+]-<<]" "fizzbuzz": "++++++++++[>++++++++++<-]>>++++++++++>->>>>>>>>>>>>>>>>-->+++++++[->++\n++++++++<]>[->+>+>+>+<<<<]+++>>+++>>>++++++++[-<++++<++++<++++>>>]++++\n+[-<++++<++++>>]>>-->++++++[->+++++++++++<]>[->+>+>+>+<<<<]+++++>>+>++\n++++>++++++>++++++++[-<++++<++++<++++>>>]++++++[-<+++<+++<+++>>>]>>-->\n---+[-<+]-<[+[->+]-<<->>>+>[-]++[-->++]-->+++[---++[--<++]---->>-<+>[+\n+++[----<++++]--[>]++[-->++]--<]>++[--+[-<+]->>[-]+++++[---->++++]-->[\n->+<]>>[.>]++[-->++]]-->+++]---+[-<+]->>-[+>>>+[-<+]->>>++++++++++<<[-\n>+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>\n+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->+++\n+++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]+[-<+]->>]+[-]<<<.>>>+[\n-<+]-<<]"
} }