basica
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -53,10 +53,15 @@ module.exports = Machine; | ||
// (so that immediate code can support WHILE, FOR) | ||
for (var i = 0; i < parsed.statements.length; ++i) { | ||
this.execStatement(parsed.statements[i]); | ||
// if we're running after executing a statement it means | ||
// a jump was encountered. | ||
if (this.running) { | ||
break; | ||
} | ||
try { | ||
for (var i = 0; i < parsed.statements.length; ++i) { | ||
this.evalStatement(parsed.statements[i]); | ||
// if we're running after executing a statement it means | ||
// a jump was encountered. | ||
if (this.running) { | ||
break; | ||
} | ||
} | ||
} catch (e) { | ||
this._handleRuntimeError(e); | ||
} | ||
if (!this.running) { | ||
@@ -122,9 +127,14 @@ this.newCommand(); | ||
while (this.running && batch--) { | ||
var stmt = this.program.getStatementAtIndex(this.pc++); | ||
if (!stmt) { | ||
this.running = false; | ||
} else { | ||
this.execStatement(stmt); | ||
try { | ||
while (this.running && batch--) { | ||
var stmt = this.program.getStatementAtIndex(this.pc++); | ||
if (!stmt) { | ||
this.running = false; | ||
} else { | ||
this.evalStatement(stmt); | ||
} | ||
} | ||
} catch (e) { | ||
this._handleRuntimeError(e); | ||
this.running = false; | ||
} | ||
@@ -156,14 +166,2 @@ | ||
Machine.prototype.execStatement = function(stmt) { | ||
try { | ||
this.evalStatement(stmt); | ||
} catch (e) { | ||
if (e === E.SYNTAX_ERROR || e === E.TYPE_MISMATCH || e === E.NO_SUCH_LINE) { | ||
this.printError(e); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
Machine.prototype.evalStatement = function(stmt) { | ||
@@ -346,2 +344,10 @@ switch (stmt.type) { | ||
Machine.prototype._handleRuntimeError = function(err) { | ||
if (err === E.SYNTAX_ERROR || err === E.TYPE_MISMATCH || err === E.NO_SUCH_LINE) { | ||
this.printError(err); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
Machine.prototype.newCommand = function() { | ||
@@ -348,0 +354,0 @@ this.console.print("Ready"); |
{ | ||
"name": "basica", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "BASIC interpreter", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
232728
6855