Commit c7a5d217 authored by Raghav Khanna's avatar Raghav Khanna
Browse files

Check for error before proccessing graph

parent c8a32334
......@@ -31,27 +31,30 @@ class App extends React.Component {
name: "",
attributes: {value: ""},
highlighting: {
wacc: [{
wacc: [{
startRow: 0,
startCol: 0,
endRow: 0,
endCol: 0,
className: "",
type: ""}],
js: [{
type: ""
}],
js: [{
startRow: 0,
startCol: 0,
endRow: 0,
endCol: 0,
className: "",
type: ""}],
arm: [{
type: ""
}],
arm: [{
startRow: 0,
startCol: 0,
endRow: 0,
endCol: 0,
className: "",
type: ""}]
type: ""
}]
},
children: [{}]
}
......@@ -68,15 +71,15 @@ class App extends React.Component {
}
onNodeOver = (nodeData, evt) => {
let hl = nodeData.highlighting;
let hl = nodeData.highlighting;
this.setState((state, props) => {
state.wacc.markers = hl.wacc;
state.js.markers = hl.js;
state.arm.markers = hl.arm;
this.setState((state, props) => {
state.wacc.markers = hl.wacc;
state.js.markers = hl.js;
state.arm.markers = hl.arm;
return state
})
return state
})
}
onNodeOut = (nodeData, evt) => {
......@@ -84,7 +87,9 @@ class App extends React.Component {
readInputCallBack = (codeToEval) => {
eval(codeToEval);
window.EMULATOR_CONSOLE_READ = () => { return window.prompt()};
window.EMULATOR_CONSOLE_READ = () => {
return window.prompt()
};
};
clearConsole = () => {
......@@ -110,31 +115,37 @@ class App extends React.Component {
};
proccesLine = () => {
if(this.state.statementIndex < this.state.mainStatements.length){
if (this.state.statementIndex < this.state.mainStatements.length) {
let current = this.state.currentNode;
let jsLines = this.state.js.code.split(/;\n(?!})/);
// console.log(jsLines)
// console.log(current)
let codeLine = jsLines[current.highlighting.js[0].startRow];
codeLine = codeLine.replace("var ", "window.");
eval(codeLine);;
eval(codeLine);
;
let newIndex = this.state.statementIndex + 1;
this.setState({
currentNode: this.state.mainStatements[newIndex],
statementIndex: newIndex})
statementIndex: newIndex
})
} else {
console.log("Finished executing code")
}
};
getStatements = () => {
let rootChildren = this.state.graphData.children;
let funcMain = rootChildren[rootChildren.length - 1];
let mainFuncStatementsNode = funcMain.children[0];
let mainFuncStatements = mainFuncStatementsNode.children;
this.setState({mainStatements: mainFuncStatements,
currentNode: mainFuncStatements[0],
statementIndex: 0})
if (typeof this.state.graphData.children !== "undefined") {
let rootChildren = this.state.graphData.children;
let funcMain = rootChildren[rootChildren.length - 1];
let mainFuncStatementsNode = funcMain.children[0];
let mainFuncStatements = mainFuncStatementsNode.children;
this.setState({
mainStatements: mainFuncStatements,
currentNode: mainFuncStatements[0],
statementIndex: 0
})
}
};
render() {
......@@ -148,93 +159,98 @@ class App extends React.Component {
<ButtonStrip
onCompileClick={(e) => {
this.processWaccCode(this.state.wacc.code).then(() => {
this.clearConsole()
this.getStatements()})
if (typeof this.state.graphData.children !== "undefined") {
this.clearConsole()
this.getStatements()
}
}
)
}}
onExecuteClick={(e) => {
eval(this.state.js.code)
eval("waccPrintFinished()")
}}
onStepWaccClick={(e) => {
this.readInputCallBack(e)
this.proccesLine()
}}
/>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={4}>
<Card>
<CardBody>
<CodeEditor
heading='WACC Code'
onCodeChange={this.onWaccCodeChange}
value={this.state.wacc.code}
markers={this.state.wacc.markers}/>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={4}>
<Card>
<CardBody>
<CodeEditor
heading='JavaScript'
value={this.state.js.code}
markers={this.state.js.markers}
readOnly={true}/>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={4}>
<Card>
<CardBody>
<CodeEditor
heading='ARM Assembly'
value={this.state.arm.code}
markers={this.state.arm.markers}
readOnly={true}/>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={8}>
<Card>
<CardBody>
<div style={{height: '50em'}}>
<Tree
/>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={4}>
<Card>
<CardBody>
<CodeEditor
heading='WACC Code'
onCodeChange={this.onWaccCodeChange}
value={this.state.wacc.code}
markers={this.state.wacc.markers}/>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={4}>
<Card>
<CardBody>
<CodeEditor
heading='JavaScript'
value={this.state.js.code}
markers={this.state.js.markers}
readOnly={true}/>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={4}>
<Card>
<CardBody>
<CodeEditor
heading='ARM Assembly'
value={this.state.arm.code}
markers={this.state.arm.markers}
readOnly={true}/>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={8}>
<Card>
<CardBody>
<div style={{height: '50em'}}>
<Tree
collapsible={false}
data={this.state.graphData}
onMouseOver={this.onNodeOver}
onMouseOut={this.onNodeOut}
orientation="vertical"/>
</div>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={4}>
<Card>
<CardBody>
<div
style={{
</div>
</CardBody>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={4}>
<Card>
<CardBody>
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
height: "50em"
}}
>
<Terminal commandPassThrough={cmd => {
}}
>
<Terminal commandPassThrough={cmd => {
window.EMULATOR_CONSOLE_READ = () => {return cmd[0]};
window.EMULATOR_IS_INPUT = true;
}} watchConsoleLogging hideTopBar allowTabs={false} key={this.state.consoleReset}/>
</div>
</CardBody>
</Card>
</GridItem>
</GridContainer>
</div>
</div>
)
}
}
}} watchConsoleLogging hideTopBar allowTabs={false} key={this.state.consoleReset}/>
</div>
</CardBody>
</Card>
</GridItem>
</GridContainer>
</div>
</div>
)
}
}
export default App;
export default App;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment