diff --git a/ibfi-ts/README.md b/ibfi-ts/README.md index 1ff769f..6a76695 100644 --- a/ibfi-ts/README.md +++ b/ibfi-ts/README.md @@ -17,9 +17,10 @@ stopping it at any point in your program to see what went wrong. * manual stepping * breakpoints * error messages - +* seeing ASCII characters in memory +* manual code input ### Future features -* seeing ASCII characters in memory * fast excecution mode (no debugging info) -* better speed control \ No newline at end of file +* better speed control +* (limited) backstepping \ No newline at end of file diff --git a/ibfi-ts/src/App.tsx b/ibfi-ts/src/App.tsx index 0b2efd7..6ebc276 100644 --- a/ibfi-ts/src/App.tsx +++ b/ibfi-ts/src/App.tsx @@ -4,6 +4,8 @@ import ProgramOutput from "./components/ProgramOutput"; import React, {useCallback, useState} from "react"; import Runner from "./components/Runner"; +export const OptionContext = React.createContext({}); + function App() { const [out, setOut] = useState(""); const [input, setInput] = useState<[string, CodeOptions]>(["", {}]); @@ -20,16 +22,19 @@ function App() { } } + const inputHandler = (code: string, options: CodeOptions) => setInput([code, options]); return (
- { - !running && - } - - { - running && - } + + { + !running && + } + + { + running && + } +
); } diff --git a/ibfi-ts/src/brainfuck/Interpreter.ts b/ibfi-ts/src/brainfuck/Interpreter.ts index 32cf9f9..05b0def 100644 --- a/ibfi-ts/src/brainfuck/Interpreter.ts +++ b/ibfi-ts/src/brainfuck/Interpreter.ts @@ -2,7 +2,6 @@ import {CodeOptions} from "../components/CodeInput"; type InHandler = (() => number); type OutHandler = ((char: number) => void); -type ErrorHandler = ((msg: string) => void); export default class Interpreter { private readonly _array: Uint8Array; @@ -33,7 +32,11 @@ export default class Interpreter { } public next() { - switch (this._code[this._programCounter++]) { + this.execute(this._code[this._programCounter++]); + } + + public execute(char: string) { + switch (char) { case '+': this._array[this._pointer]++; break; @@ -67,7 +70,7 @@ export default class Interpreter { } break; case undefined: - this._pointer = this._code.length; + this._programCounter = this._code.length; break; default: break; @@ -112,7 +115,7 @@ export default class Interpreter { } public prev() { - // - + // - will add some day } get reachedEnd(): boolean { diff --git a/ibfi-ts/src/components/CodeInput.tsx b/ibfi-ts/src/components/CodeInput.tsx index 7a7c1d8..90492f6 100644 --- a/ibfi-ts/src/components/CodeInput.tsx +++ b/ibfi-ts/src/components/CodeInput.tsx @@ -1,83 +1,79 @@ -import React, {useState} from 'react'; +import React, {ChangeEvent, useState} from 'react'; import presets from "../presets.json"; export interface CodeOptions { minify?: boolean, directStart?: boolean, enableBreakpoints?: boolean + asciiView?: boolean } interface CodeInputProps { setInput: ((code: string, options: CodeOptions) => void), - code: string + input: [string, CodeOptions] } -const CodeInput = ({code, setInput}: CodeInputProps) => { +const CodeInput = ({input: [code, options], setInput}: CodeInputProps) => { const [fontSize, setFontSize] = useState(40); - const [codeOptions, setCodeOptions] = useState({}); - - const setPreset = (name: keyof typeof presets) => () => { - setInput(presets[name], codeOptions); + setInput(presets[name], options); } - const changeMinify = (e: React.ChangeEvent) => { - setCodeOptions(old => ({...old, minify: e.target.checked})) - setInput(code, codeOptions); - } - - const changeStart = (e: React.ChangeEvent) => { - setCodeOptions(old => ({...old, directStart: e.target.checked})) - setInput(code, codeOptions); - } - - const changeBreakpoint = (e: React.ChangeEvent) => { - setCodeOptions(old => ({...old, enableBreakpoints: e.target.checked})) - setInput(code, codeOptions); + const changeHandler = (name: keyof CodeOptions) => (event: ChangeEvent) => { + setInput(code, {...options, [name]: event.target.checked}) } return ( -
-
+
+
- setFontSize(+v.target.value)}/> - - - - - - - - - - - - -
-