-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
284 lines (284 loc) · 6.34 KB
/
Copy pathmain.js
File metadata and controls
284 lines (284 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// Generated by Haxe 4.0.0 (git build development @ 7429981)
(function () { "use strict";
var $estr = function() { return js_Boot.__string_rec(this,''); };
function $extend(from, fields) {
function Inherit() {} Inherit.prototype = from; var proto = new Inherit();
for (var name in fields) proto[name] = fields[name];
if( fields.toString !== Object.prototype.toString ) proto.toString = fields.toString;
return proto;
}
var Main = function() { };
Main.__name__ = true;
Main.getNumber = function(cb) {
cb(++Main.nextNumber);
};
Main.getNumberPromise = function() {
return new Promise(function(resolve,_) {
Main.getNumber(resolve);
return;
});
};
Main.someAsync = function(__continuation) {
var __state = 0;
var tmp0;
var promise;
var tmp1;
var __stateMachine = null;
__stateMachine = function(__result) {
while(true) switch(__state) {
case 0:
console.log("Main.hx:23:","hi");
__state = 1;
break;
case 1:
__state = 2;
Main.getNumber(__stateMachine);
return;
case 2:
tmp0 = __result;
if(tmp0 < 10) {
__state = 3;
} else {
__state = 5;
}
break;
case 3:
console.log("Main.hx:25:","wait for it...");
promise = Main.getNumberPromise();
__state = 4;
promise.then(__stateMachine);
return;
case 4:
tmp1 = __result;
console.log("Main.hx:28:",tmp1);
__state = 1;
break;
case 5:
console.log("Main.hx:30:","bye");
__state = -1;
__continuation(15);
return;
default:
throw new js__$Boot_HaxeError("Invalid state");
}
};
return __stateMachine;
};
Main.fibonacci = function($yield,__continuation) {
var __state = 0;
var tmp0;
var cur;
var next;
var tmp1;
var tmp;
var __stateMachine = null;
__stateMachine = function(__result) {
while(true) switch(__state) {
case 0:
__state = 1;
$yield(1,__stateMachine);
return;
case 1:
tmp0 = __result;
cur = 1;
next = 1;
__state = 2;
break;
case 2:
__state = 3;
break;
case 3:
__state = 4;
$yield(next,__stateMachine);
return;
case 4:
tmp1 = __result;
tmp = cur + next;
cur = next;
next = tmp;
__state = 2;
break;
case 5:
__state = -1;
__continuation(null);
return;
default:
throw new js__$Boot_HaxeError("Invalid state");
}
};
return __stateMachine;
};
Main.main = function() {
(Main.someAsync(function(result) {
console.log("Main.hx:47:","Result: " + result);
return;
}))(null);
var v = new Gen(Main.fibonacci);
while(v.hasNext()) {
var v1 = v.next();
console.log("Main.hx:51:",v1);
if(v1 > 10000) {
break;
}
}
};
var GenState = { __ename__ : true, __constructs__ : ["NotReady","Ready","Done","Failed"] };
GenState.NotReady = ["NotReady",0];
GenState.NotReady.toString = $estr;
GenState.NotReady.__enum__ = GenState;
GenState.Ready = ["Ready",1];
GenState.Ready.toString = $estr;
GenState.Ready.__enum__ = GenState;
GenState.Done = ["Done",2];
GenState.Done.toString = $estr;
GenState.Done.__enum__ = GenState;
GenState.Failed = ["Failed",3];
GenState.Failed.toString = $estr;
GenState.Failed.__enum__ = GenState;
var Gen = function(cont) {
this.nextStep = cont($bind(this,this["yield"]),$bind(this,this.done));
this.state = GenState.NotReady;
};
Gen.__name__ = true;
Gen.prototype = {
'yield': function(value,next) {
this.nextValue = value;
this.state = GenState.Ready;
}
,done: function(result) {
this.state = GenState.Done;
}
,hasNext: function() {
switch(this.state[1]) {
case 1:
return true;
case 2:
return false;
default:
this.state = GenState.Failed;
this.nextStep(null);
return this.state == GenState.Ready;
}
}
,next: function() {
if(!this.hasNext()) {
throw new js__$Boot_HaxeError("no more");
}
this.state = GenState.NotReady;
return this.nextValue;
}
};
Math.__name__ = true;
var js__$Boot_HaxeError = function(val) {
Error.call(this);
this.val = val;
this.message = String(val);
if(Error.captureStackTrace) {
Error.captureStackTrace(this,js__$Boot_HaxeError);
}
};
js__$Boot_HaxeError.__name__ = true;
js__$Boot_HaxeError.wrap = function(val) {
if((val instanceof Error)) {
return val;
} else {
return new js__$Boot_HaxeError(val);
}
};
js__$Boot_HaxeError.__super__ = Error;
js__$Boot_HaxeError.prototype = $extend(Error.prototype,{
});
var js_Boot = function() { };
js_Boot.__name__ = true;
js_Boot.__string_rec = function(o,s) {
if(o == null) {
return "null";
}
if(s.length >= 5) {
return "<...>";
}
var t = typeof(o);
if(t == "function" && (o.__name__ || o.__ename__)) {
t = "object";
}
switch(t) {
case "function":
return "<function>";
case "object":
if(o instanceof Array) {
if(o.__enum__) {
if(o.length == 2) {
return o[0];
}
var str = o[0] + "(";
s += "\t";
var _g1 = 2;
var _g = o.length;
while(_g1 < _g) {
var i = _g1++;
if(i != 2) {
str += "," + js_Boot.__string_rec(o[i],s);
} else {
str += js_Boot.__string_rec(o[i],s);
}
}
return str + ")";
}
var l = o.length;
var i1;
var str1 = "[";
s += "\t";
var _g11 = 0;
var _g2 = l;
while(_g11 < _g2) {
var i2 = _g11++;
str1 += (i2 > 0 ? "," : "") + js_Boot.__string_rec(o[i2],s);
}
str1 += "]";
return str1;
}
var tostr;
try {
tostr = o.toString;
} catch( e ) {
return "???";
}
if(tostr != null && tostr != Object.toString && typeof(tostr) == "function") {
var s2 = o.toString();
if(s2 != "[object Object]") {
return s2;
}
}
var k = null;
var str2 = "{\n";
s += "\t";
var hasp = o.hasOwnProperty != null;
for( var k in o ) {
if(hasp && !o.hasOwnProperty(k)) {
continue;
}
if(k == "prototype" || k == "__class__" || k == "__super__" || k == "__interfaces__" || k == "__properties__") {
continue;
}
if(str2.length != 2) {
str2 += ", \n";
}
str2 += s + k + " : " + js_Boot.__string_rec(o[k],s);
}
s = s.substring(1);
str2 += "\n" + s + "}";
return str2;
case "string":
return o;
default:
return String(o);
}
};
var $_, $fid = 0;
function $bind(o,m) { if( m == null ) return null; if( m.__id__ == null ) m.__id__ = $fid++; var f; if( o.hx__closures__ == null ) o.hx__closures__ = {}; else f = o.hx__closures__[m.__id__]; if( f == null ) { f = function(){ return f.method.apply(f.scope, arguments); }; f.scope = o; f.method = m; o.hx__closures__[m.__id__] = f; } return f; }
String.__name__ = true;
Array.__name__ = true;
Date.__name__ = ["Date"];
Main.nextNumber = 0;
Main.main();
})();