Commit c8a32334 authored by Matej Genci's avatar Matej Genci

Merge branch 'line_execution' into 'master'

Implement a basic line by line executor

See merge request !2
parents a20f30b4 74eec1c9
...@@ -24,7 +24,37 @@ class App extends React.Component { ...@@ -24,7 +24,37 @@ class App extends React.Component {
js: {code: "", markers: [],}, js: {code: "", markers: [],},
arm: {code: "", markers: [],}, arm: {code: "", markers: [],},
graphData: [{}], graphData: [{}],
consoleReset: 0 consoleReset: 0,
mainStatements: [{}],
statementIndex: 0,
currentNode: {
name: "",
attributes: {value: ""},
highlighting: {
wacc: [{
startRow: 0,
startCol: 0,
endRow: 0,
endCol: 0,
className: "",
type: ""}],
js: [{
startRow: 0,
startCol: 0,
endRow: 0,
endCol: 0,
className: "",
type: ""}],
arm: [{
startRow: 0,
startCol: 0,
endRow: 0,
endCol: 0,
className: "",
type: ""}]
},
children: [{}]
}
} }
} }
...@@ -76,7 +106,36 @@ class App extends React.Component { ...@@ -76,7 +106,36 @@ class App extends React.Component {
graphData: graph graphData: graph
}) })
} }
}
};
proccesLine = () => {
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);;
let newIndex = this.state.statementIndex + 1;
this.setState({
currentNode: this.state.mainStatements[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})
};
render() { render() {
return ( return (
...@@ -88,8 +147,9 @@ class App extends React.Component { ...@@ -88,8 +147,9 @@ class App extends React.Component {
<CardBody> <CardBody>
<ButtonStrip <ButtonStrip
onCompileClick={(e) => { onCompileClick={(e) => {
this.processWaccCode(this.state.wacc.code) this.processWaccCode(this.state.wacc.code).then(() => {
this.clearConsole() this.clearConsole()
this.getStatements()})
}} }}
onExecuteClick={(e) => { onExecuteClick={(e) => {
eval(this.state.js.code) eval(this.state.js.code)
......
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