UNPKG

sai-language

Version:

An object-oriented language designed to afford code comprehension and maintenance. Transpiles in-place to Javascript.

271 lines (267 loc) 8.58 kB
#!/usr/bin/env node // Javascript source for async transipled by SAI // "use strict"; var prototype=new function() { this.Constructor=function(){}; this.__tobelocked=[]; this.__tobefrozen=[]; this.__contracts=[]; this.__unverified=true; this.isof={}; return this; }(); var $AI=require("sai-library"); // Generated code follows var __context={"name":"async","loader":"SAI.GetSourceFromPaths","path":"async.sai","mtime":"2018-03-01T13:33:45.767Z","fetched":"2018-03-01T13:33:48.007Z"}; var isa = prototype.isa = 'Async'; var $bindfail = function(m) { throw new Error("SAI: A call to " + m + " on object " + isa + " has come unbound from any instance of that object. (If this is not in error, mark the declaration of " + m + " as unbound.)"); } prototype.isof['Async'] = { version: '0.0.0-unspecified', isa: isa, context: __context, type: "main" }; prototype.__tobelocked = prototype.__tobelocked.concat(["'Instantiate'", "'Old'", "'Foo'", "'Bar'", "'Baz'", "'Rando'", "'Mightfail'", "'Timer'", "'Whatever'", "'Bindingfail'", "isa"]); prototype.__tobefrozen = prototype.__tobefrozen.concat(["isof"]); var $1g = function() { var $ = this; return { fruit: 1 }; } for (var i in $1g()) { prototype[i] = undefined; }; var $2g = prototype.Constructor || function() {}; prototype.Constructor = function() { $2g.call(this); var t = $1g(); for (var i in t) if (t[i] !== undefined) this[i] = t[i]; }; var $3g = prototype['Instantiate'] || function() {}; prototype['Instantiate'] = function(p) { var $_d, $_c, _p, $ = this['Instantiate'] ? this : $bindfail('Instantiate'); { $.Timer(5000, $.Whatever); $AI.debug_op('start'); (function(p) { return new Promise(function($_resolve, $_reject) { { $.Timer(500, function(p) { { $AI.debug_op('500'); $_resolve('okay then'); } }); } }) }()).then(function(p) { return new Promise(function($_resolve, $_reject) { var _p = p; { $.Timer(1000, function(p) { { $AI.debug_op(('son of bar: ' + _p)); $_resolve([$.Rando(), $.Rando(), $.Rando(), $.Mightfail()]); } }); } }) }).then(function(p) { return new Promise(function($_resolve, $_reject) { { Promise.race(p).then(function() { $_resolve.apply($, arguments); }).catch(function() { $_reject.apply($, arguments); }); } }); }).then(function(p) { return new Promise(function($_resolve, $_reject) { { $AI.debug_op(('all good ' + p)); } }) }).catch(function(p) { { $AI.debug_op(('that didn\'t work ' + p)); } }); } }; var $4g = prototype['Old'] || function() {}; prototype['Old'] = function(p) { var $_d, $_c, _e, _a, _msg, _randomlist, $0, $ = this['Old'] ? this : $bindfail('Old'); { $AI.drain_op(((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = ((undefined === ($_c = (($_d = $.Foo()).then(function() { return ($.Bar).apply($, arguments); })))) ? $_d : $_c)).then(function(p) { return new Promise(function($_resolve, $_reject) { { $.Timer(1000, function(p) { { $AI.debug_op('son of bar'); $_resolve([$.Rando(), $.Rando(), $.Rando(), $.Mightfail()]); } }); } }); })))) ? $_d : $_c)).then(function(p) { return new Promise(function($_resolve, $_reject) { var _randomlist = p; { Promise.race($AI.slice_op((_randomlist), undefined, (0 - (3)))).then(function() { $_resolve.apply($, arguments); }).catch(function() { $_reject.apply($, arguments); }); } }); })))) ? $_d : $_c)).catch(function(p) { return new Promise(function($_resolve, $_reject) { var _msg = p; { $AI.debug_op(('it was bad: ' + _msg)); $AI.debug_op(' but it will be good again'); $_resolve('failed but recovering'); } }); })))) ? $_d : $_c)).then(function(p) { return new Promise(function($_resolve, $_reject) { var _a = p; { $AI.debug_op('ANY status of ' + _a); $_resolve(); } }); })))) ? $_d : $_c)).then(function(p) { return new Promise(function($_resolve, $_reject) { { Promise.all([$.Rando(), $.Rando(), $.Rando()]).then(function() { $_resolve.apply($, arguments); }).catch(function() { $_reject.apply($, arguments); }); } }); })))) ? $_d : $_c)).then(function(p) { return new Promise(function($_resolve, $_reject) { { Promise.all([$.Rando(), $.Rando(), $.Rando()]).then(function() { $_resolve.apply($, arguments); }).catch(function() { $_reject.apply($, arguments); }); } }); })))) ? $_d : $_c)).then(function(p) { return new Promise(function($_resolve, $_reject) { var _a = p; { $AI.debug_op('ALL status of ' + _a); $_resolve(); } }); })))) ? $_d : $_c)).then(function() { return ($.Baz).apply($, arguments); })))) ? $_d : $_c)).catch(function(p) { var _e = p; { $AI.debug_op(_e); } })))) ? $_d : $_c)); } }; var $5g = prototype['Foo'] || function() {}; prototype['Foo'] = function(p) { var $ = this['Foo'] ? this : $bindfail('Foo'); return new Promise(function($_resolve, $_reject) { var $_d, $_c, $1; { $.Timer(1000, function(p) { { $AI.debug_op('foo'); $_resolve('that was foo'); } }); } }); }; var $6g = prototype['Bar'] || function() {}; prototype['Bar'] = function(p) { var $ = this['Bar'] ? this : $bindfail('Bar'); return new Promise(function($_resolve, $_reject) { var $_d, $_c, $2; { $.Timer(1000, function(p) { { $AI.debug_op('bar'); $_resolve('That was bar'); } }); } }); }; var $7g = prototype['Baz'] || function() {}; prototype['Baz'] = function(p) { var $ = this['Baz'] ? this : $bindfail('Baz'); return new Promise(function($_resolve, $_reject) { var $_d, $_c, $3; { $.Timer(100, function(p) { { $AI.debug_op('baz'); $_resolve('that was baz'); } }); } }); }; var $8g = prototype['Rando'] || function() {}; prototype['Rando'] = function(p) { var $ = this['Rando'] ? this : $bindfail('Rando'); return new Promise(function($_resolve, $_reject) { var $_d, $_c, _t, $4; { _t = (500 * Math.random()); $.Timer(_t, function(p) { { $AI.debug_op('rando(' + _t + ')'); $_resolve('rando!'); } }); } }); }; var $9g = prototype['Mightfail'] || function() {}; prototype['Mightfail'] = function(p) { var $ = this['Mightfail'] ? this : $bindfail('Mightfail'); return new Promise(function($_resolve, $_reject) { var $_d, $_c, _t, $5; { _t = (400 * Math.random()); $.Timer(_t, function(p) { { $AI.debug_op('crasho(' + _t + ')'); $_reject('ah shit'); } }); } }); }; var $10g = prototype['Timer'] || function() {}; prototype['Timer'] = function(p, _cb) { var $_d, $_c, $6, _time = p, $ = this['Timer'] ? this : $bindfail('Timer'); { setTimeout(_cb, _time); } }; var $11g = prototype['Whatever'] || function() {}; prototype['Whatever'] = function(p) { var $_d, $_c, $7, $ = this; { $AI.debug_op('this is unbound but it\'s okay because it doesn\'t reference members.'); } }; var $12g = prototype['Bindingfail'] || function() {}; prototype['Bindingfail'] = function(p) { var $_d, $_c, $8, $ = this['Bindingfail'] ? this : $bindfail('Bindingfail'); { $AI.debug_op('this is bound and an unbound call to it should fail, even though it doesn\'t reference members'); } }; $AI.finalizePrototype(prototype); if (prototype.isof[prototype.isa].type === "singleton") { prototype.Constructor(); prototype.Instantiate(); } var result=prototype.isof[prototype.isa].type === "main" ? prototype.constructor() : prototype; exports=result; try { module.exports=result; } catch(e) {}; return result;