forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_io.js
82 lines (70 loc) · 1.81 KB
/
caml_io.js
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
'use strict';
var stdout = {
buffer: "",
output: (function (param, s) {
var v = s.length - 1 | 0;
if (((typeof process !== "undefined") && process.stdout && process.stdout.write)) {
return process.stdout.write(s);
} else {
if (s[v] === "\n") {
console.log(s.slice(0, v));
} else {
console.log(s);
}
return ;
}
})
};
var stderr = {
buffer: "",
output: (function (param, s) {
var v = s.length - 1 | 0;
if (s[v] === "\n") {
console.log(s.slice(0, v));
} else {
console.log(s);
}
})
};
function caml_ml_flush(oc) {
if (oc.buffer !== "") {
oc.output(oc, oc.buffer);
oc.buffer = "";
return ;
}
}
function caml_ml_output(oc, str, offset, len) {
var str$1 = offset === 0 && len === str.length ? str : str.slice(offset, len);
if (((typeof process !== "undefined") && process.stdout && process.stdout.write) && oc === stdout) {
return process.stdout.write(str$1);
}
var id = str$1.lastIndexOf("\n");
if (id < 0) {
oc.buffer = oc.buffer + str$1;
} else {
oc.buffer = oc.buffer + str$1.slice(0, id + 1 | 0);
caml_ml_flush(oc);
oc.buffer = oc.buffer + str$1.slice(id + 1 | 0);
}
}
function caml_ml_output_char(oc, $$char) {
return caml_ml_output(oc, String.fromCharCode($$char), 0, 1);
}
function caml_ml_out_channels_list(param) {
return {
hd: stdout,
tl: {
hd: stderr,
tl: /* [] */0
}
};
}
var stdin;
exports.stdin = stdin;
exports.stdout = stdout;
exports.stderr = stderr;
exports.caml_ml_flush = caml_ml_flush;
exports.caml_ml_output = caml_ml_output;
exports.caml_ml_output_char = caml_ml_output_char;
exports.caml_ml_out_channels_list = caml_ml_out_channels_list;
/* No side effect */