diff --git a/src/engine/runtime.js b/src/engine/runtime.js index e4f94f8f3..6625fa465 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -1,3 +1,6 @@ +var EventEmitter = require('events'); +var util = require('util'); + var Primitives = require('./primatives'); var Sequencer = require('./sequencer'); var Thread = require('./thread'); @@ -8,6 +11,10 @@ var STEP_THREADS_INTERVAL = 1000 / 30; * A simple runtime for blocks. */ function Runtime () { + // Bind event emitter + EventEmitter.call(instance); + + // Instantiate sequencer and primitives this.sequencer = new Sequencer(this); this.primitives = new Primitives(); @@ -16,6 +23,11 @@ function Runtime () { this.stacks = []; } +/** + * Inherit from EventEmitter + */ +util.inherits(Runtime, EventEmitter); + Runtime.prototype.createBlock = function (e) { // Create new block this.blocks[e.id] = { @@ -90,8 +102,9 @@ Runtime.prototype.runAllStacks = function () { // @todo }; -Runtime.prototype.runStack = function () { +Runtime.prototype.runStack = function (e) { // @todo + console.dir(e); }; Runtime.prototype.stopAllStacks = function () { diff --git a/src/index.js b/src/index.js index ecbcecdbd..148155b51 100644 --- a/src/index.js +++ b/src/index.js @@ -12,11 +12,12 @@ function VirtualMachine () { var instance = this; // Bind event emitter and runtime to VM instance + // @todo Post message (Web Worker) polyfill EventEmitter.call(instance); instance.runtime = new Runtime(); /** - * Event listener for blockly. Handles validation and serves as a generic + * Event listener for blocks. Handles validation and serves as a generic * adapter between the blocks and the runtime interface. * * @param {Object} Blockly "block" event @@ -54,42 +55,19 @@ function VirtualMachine () { }); break; } + + // UI + if (typeof e.element === 'undefined') return; + switch (e.element) { + case 'click': + instance.runtime.runStack({ + id: e.blockId + }); + break; + } }; - // @todo UI listener - // @todo Forward runtime events - - // Event dispatcher - // this.types = keymirror({ - // // Messages to runtime - // CREATE_BLOCK: null, - // MOVE_BLOCK: null, - // CHANGE_BLOCK: null, - // DELETE_BLOCK: null, - // - // ADD_DEVICE: null, - // REMOVE_DEVICE: null, - // - // RUN_STRIP: null, - // RUN_ALL_STRIPS: null, - // STOP_ALL_STRIPS: null, - // RUN_PALETTE_BLOCK: null, - // - // // Messages from runtime - subscribe to these - // FEEDBACK_EXECUTING_BLOCK: null, - // FEEDBACK_STOPPED_EXECUTING_BLOCK: null, - // DEVICE_RUN_OP: null, - // DEVICE_STOP_OP: null, - // - // // Tell back the interpreter device has finished an op - // DEVICE_FINISHED_OP: null - // }); - - // Bind block event stream - // setTimeout(function () { - // _this.emit('foo', 'bar'); - // }, 1000); } /** @@ -97,40 +75,12 @@ function VirtualMachine () { */ util.inherits(VirtualMachine, EventEmitter); -// VirtualMachine.prototype.changeListener = function (e) { -// var _this = this; -// console.dir(this); -// -// switch (e.type) { -// case 'create': -// console.dir(e); -// _this.runtime.createBlock( -// e.blockId, -// event.xml.attributes.type.value -// ); -// break; -// case 'change': -// // @todo -// break; -// case 'move': -// // @todo -// break; -// case 'delete': -// // @todo -// break; -// } -// }; -// -// VirtualMachine.prototype.tapListener = function (e) { -// // @todo -// }; - VirtualMachine.prototype.start = function () { - this.runtime.runAllGreenFlags(); + // @todo Run all green flags }; VirtualMachine.prototype.stop = function () { - this.runtime.stop(); + // @todo Stop all threads }; VirtualMachine.prototype.save = function () { diff --git a/vm.js b/vm.js index 430c27449..c91db8ad5 100644 --- a/vm.js +++ b/vm.js @@ -58,11 +58,12 @@ var instance = this; // Bind event emitter and runtime to VM instance + // @todo Post message (Web Worker) polyfill EventEmitter.call(instance); instance.runtime = new Runtime(); /** - * Event listener for blockly. Handles validation and serves as a generic + * Event listener for blocks. Handles validation and serves as a generic * adapter between the blocks and the runtime interface. * * @param {Object} Blockly "block" event @@ -100,42 +101,19 @@ }); break; } + + // UI + if (typeof e.element === 'undefined') return; + switch (e.element) { + case 'click': + instance.runtime.runStack({ + id: e.blockId + }); + break; + } }; - // @todo UI listener - // @todo Forward runtime events - - // Event dispatcher - // this.types = keymirror({ - // // Messages to runtime - // CREATE_BLOCK: null, - // MOVE_BLOCK: null, - // CHANGE_BLOCK: null, - // DELETE_BLOCK: null, - // - // ADD_DEVICE: null, - // REMOVE_DEVICE: null, - // - // RUN_STRIP: null, - // RUN_ALL_STRIPS: null, - // STOP_ALL_STRIPS: null, - // RUN_PALETTE_BLOCK: null, - // - // // Messages from runtime - subscribe to these - // FEEDBACK_EXECUTING_BLOCK: null, - // FEEDBACK_STOPPED_EXECUTING_BLOCK: null, - // DEVICE_RUN_OP: null, - // DEVICE_STOP_OP: null, - // - // // Tell back the interpreter device has finished an op - // DEVICE_FINISHED_OP: null - // }); - - // Bind block event stream - // setTimeout(function () { - // _this.emit('foo', 'bar'); - // }, 1000); } /** @@ -143,40 +121,12 @@ */ util.inherits(VirtualMachine, EventEmitter); - // VirtualMachine.prototype.changeListener = function (e) { - // var _this = this; - // console.dir(this); - // - // switch (e.type) { - // case 'create': - // console.dir(e); - // _this.runtime.createBlock( - // e.blockId, - // event.xml.attributes.type.value - // ); - // break; - // case 'change': - // // @todo - // break; - // case 'move': - // // @todo - // break; - // case 'delete': - // // @todo - // break; - // } - // }; - // - // VirtualMachine.prototype.tapListener = function (e) { - // // @todo - // }; - VirtualMachine.prototype.start = function () { - this.runtime.runAllGreenFlags(); + // @todo Run all green flags }; VirtualMachine.prototype.stop = function () { - this.runtime.stop(); + // @todo Stop all threads }; VirtualMachine.prototype.save = function () { @@ -1232,9 +1182,12 @@ /* 6 */ /***/ function(module, exports, __webpack_require__) { - var Primitives = __webpack_require__(10); - var Sequencer = __webpack_require__(7); - var Thread = __webpack_require__(9); + var EventEmitter = __webpack_require__(1); + var util = __webpack_require__(2); + + var Primitives = __webpack_require__(7); + var Sequencer = __webpack_require__(8); + var Thread = __webpack_require__(10); var STEP_THREADS_INTERVAL = 1000 / 30; @@ -1242,6 +1195,10 @@ * A simple runtime for blocks. */ function Runtime () { + // Bind event emitter + EventEmitter.call(instance); + + // Instantiate sequencer and primitives this.sequencer = new Sequencer(this); this.primitives = new Primitives(); @@ -1250,6 +1207,11 @@ this.stacks = []; } + /** + * Inherit from EventEmitter + */ + util.inherits(Runtime, EventEmitter); + Runtime.prototype.createBlock = function (e) { // Create new block this.blocks[e.id] = { @@ -1324,8 +1286,9 @@ // @todo }; - Runtime.prototype.runStack = function () { + Runtime.prototype.runStack = function (e) { // @todo + console.dir(e); }; Runtime.prototype.stopAllStacks = function () { @@ -1355,93 +1318,6 @@ /***/ }, /* 7 */ -/***/ function(module, exports, __webpack_require__) { - - var Timer = __webpack_require__(8); - - /** - * Constructor - */ - function Sequencer (runtime) { - // Bi-directional binding for runtime - this.runtime = runtime; - - // State - this.runningThreads = []; - this.workTime = 30; - this.timer = new Timer(); - this.currentTime = 0; - } - - Sequencer.prototype.stepAllThreads = function () { - - }; - - Sequencer.prototype.stepThread = function (thread) { - - }; - - Sequencer.prototype.startSubstack = function (thread) { - - }; - - module.exports = Sequencer; - - -/***/ }, -/* 8 */ -/***/ function(module, exports) { - - /** - * Constructor - * @todo Swap out Date.now() with microtime module that works in node & browsers - */ - function Timer () { - this.startTime = 0; - } - - Timer.prototype.time = function () { - return Date.now(); - }; - - Timer.prototype.start = function () { - this.startTime = this.time(); - }; - - Timer.prototype.stop = function () { - return this.startTime - this.time(); - }; - - module.exports = Timer; - - -/***/ }, -/* 9 */ -/***/ function(module, exports) { - - /** - * Thread is an internal data structure used by the interpreter. It holds the - * state of a thread so it can continue from where it left off, and it has - * a stack to support nested control structures and procedure calls. - * - * @param {String} Unique block identifier - */ - function Thread (id) { - this.topBlockId = id; - this.blockPointer = id; - this.blockFirstTime = -1; - this.nextBlock = null; - this.waiting = null; - this.runningDeviceBlock = false; - this.stack = []; - this.repeatCounter = -1; - } - - module.exports = Thread; - - -/***/ }, -/* 10 */ /***/ function(module, exports) { function Primitives () { @@ -1487,5 +1363,92 @@ module.exports = Primitives; +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + var Timer = __webpack_require__(9); + + /** + * Constructor + */ + function Sequencer (runtime) { + // Bi-directional binding for runtime + this.runtime = runtime; + + // State + this.runningThreads = []; + this.workTime = 30; + this.timer = new Timer(); + this.currentTime = 0; + } + + Sequencer.prototype.stepAllThreads = function () { + + }; + + Sequencer.prototype.stepThread = function (thread) { + + }; + + Sequencer.prototype.startSubstack = function (thread) { + + }; + + module.exports = Sequencer; + + +/***/ }, +/* 9 */ +/***/ function(module, exports) { + + /** + * Constructor + * @todo Swap out Date.now() with microtime module that works in node & browsers + */ + function Timer () { + this.startTime = 0; + } + + Timer.prototype.time = function () { + return Date.now(); + }; + + Timer.prototype.start = function () { + this.startTime = this.time(); + }; + + Timer.prototype.stop = function () { + return this.startTime - this.time(); + }; + + module.exports = Timer; + + +/***/ }, +/* 10 */ +/***/ function(module, exports) { + + /** + * Thread is an internal data structure used by the interpreter. It holds the + * state of a thread so it can continue from where it left off, and it has + * a stack to support nested control structures and procedure calls. + * + * @param {String} Unique block identifier + */ + function Thread (id) { + this.topBlockId = id; + this.blockPointer = id; + this.blockFirstTime = -1; + this.nextBlock = null; + this.waiting = null; + this.runningDeviceBlock = false; + this.stack = []; + this.repeatCounter = -1; + } + + module.exports = Thread; + + /***/ } /******/ ]); \ No newline at end of file diff --git a/vm.min.js b/vm.min.js index 033dd0718..4b85be96a 100644 --- a/vm.min.js +++ b/vm.min.js @@ -1 +1 @@ -!function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(){var t=this;i.call(t),t.runtime=new s,t.blockListener=function(e){if("object"==typeof e&&"string"==typeof e.blockId)switch(e.type){case"create":t.runtime.createBlock({id:e.blockId,opcode:e.xml.attributes.type.value});break;case"move":t.runtime.moveBlock({id:e.blockId,oldParent:e.oldParentId,oldInput:e.oldInputName,newParent:e.newParentId,newInput:e.newInputName});break;case"change":t.runtime.changeBlock({id:e.blockId});break;case"delete":t.runtime.deleteBlock({id:e.blockId})}}}var i=n(1),o=n(2),s=n(6);o.inherits(r,i),r.prototype.start=function(){this.runtime.runAllGreenFlags()},r.prototype.stop=function(){this.runtime.stop()},r.prototype.save=function(){},r.prototype.load=function(){},t.exports=r,"undefined"!=typeof window&&(window.VirtualMachine=t.exports)},function(t,e){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(t){return"function"==typeof t}function i(t){return"number"==typeof t}function o(t){return"object"==typeof t&&null!==t}function s(t){return void 0===t}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(t){if(!i(t)||0>t||isNaN(t))throw TypeError("n must be a positive number");return this._maxListeners=t,this},n.prototype.emit=function(t){var e,n,i,u,c,l;if(this._events||(this._events={}),"error"===t&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(e=arguments[1],e instanceof Error)throw e;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[t],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:u=Array.prototype.slice.call(arguments,1),n.apply(this,u)}else if(o(n))for(u=Array.prototype.slice.call(arguments,1),l=n.slice(),i=l.length,c=0;i>c;c++)l[c].apply(this,u);return!0},n.prototype.addListener=function(t,e){var i;if(!r(e))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",t,r(e.listener)?e.listener:e),this._events[t]?o(this._events[t])?this._events[t].push(e):this._events[t]=[this._events[t],e]:this._events[t]=e,o(this._events[t])&&!this._events[t].warned&&(i=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,i&&i>0&&this._events[t].length>i&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),i||(i=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var i=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,i,s,u;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,i=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(o(n)){for(u=s;u-- >0;)if(n[u]===e||n[u].listener&&n[u].listener===e){i=u;break}if(0>i)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],r(n))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){var e;return e=this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}},function(t,e,n){(function(t,r){function i(t,n){var r={seen:[],stylize:s};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),v(n)?r.showHidden=n:n&&e._extend(r,n),_(r.showHidden)&&(r.showHidden=!1),_(r.depth)&&(r.depth=2),_(r.colors)&&(r.colors=!1),_(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),c(r,t,r.depth)}function o(t,e){var n=i.styles[e];return n?"["+i.colors[n][0]+"m"+t+"["+i.colors[n][1]+"m":t}function s(t,e){return t}function u(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}function c(t,n,r){if(t.customInspect&&n&&E(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,t);return b(i)||(i=c(t,i,r)),i}var o=l(t,n);if(o)return o;var s=Object.keys(n),v=u(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),L(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return p(n);if(0===s.length){if(E(n)){var y=n.name?": "+n.name:"";return t.stylize("[Function"+y+"]","special")}if(w(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(S(n))return t.stylize(Date.prototype.toString.call(n),"date");if(L(n))return p(n)}var g="",m=!1,k=["{","}"];if(d(n)&&(m=!0,k=["[","]"]),E(n)){var _=n.name?": "+n.name:"";g=" [Function"+_+"]"}if(w(n)&&(g=" "+RegExp.prototype.toString.call(n)),S(n)&&(g=" "+Date.prototype.toUTCString.call(n)),L(n)&&(g=" "+p(n)),0===s.length&&(!m||0==n.length))return k[0]+g+k[1];if(0>r)return w(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special");t.seen.push(n);var x;return x=m?a(t,n,r,v,s):s.map(function(e){return f(t,n,r,v,e,m)}),t.seen.pop(),h(x,g,k)}function l(t,e){if(_(e))return t.stylize("undefined","undefined");if(b(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}return m(e)?t.stylize(""+e,"number"):v(e)?t.stylize(""+e,"boolean"):y(e)?t.stylize("null","null"):void 0}function p(t){return"["+Error.prototype.toString.call(t)+"]"}function a(t,e,n,r,i){for(var o=[],s=0,u=e.length;u>s;++s)z(e,String(s))?o.push(f(t,e,n,r,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(f(t,e,n,r,i,!0))}),o}function f(t,e,n,r,i,o){var s,u,l;if(l=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]},l.get?u=l.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):l.set&&(u=t.stylize("[Setter]","special")),z(r,i)||(s="["+i+"]"),u||(t.seen.indexOf(l.value)<0?(u=y(n)?c(t,l.value,null):c(t,l.value,n-1),u.indexOf("\n")>-1&&(u=o?u.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+u.split("\n").map(function(t){return" "+t}).join("\n"))):u=t.stylize("[Circular]","special")),_(s)){if(o&&i.match(/^\d+$/))return u;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+u}function h(t,e,n){var r=0,i=t.reduce(function(t,e){return r++,e.indexOf("\n")>=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1]:n[0]+e+" "+t.join(", ")+" "+n[1]}function d(t){return Array.isArray(t)}function v(t){return"boolean"==typeof t}function y(t){return null===t}function g(t){return null==t}function m(t){return"number"==typeof t}function b(t){return"string"==typeof t}function k(t){return"symbol"==typeof t}function _(t){return void 0===t}function w(t){return x(t)&&"[object RegExp]"===O(t)}function x(t){return"object"==typeof t&&null!==t}function S(t){return x(t)&&"[object Date]"===O(t)}function L(t){return x(t)&&("[object Error]"===O(t)||t instanceof Error)}function E(t){return"function"==typeof t}function j(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||"undefined"==typeof t}function O(t){return Object.prototype.toString.call(t)}function T(t){return 10>t?"0"+t.toString(10):t.toString(10)}function I(){var t=new Date,e=[T(t.getHours()),T(t.getMinutes()),T(t.getSeconds())].join(":");return[t.getDate(),P[t.getMonth()],e].join(" ")}function z(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var B=/%[sdj%]/g;e.format=function(t){if(!b(t)){for(var e=[],n=0;n=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return t}}),u=r[n];o>n;u=r[++n])s+=y(u)||!x(u)?" "+u:" "+i(u);return s},e.deprecate=function(n,i){function o(){if(!s){if(r.throwDeprecation)throw new Error(i);r.traceDeprecation?console.trace(i):console.error(i),s=!0}return n.apply(this,arguments)}if(_(t.process))return function(){return e.deprecate(n,i).apply(this,arguments)};if(r.noDeprecation===!0)return n;var s=!1;return o};var A,D={};e.debuglog=function(t){if(_(A)&&(A=r.env.NODE_DEBUG||""),t=t.toUpperCase(),!D[t])if(new RegExp("\\b"+t+"\\b","i").test(A)){var n=r.pid;D[t]=function(){var r=e.format.apply(e,arguments);console.error("%s %d: %s",t,n,r)}}else D[t]=function(){};return D[t]},e.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},e.isArray=d,e.isBoolean=v,e.isNull=y,e.isNullOrUndefined=g,e.isNumber=m,e.isString=b,e.isSymbol=k,e.isUndefined=_,e.isRegExp=w,e.isObject=x,e.isDate=S,e.isError=L,e.isFunction=E,e.isPrimitive=j,e.isBuffer=n(4);var P=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];e.log=function(){console.log("%s - %s",I(),e.format.apply(e,arguments))},e.inherits=n(5),e._extend=function(t,e){if(!e||!x(e))return t;for(var n=Object.keys(e),r=n.length;r--;)t[n[r]]=e[n[r]];return t}}).call(e,function(){return this}(),n(3))},function(t,e){function n(){l=!1,s.length?c=s.concat(c):p=-1,c.length&&r()}function r(){if(!l){var t=setTimeout(n);l=!0;for(var e=c.length;e;){for(s=c,c=[];++p1)for(var n=1;n-1&&this.stacks.splice(e,1)},r.prototype._getNextBlock=function(t){return"undefined"==typeof this.blocks[t]?null:this.blocks[t].next},r.prototype._getSubstack=function(t){return"undefined"==typeof this.blocks[t]?null:this.blocks[t].inputs.SUBSTACK},t.exports=r},function(t,e,n){function r(t){this.runtime=t,this.runningThreads=[],this.workTime=30,this.timer=new i,this.currentTime=0}var i=n(8);r.prototype.stepAllThreads=function(){},r.prototype.stepThread=function(t){},r.prototype.startSubstack=function(t){},t.exports=r},function(t,e){function n(){this.startTime=0}n.prototype.time=function(){return Date.now()},n.prototype.start=function(){this.startTime=this.time()},n.prototype.stop=function(){return this.startTime-this.time()},t.exports=n},function(t,e){function n(t){this.topBlockId=t,this.blockPointer=t,this.blockFirstTime=-1,this.nextBlock=null,this.waiting=null,this.runningDeviceBlock=!1,this.stack=[],this.repeatCounter=-1}t.exports=n},function(t,e){function n(){}n.prototype.event_whenflagclicked=function(t,e){return Date.now()-t.blockFirstTime<300?void(t["yield"]=!0):void 0},n.prototype.control_repeat=function(t,e){return Date.now()-t.blockFirstTime<300?void(t["yield"]=!0):(-1==t.repeatCounter&&(t.repeatCounter=10),void(t.repeatCounter>0?(t.repeatCounter-=1,e.interpreter.startSubstack(t)):(t.repeatCounter=-1,t.nextBlock=e.getNextBlock(t.blockPointer))))},n.prototype.control_forever=function(t,e){return Date.now()-t.blockFirstTime<300?void(t["yield"]=!0):void e.interpreter.startSubstack(t)},t.exports=n}]); \ No newline at end of file +!function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){function r(){var e=this;i.call(e),e.runtime=new s,e.blockListener=function(t){if("object"==typeof t&&"string"==typeof t.blockId){switch(t.type){case"create":e.runtime.createBlock({id:t.blockId,opcode:t.xml.attributes.type.value});break;case"move":e.runtime.moveBlock({id:t.blockId,oldParent:t.oldParentId,oldInput:t.oldInputName,newParent:t.newParentId,newInput:t.newInputName});break;case"change":e.runtime.changeBlock({id:t.blockId});break;case"delete":e.runtime.deleteBlock({id:t.blockId})}if("undefined"!=typeof t.element)switch(t.element){case"click":e.runtime.runStack({id:t.blockId})}}}}var i=n(1),o=n(2),s=n(6);o.inherits(r,i),r.prototype.start=function(){},r.prototype.stop=function(){},r.prototype.save=function(){},r.prototype.load=function(){},e.exports=r,"undefined"!=typeof window&&(window.VirtualMachine=e.exports)},function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function i(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!i(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,i,u,c,l;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:u=Array.prototype.slice.call(arguments,1),n.apply(this,u)}else if(o(n))for(u=Array.prototype.slice.call(arguments,1),l=n.slice(),i=l.length,c=0;i>c;c++)l[c].apply(this,u);return!0},n.prototype.addListener=function(e,t){var i;if(!r(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,r(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned&&(i=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,i&&i>0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),i||(i=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var i=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,i,s,u;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=n.length,i=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(n)){for(u=s;u-- >0;)if(n[u]===t||n[u].listener&&n[u].listener===t){i=u;break}if(0>i)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(r(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,n){(function(e,r){function i(e,n){var r={seen:[],stylize:s};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),v(n)?r.showHidden=n:n&&t._extend(r,n),w(r.showHidden)&&(r.showHidden=!1),w(r.depth)&&(r.depth=2),w(r.colors)&&(r.colors=!1),w(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),c(r,e,r.depth)}function o(e,t){var n=i.styles[t];return n?"["+i.colors[n][0]+"m"+e+"["+i.colors[n][1]+"m":e}function s(e,t){return e}function u(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}function c(e,n,r){if(e.customInspect&&n&&E(n.inspect)&&n.inspect!==t.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,e);return b(i)||(i=c(e,i,r)),i}var o=l(e,n);if(o)return o;var s=Object.keys(n),v=u(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(n)),L(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return a(n);if(0===s.length){if(E(n)){var y=n.name?": "+n.name:"";return e.stylize("[Function"+y+"]","special")}if(_(n))return e.stylize(RegExp.prototype.toString.call(n),"regexp");if(S(n))return e.stylize(Date.prototype.toString.call(n),"date");if(L(n))return a(n)}var g="",m=!1,k=["{","}"];if(d(n)&&(m=!0,k=["[","]"]),E(n)){var w=n.name?": "+n.name:"";g=" [Function"+w+"]"}if(_(n)&&(g=" "+RegExp.prototype.toString.call(n)),S(n)&&(g=" "+Date.prototype.toUTCString.call(n)),L(n)&&(g=" "+a(n)),0===s.length&&(!m||0==n.length))return k[0]+g+k[1];if(0>r)return _(n)?e.stylize(RegExp.prototype.toString.call(n),"regexp"):e.stylize("[Object]","special");e.seen.push(n);var x;return x=m?p(e,n,r,v,s):s.map(function(t){return f(e,n,r,v,t,m)}),e.seen.pop(),h(x,g,k)}function l(e,t){if(w(t))return e.stylize("undefined","undefined");if(b(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}return m(t)?e.stylize(""+t,"number"):v(t)?e.stylize(""+t,"boolean"):y(t)?e.stylize("null","null"):void 0}function a(e){return"["+Error.prototype.toString.call(e)+"]"}function p(e,t,n,r,i){for(var o=[],s=0,u=t.length;u>s;++s)z(t,String(s))?o.push(f(e,t,n,r,String(s),!0)):o.push("");return i.forEach(function(i){i.match(/^\d+$/)||o.push(f(e,t,n,r,i,!0))}),o}function f(e,t,n,r,i,o){var s,u,l;if(l=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},l.get?u=l.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):l.set&&(u=e.stylize("[Setter]","special")),z(r,i)||(s="["+i+"]"),u||(e.seen.indexOf(l.value)<0?(u=y(n)?c(e,l.value,null):c(e,l.value,n-1),u.indexOf("\n")>-1&&(u=o?u.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+u.split("\n").map(function(e){return" "+e}).join("\n"))):u=e.stylize("[Circular]","special")),w(s)){if(o&&i.match(/^\d+$/))return u;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+u}function h(e,t,n){var r=0,i=e.reduce(function(e,t){return r++,t.indexOf("\n")>=0&&r++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0);return i>60?n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1]:n[0]+t+" "+e.join(", ")+" "+n[1]}function d(e){return Array.isArray(e)}function v(e){return"boolean"==typeof e}function y(e){return null===e}function g(e){return null==e}function m(e){return"number"==typeof e}function b(e){return"string"==typeof e}function k(e){return"symbol"==typeof e}function w(e){return void 0===e}function _(e){return x(e)&&"[object RegExp]"===O(e)}function x(e){return"object"==typeof e&&null!==e}function S(e){return x(e)&&"[object Date]"===O(e)}function L(e){return x(e)&&("[object Error]"===O(e)||e instanceof Error)}function E(e){return"function"==typeof e}function j(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||"undefined"==typeof e}function O(e){return Object.prototype.toString.call(e)}function T(e){return 10>e?"0"+e.toString(10):e.toString(10)}function I(){var e=new Date,t=[T(e.getHours()),T(e.getMinutes()),T(e.getSeconds())].join(":");return[e.getDate(),P[e.getMonth()],t].join(" ")}function z(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var B=/%[sdj%]/g;t.format=function(e){if(!b(e)){for(var t=[],n=0;n=o)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return e}}),u=r[n];o>n;u=r[++n])s+=y(u)||!x(u)?" "+u:" "+i(u);return s},t.deprecate=function(n,i){function o(){if(!s){if(r.throwDeprecation)throw new Error(i);r.traceDeprecation?console.trace(i):console.error(i),s=!0}return n.apply(this,arguments)}if(w(e.process))return function(){return t.deprecate(n,i).apply(this,arguments)};if(r.noDeprecation===!0)return n;var s=!1;return o};var A,D={};t.debuglog=function(e){if(w(A)&&(A=r.env.NODE_DEBUG||""),e=e.toUpperCase(),!D[e])if(new RegExp("\\b"+e+"\\b","i").test(A)){var n=r.pid;D[e]=function(){var r=t.format.apply(t,arguments);console.error("%s %d: %s",e,n,r)}}else D[e]=function(){};return D[e]},t.inspect=i,i.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},i.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"},t.isArray=d,t.isBoolean=v,t.isNull=y,t.isNullOrUndefined=g,t.isNumber=m,t.isString=b,t.isSymbol=k,t.isUndefined=w,t.isRegExp=_,t.isObject=x,t.isDate=S,t.isError=L,t.isFunction=E,t.isPrimitive=j,t.isBuffer=n(4);var P=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];t.log=function(){console.log("%s - %s",I(),t.format.apply(t,arguments))},t.inherits=n(5),t._extend=function(e,t){if(!t||!x(t))return e;for(var n=Object.keys(t),r=n.length;r--;)e[n[r]]=t[n[r]];return e}}).call(t,function(){return this}(),n(3))},function(e,t){function n(){l=!1,s.length?c=s.concat(c):a=-1,c.length&&r()}function r(){if(!l){var e=setTimeout(n);l=!0;for(var t=c.length;t;){for(s=c,c=[];++a1)for(var n=1;n-1&&this.stacks.splice(t,1)},r.prototype._getNextBlock=function(e){return"undefined"==typeof this.blocks[e]?null:this.blocks[e].next},r.prototype._getSubstack=function(e){return"undefined"==typeof this.blocks[e]?null:this.blocks[e].inputs.SUBSTACK},e.exports=r},function(e,t){function n(){}n.prototype.event_whenflagclicked=function(e,t){return Date.now()-e.blockFirstTime<300?void(e["yield"]=!0):void 0},n.prototype.control_repeat=function(e,t){return Date.now()-e.blockFirstTime<300?void(e["yield"]=!0):(-1==e.repeatCounter&&(e.repeatCounter=10),void(e.repeatCounter>0?(e.repeatCounter-=1,t.interpreter.startSubstack(e)):(e.repeatCounter=-1,e.nextBlock=t.getNextBlock(e.blockPointer))))},n.prototype.control_forever=function(e,t){return Date.now()-e.blockFirstTime<300?void(e["yield"]=!0):void t.interpreter.startSubstack(e)},e.exports=n},function(e,t,n){function r(e){this.runtime=e,this.runningThreads=[],this.workTime=30,this.timer=new i,this.currentTime=0}var i=n(9);r.prototype.stepAllThreads=function(){},r.prototype.stepThread=function(e){},r.prototype.startSubstack=function(e){},e.exports=r},function(e,t){function n(){this.startTime=0}n.prototype.time=function(){return Date.now()},n.prototype.start=function(){this.startTime=this.time()},n.prototype.stop=function(){return this.startTime-this.time()},e.exports=n},function(e,t){function n(e){this.topBlockId=e,this.blockPointer=e,this.blockFirstTime=-1,this.nextBlock=null,this.waiting=null,this.runningDeviceBlock=!1,this.stack=[],this.repeatCounter=-1}e.exports=n}]); \ No newline at end of file