-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
286 lines (286 loc) · 9.68 KB
/
test.js
File metadata and controls
286 lines (286 loc) · 9.68 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
285
286
// This program was compiled from OCaml by js_of_ocaml 1.0
function caml_raise_with_arg (tag, arg) { throw [0, tag, arg]; }
function caml_raise_with_string (tag, msg) {
caml_raise_with_arg (tag, new MlWrappedString (msg));
}
function caml_invalid_argument (msg) {
caml_raise_with_string(caml_global_data[4], msg);
}
function caml_array_bound_error () {
caml_invalid_argument("index out of bounds");
}
function caml_str_repeat(n, s) {
if (!n) { return ""; }
if (n & 1) { return caml_str_repeat(n - 1, s) + s; }
var r = caml_str_repeat(n >> 1, s);
return r + r;
}
function MlString(param) {
if (param != null) {
this.bytes = this.fullBytes = param;
this.last = this.len = param.length;
}
}
MlString.prototype = {
string:null,
bytes:null,
fullBytes:null,
array:null,
len:null,
last:0,
toJsString:function() {
return this.string = decodeURIComponent (escape(this.getFullBytes()));
},
toBytes:function() {
if (this.string != null)
var b = unescape (encodeURIComponent (this.string));
else {
var b = "", a = this.array, l = a.length;
for (var i = 0; i < l; i ++) b += String.fromCharCode (a[i]);
}
this.bytes = this.fullBytes = b;
this.last = this.len = b.length;
return b;
},
getBytes:function() {
var b = this.bytes;
if (b == null) b = this.toBytes();
return b;
},
getFullBytes:function() {
var b = this.fullBytes;
if (b !== null) return b;
b = this.bytes;
if (b == null) b = this.toBytes ();
if (this.last < this.len) {
this.bytes = (b += caml_str_repeat(this.len - this.last, '\0'));
this.last = this.len;
}
this.fullBytes = b;
return b;
},
toArray:function() {
var b = this.bytes;
if (b == null) b = this.toBytes ();
var a = [], l = this.last;
for (var i = 0; i < l; i++) a[i] = b.charCodeAt(i);
for (l = this.len; i < l; i++) a[i] = 0;
this.string = this.bytes = this.fullBytes = null;
this.last = this.len;
this.array = a;
return a;
},
getArray:function() {
var a = this.array;
if (!a) a = this.toArray();
return a;
},
getLen:function() {
var len = this.len;
if (len !== null) return len;
this.toBytes();
return this.len;
},
toString:function() { var s = this.string; return s?s:this.toJsString(); },
valueOf:function() { var s = this.string; return s?s:this.toJsString(); },
blitToArray:function(i1, a2, i2, l) {
var a1 = this.array;
if (a1)
for (var i = 0; i < l; i++) a2 [i2 + i] = a1 [i1 + i];
else {
var b = this.bytes;
if (b == null) b = this.toBytes();
var l1 = this.last - i1;
if (l <= l1)
for (var i = 0; i < l; i++) a2 [i2 + i] = b.charCodeAt(i1 + i);
else {
for (var i = 0; i < l1; i++) a2 [i2 + i] = b.charCodeAt(i1 + i);
for (; i < l; i++) a2 [i2 + i] = 0;
}
}
},
get:function (i) {
var a = this.array;
if (a) return a[i];
var b = this.bytes;
if (b == null) b = this.toBytes();
return (i<this.last)?b.charCodeAt(i):0;
},
safeGet:function (i) {
if (!this.len) this.toBytes();
if ((i < 0) || (i >= this.len)) caml_array_bound_error ();
return this.get(i);
},
set:function (i, c) {
var a = this.array;
if (!a) {
if (this.last == i) {
this.bytes += String.fromCharCode (c & 0xff);
this.last ++;
return 0;
}
a = this.toArray();
} else if (this.bytes != null) {
this.bytes = this.fullBytes = this.string = null;
}
a[i] = c & 0xff;
return 0;
},
safeSet:function (i, c) {
if (this.len == null) this.toBytes ();
if ((i < 0) || (i >= this.len)) caml_array_bound_error ();
this.set(i, c);
},
fill:function (ofs, len, c) {
if (ofs >= this.last && this.last && c == 0) return;
var a = this.array;
if (!a) a = this.toArray();
else if (this.bytes != null) {
this.bytes = this.fullBytes = this.string = null;
}
var l = ofs + len;
for (var i = ofs; i < l; i++) a[i] = c;
},
compare:function (s2) {
if (this.string != null && s2.string != null) {
if (this.string < s2.string) return -1;
if (this.string > s2.string) return 1;
return 0;
}
var b1 = this.getFullBytes ();
var b2 = s2.getFullBytes ();
if (b1 < b2) return -1;
if (b1 > b2) return 1;
return 0;
},
equal:function (s2) {
if (this.string != null && s2.string != null)
return this.string == s2.string;
return this.getFullBytes () == s2.getFullBytes ();
},
lessThan:function (s2) {
if (this.string != null && s2.string != null)
return this.string < s2.string;
return this.getFullBytes () < s2.getFullBytes ();
},
lessEqual:function (s2) {
if (this.string != null && s2.string != null)
return this.string <= s2.string;
return this.getFullBytes () <= s2.getFullBytes ();
}
}
function MlWrappedString (s) { this.string = s; }
MlWrappedString.prototype = new MlString();
function MlMakeString (l) { this.bytes = ""; this.len = l; }
MlMakeString.prototype = new MlString ();
function caml_call_gen(f, args) {
if(f.fun)
return caml_call_gen(f.fun, args);
var n = f.length;
var d = n - args.length;
if (d == 0)
return f.apply(null, args);
else if (d < 0)
return caml_call_gen(f.apply(null, args.slice(0,n)), args.slice(n));
else
return function (x){ return caml_call_gen(f, args.concat([x])); };
}
function caml_parse_format (fmt) {
fmt = fmt.toString ();
var len = fmt.length;
if (len > 31) caml_invalid_argument("format_int: format too long");
var f =
{ justify:'+', signstyle:'-', filler:' ', alternate:false,
base:0, signedconv:false, width:0, uppercase:false,
sign:1, prec:6, conv:'f' };
for (var i = 0; i < len; i++) {
var c = fmt.charAt(i);
switch (c) {
case '-':
f.justify = '-'; break;
case '+': case ' ':
f.signstyle = c; break;
case '0':
f.filler = '0'; break;
case '#':
f.alternate = true; break;
case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
f.width = 0;
while (c=fmt.charCodeAt(i) - 48, c >= 0 && c <= 9) {
f.width = f.width * 10 + c; i++
}
i--;
break;
case '.':
f.prec = 0;
i++;
while (c=fmt.charCodeAt(i) - 48, c >= 0 && c <= 9) {
f.prec = f.prec * 10 + c; i++
}
i--;
case 'd': case 'i':
f.signedconv = true; /* fallthrough */
case 'u':
f.base = 10; break;
case 'x':
f.base = 16; break;
case 'X':
f.base = 16; f.uppercase = true; break;
case 'o':
f.base = 8; break;
case 'e': case 'f': case 'g':
f.signedconv = true; f.conv = c; break;
case 'E': case 'F': case 'G':
f.signedconv = true; f.uppercase = true;
f.conv = c.toLowerCase (); break;
}
}
return f;
}
function caml_finish_formatting(f, rawbuffer) {
if (f.uppercase) rawbuffer = rawbuffer.toUpperCase();
var len = rawbuffer.length;
if (f.signedconv && (f.sign < 0 || f.signstyle != '-')) len++;
if (f.alternate) {
if (f.base == 8) len += 1;
if (f.base == 16) len += 2;
}
var buffer = "";
if (f.justify == '+' && f.filler == ' ')
for (var i = len; i < f.width; i++) buffer += ' ';
if (f.signedconv) {
if (f.sign < 0) buffer += '-';
else if (f.signstyle != '-') buffer += f.signstyle;
}
if (f.alternate && f.base == 8) buffer += '0';
if (f.alternate && f.base == 16) buffer += "0x";
if (f.justify == '+' && f.filler == '0')
for (var i = len; i < f.width; i++) buffer += '0';
buffer += rawbuffer;
if (f.justify == '-')
for (var i = len; i < f.width; i++) buffer += ' ';
return new MlWrappedString (buffer);
}
function caml_format_int(fmt, i) {
if (fmt.toString() == "%d") return new MlWrappedString(""+i);
var f = caml_parse_format(fmt);
if (i < 0) { if (f.signedconv) { f.sign = -1; i = -i; } else i >>>= 0; }
var s = i.toString(f.base);
return caml_finish_formatting(f, s);
}
function caml_js_wrap_callback(f) {
var toArray = Array.prototype.slice;
return function () {
var args = (arguments.length > 0)?toArray.call (arguments):[undefined];
return caml_call_gen(f, args);
}
}
function caml_ml_out_channels_list () { return 0; }
var caml_global_data = [0];
function caml_register_global (n, v) { caml_global_data[n + 1] = v; }
var caml_named_values = {};
function caml_register_named_value(nm,v) {
caml_named_values[nm] = v; return 0;
}
(function(){function y(M,N){return M.length==1?M(N):caml_call_gen(M,[N]);}caml_register_global(5,[0,new MlString("Division_by_zero")]);caml_register_global(3,[0,new MlString("Invalid_argument")]);caml_register_global(2,[0,new MlString("Failure")]);var l=[0,new MlString("Assert_failure")],k=new MlString("%d"),j=new MlString("Pervasives.do_at_exit"),i=[0,new MlString("test.ml"),8,17],h=new MlString("main"),g=new MlString("Heyyo\n\n"),f=new MlString("Heyyooo");function e(d){var a=caml_ml_out_channels_list(0);for(;;){if(a){var b=a[2];try {}catch(c){}var a=b;continue;}return 0;}}caml_register_named_value(j,e);var m=[0,0],n=undefined,o=false,r=null,q=Array;m[1]=[0,function(p){return p instanceof q?0:[0,new MlWrappedString(p.toString())];},m[1]];function u(s,t){s.appendChild(t);return 0;}function C(x){return caml_js_wrap_callback(function(v){if(v===n){var w=event,z=y(x,w);w.returnValue=z;var A=z;}else{var B=y(x,v);if(!(B|0))v.preventDefault();var A=B;}return A;});}var D=window;window.HTMLElement===n;var E=D.document;D.onload=C(function(L){var F=E.getElementById(h.toString());if(F==r)throw [0,l,i];var G=E.createTextNode(g.toString());u(F,G);var H=[0,0],I=[0,G];E.title=f.toString();E.onkeypress=C(function(K){var J=E.createTextNode(caml_format_int(k,H[1]).toString());H[1]+=1;F.removeChild(I[1]);u(F,J);I[1]=J;return o;});return o;});e(0);return;}());