Improve block primitive lookup and execution

Slightly simplify export of block primitives from a block package.
Catch and report exceptions from block functions.
This commit is contained in:
Christopher Willis-Ford 2016-05-02 11:07:40 -07:00
parent 27c06ce476
commit 4a3276d026
4 changed files with 94 additions and 13 deletions
src/engine

View file

@ -60,18 +60,23 @@ Sequencer.prototype.stepThreads = function (threads) {
Sequencer.prototype.stepThread = function (thread) {
var opcode = this.runtime._getOpcode(thread.nextBlock);
if (!opcode) {
console.log('Could not get opcode for block: ' + thread.nextBlock);
}
else {
var blockFunction = this.runtime.getOpcodeFunction(opcode);
if (!blockFunction) {
console.log('Could not get implementation for opcode: ' + opcode);
if (!opcode) {
console.warn('Could not get opcode for block: ' + thread.nextBlock);
}
else {
blockFunction();
var blockFunction = this.runtime.getOpcodeFunction(opcode);
if (!blockFunction) {
console.warn('Could not get implementation for opcode: ' + opcode);
}
else {
try {
blockFunction();
}
catch(e) {
console.error('Exception calling block function', {opcode: opcode, exception: e});
}
}
}
}
thread.nextBlock = this.runtime._getNextBlock(thread.nextBlock);
};