-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove extra closing tag and reformat index.html * Install prettier and reformat codebase
- Loading branch information
Showing
16 changed files
with
932 additions
and
760 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true | ||
"env": { | ||
"browser": true, | ||
"es6": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:react/recommended", | ||
"plugin:react-hooks/recommended", | ||
"prettier" | ||
], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:react/recommended", | ||
"plugin:react-hooks/recommended" | ||
], | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 11, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"react" | ||
], | ||
"rules": { | ||
"react/prop-types": 0 | ||
} | ||
"ecmaVersion": 11, | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["react", "prettier"], | ||
"rules": { | ||
"react/prop-types": 0, | ||
"prettier/prettier": ["error"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"printWidth": 80 | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,120 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import MonacoEditor from 'react-monaco-editor'; | ||
|
||
const Code = (props) => { | ||
const [monaco, setMonaco] = useState(null); | ||
const [editor, setEditor] = useState(null); | ||
const [monaco, setMonaco] = useState(null); | ||
const [editor, setEditor] = useState(null); | ||
|
||
// IDisposable to clean up the hover provider. | ||
const [hoverDisposable, setHoverCleanup] = useState(null); | ||
// IDisposable to clean up the hover provider. | ||
const [hoverDisposable, setHoverCleanup] = useState(null); | ||
|
||
// Hook to update the map of source line to instruction. | ||
useEffect(() => { | ||
if (!monaco) { | ||
return; | ||
} | ||
// Hook to update the map of source line to instruction. | ||
useEffect(() => { | ||
if (!monaco) { | ||
return; | ||
} | ||
|
||
let map = new Map(); | ||
if (props.parsedInstructions) { | ||
props.parsedInstructions | ||
.filter((instruction) => instruction) | ||
.map((instruction) => map.set(instruction.Line, instruction)); | ||
} | ||
|
||
if (hoverDisposable) { | ||
hoverDisposable.dispose(); | ||
} | ||
|
||
let map = new Map(); | ||
if (props.parsedInstructions) { | ||
props.parsedInstructions | ||
.filter(instruction => instruction) | ||
.map(instruction => map.set(instruction.Line, instruction)); | ||
let disposable = monaco.languages.registerHoverProvider('mips', { | ||
provideHover: (model, position) => { | ||
if (map.size === 0) { | ||
return; | ||
} | ||
|
||
if (hoverDisposable) { | ||
hoverDisposable.dispose(); | ||
const line = position.lineNumber; | ||
if (!map.has(line)) { | ||
return; | ||
} | ||
|
||
let disposable = monaco.languages.registerHoverProvider("mips", {provideHover: | ||
(model, position) => { | ||
if (map.size === 0) { | ||
return; | ||
} | ||
|
||
const line = position.lineNumber; | ||
if (!map.has(line)) { | ||
return; | ||
} | ||
|
||
const instruction = map.get(line); | ||
return { | ||
range: new monaco.Range(line, 0, line, model.getLineMaxColumn(line)), | ||
contents: [ | ||
{ value: `*Address*: \`${instruction.Address}\``}, | ||
{ value: `*OpCode*: \`${instruction.OpCode}\``}, | ||
{ value: `*Binary*: \`${instruction.BinaryRepresentation}\``}, | ||
] | ||
} | ||
}, | ||
}); | ||
setHoverCleanup(disposable); | ||
}, [props.parsedInstructions, monaco]); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
|
||
const editorDidMount = (editor, monaco) => { | ||
setMonaco(monaco); | ||
setEditor(editor); | ||
const instruction = map.get(line); | ||
return { | ||
range: new monaco.Range(line, 0, line, model.getLineMaxColumn(line)), | ||
contents: [ | ||
{ value: `*Address*: \`${instruction.Address}\`` }, | ||
{ value: `*OpCode*: \`${instruction.OpCode}\`` }, | ||
{ value: `*Binary*: \`${instruction.BinaryRepresentation}\`` }, | ||
], | ||
}; | ||
}, | ||
}); | ||
setHoverCleanup(disposable); | ||
}, [props.parsedInstructions, monaco]); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
const editorDidMount = (editor, monaco) => { | ||
setMonaco(monaco); | ||
setEditor(editor); | ||
}; | ||
|
||
const options = { | ||
selectOnLineNumbers: true, | ||
roundedSelection: false, | ||
readOnly: false, | ||
cursorStyle: 'line', | ||
codelens: false, | ||
minimap: { enabled: false }, | ||
tabsize: 4, | ||
lineNumbersMinChars: 3, | ||
|
||
// Note: the documentation mentions this might have a negative performance | ||
// impact. | ||
automaticLayout: true, | ||
}; | ||
|
||
// Hook to compute and set markers for warnings and errors. | ||
useEffect(() => { | ||
if (!monaco || !editor) { | ||
return; | ||
} | ||
|
||
const options = { | ||
selectOnLineNumbers: true, | ||
roundedSelection: false, | ||
readOnly: false, | ||
cursorStyle: "line", | ||
codelens: false, | ||
minimap: {enabled: false}, | ||
tabsize: 4, | ||
lineNumbersMinChars: 3, | ||
|
||
// Note: the documentation mentions this might have a negative performance | ||
// impact. | ||
automaticLayout: true, | ||
}; | ||
|
||
// Hook to compute and set markers for warnings and errors. | ||
useEffect(() => { | ||
if (!monaco || !editor) { | ||
return; | ||
} | ||
|
||
const model = editor.getModel(); | ||
monaco.editor.setModelMarkers(model, "EduMIPS64", []); | ||
const model = editor.getModel(); | ||
monaco.editor.setModelMarkers(model, 'EduMIPS64', []); | ||
|
||
if(!props.parsingErrors) { | ||
return; | ||
} | ||
if (!props.parsingErrors) { | ||
return; | ||
} | ||
|
||
console.log("Parsing errors", props.parsingErrors); | ||
const lines = editor.getValue().split("\n"); | ||
const markers = props.parsingErrors.map(err => { | ||
const line = lines[err.row-1]; | ||
// First non-space character. | ||
const startColumn = line.search(/\S/)+1; | ||
return { | ||
startLineNumber: err.row, | ||
endLineNumber: err.row, | ||
startColumn: startColumn, | ||
endColumn: line.length+1, | ||
message: `${err.description}`, | ||
severity: err.isWarning ? 4 : 8, | ||
source: 'EduMIPS64', | ||
}; | ||
}); | ||
console.log("Markers", markers); | ||
|
||
monaco.editor.setModelMarkers(model, "EduMIPS64", markers); | ||
}, [props.parsingErrors, editor, monaco]); | ||
|
||
return ( | ||
<MonacoEditor | ||
language="mips" | ||
value={props.code} | ||
options={options} | ||
onChange={props.onChangeValue} | ||
theme="vs-light" | ||
editorDidMount={editorDidMount} | ||
/> | ||
) | ||
} | ||
|
||
export default Code; | ||
console.log('Parsing errors', props.parsingErrors); | ||
const lines = editor.getValue().split('\n'); | ||
const markers = props.parsingErrors.map((err) => { | ||
const line = lines[err.row - 1]; | ||
// First non-space character. | ||
const startColumn = line.search(/\S/) + 1; | ||
return { | ||
startLineNumber: err.row, | ||
endLineNumber: err.row, | ||
startColumn: startColumn, | ||
endColumn: line.length + 1, | ||
message: `${err.description}`, | ||
severity: err.isWarning ? 4 : 8, | ||
source: 'EduMIPS64', | ||
}; | ||
}); | ||
console.log('Markers', markers); | ||
|
||
monaco.editor.setModelMarkers(model, 'EduMIPS64', markers); | ||
}, [props.parsingErrors, editor, monaco]); | ||
|
||
return ( | ||
<MonacoEditor | ||
language="mips" | ||
value={props.code} | ||
options={options} | ||
onChange={props.onChangeValue} | ||
theme="vs-light" | ||
editorDidMount={editorDidMount} | ||
/> | ||
); | ||
}; | ||
|
||
export default Code; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,60 @@ | ||
import React from "react"; | ||
import ErrorDisplay from "./ErrorDisplay"; | ||
import React from 'react'; | ||
import ErrorDisplay from './ErrorDisplay'; | ||
|
||
// Number of steps to run with the multi-step button. | ||
const STEP_STRIDE = 500; | ||
|
||
const Controls = (props) => { | ||
return ( | ||
<div id="controls"> | ||
<input id="load-button" type="button" value="Load/Reset" onClick={() => {props.onLoadClick()}} disabled={!props.loadEnabled} /> | ||
<input id="step-button" type="button" value="Single Step" onClick={() => {props.onStepClick(1)}} disabled={!props.stepEnabled} /> | ||
<input id="multi-step-button" type="button" value="Multi Step" onClick={() => {props.onStepClick(STEP_STRIDE)}} disabled={!props.stepEnabled} /> | ||
<input id="run-button" type="button" value="Run All" onClick={() => {props.onRunClick()}} disabled={!props.runEnabled} /> | ||
<input id="stop-button" type="button" value="Stop" onClick={() => {props.onStopClick()}} disabled={!props.stopEnabled} /> | ||
<ErrorDisplay parsingErrors={props.parsingErrors} /> | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div id="controls"> | ||
<input | ||
id="load-button" | ||
type="button" | ||
value="Load/Reset" | ||
onClick={() => { | ||
props.onLoadClick(); | ||
}} | ||
disabled={!props.loadEnabled} | ||
/> | ||
<input | ||
id="step-button" | ||
type="button" | ||
value="Single Step" | ||
onClick={() => { | ||
props.onStepClick(1); | ||
}} | ||
disabled={!props.stepEnabled} | ||
/> | ||
<input | ||
id="multi-step-button" | ||
type="button" | ||
value="Multi Step" | ||
onClick={() => { | ||
props.onStepClick(STEP_STRIDE); | ||
}} | ||
disabled={!props.stepEnabled} | ||
/> | ||
<input | ||
id="run-button" | ||
type="button" | ||
value="Run All" | ||
onClick={() => { | ||
props.onRunClick(); | ||
}} | ||
disabled={!props.runEnabled} | ||
/> | ||
<input | ||
id="stop-button" | ||
type="button" | ||
value="Stop" | ||
onClick={() => { | ||
props.onStopClick(); | ||
}} | ||
disabled={!props.stopEnabled} | ||
/> | ||
<ErrorDisplay parsingErrors={props.parsingErrors} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Controls; | ||
export default Controls; |
Oops, something went wrong.