// Arity structure /*jslint unparam: true, sub: true, vars: true, maxerr: 50, indent: 4 */ /*globals $*/ (function (baselib, $) { 'use strict'; var exports = {}; baselib.ports = exports; // Output Ports var OutputPort = function () {}; var isOutputPort = baselib.makeClassPredicate(OutputPort); var StandardOutputPort = function () { OutputPort.call(this); }; StandardOutputPort.prototype = baselib.heir(OutputPort.prototype); StandardOutputPort.prototype.writeDomNode = function (MACHINE, domNode) { MACHINE.params['currentDisplayer'](MACHINE, domNode); $(domNode).trigger({type : 'afterAttach'}); $('*', domNode).trigger({type : 'afterAttach'}); }; var StandardErrorPort = function () { OutputPort.call(this); }; StandardErrorPort.prototype = baselib.heir(OutputPort.prototype); StandardErrorPort.prototype.writeDomNode = function (MACHINE, domNode) { MACHINE.params['currentErrorDisplayer'](MACHINE, domNode); $(domNode).trigger({type : 'afterAttach'}); $('*', domNode).trigger({type : 'afterAttach'}); }; var OutputStringPort = function () { this.buf = []; }; OutputStringPort.prototype = baselib.heir(OutputPort.prototype); OutputStringPort.prototype.writeDomNode = function (MACHINE, v) { this.buf.push($(v).text()); }; OutputStringPort.prototype.getOutputString = function () { return this.buf.join(''); }; var isOutputStringPort = baselib.makeClassPredicate(OutputStringPort); // Input ports // Input Ports need to provide two things: // // readByte: // callWhenReady: var InputPort = function () {}; InputPort.prototype.readByte = function(MACHINE) { return baselib.constants.EOF_VALUE; }; InputPort.prototype.callWhenReady = function(MACHINE, k) { throw new Error("unimplemented"); }; var isInputPort = baselib.makeClassPredicate(InputPort); var DefaultInputPort = function() { this.content = []; this.closed = false; }; DefaultInputPort.prototype = baselib.heir(InputPort.prototype); DefaultInputPort.prototype.readByte = function(MACHINE) { if (this.content.length !== 0) { return this.content.shift(); } return baselib.constants.EOF_VALUE; }; DefaultInputPort.prototype.callWhenReady = function(MACHINE, k) { if (this.content.length > 0) { return k(); } if (this.closed) { return k(); } var that = this; var textFieldDiv = $("