-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepl.js
More file actions
37 lines (29 loc) · 952 Bytes
/
repl.js
File metadata and controls
37 lines (29 loc) · 952 Bytes
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
var util = require('util'),
salliedforth = require('./tests/js/salliedforth.js');
var forthInt = new salliedforth.Interpreter( this );
process.stdin.setEncoding('utf8');
var inspectOptions = {
colors: true
};
process.stdout.write('\nsalliedforth.js - v: ' + forthInt.versionString + '\n');
process.stdout.write('https://github.com/jococo/sallied-forth\n\n');
process.stdout.write('OK.\n> ');
process.stdin.on('readable', function() {
var chunk = process.stdin.read();
if (chunk !== null) {
var result;
try {
result = forthInt.interpret(chunk);
if(result.data && (result.data.length > 0)) {
process.stdout.write("" + util.inspect(result.data, inspectOptions) + '\n');
}
process.stdout.write('OK.\n> ');
} catch( err) {
process.stderr.write('!! ' + err + '\n');
process.stdout.write('OK.\n> ');
}
}
});
process.stdin.on('end', function() {
process.stdout.write('end');
});