-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsole.js
74 lines (67 loc) · 1.81 KB
/
console.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
require(['atum/interpret',
'atum/compute',
'atum/compute/context',
'atum/builtin/impl/global',
'atum/builtin/operations/global',
'atum/operations/evaluation',
'atum/semantics/semantics',
'ecma/parse/parser'],
function(interpret,
compute,
context,
global,
global_operations,
evaluation) {
/*
******************************************************************************/
var out = {
'write': function(x, ctx) {
$('#output-console').append("<li class='output-value'>" +
x +
"</li>");
}
};
var errorOut = {
'write': function(x, ctx) {
$('#output-console').append("<li class='output-value output-error'>" +
x +
"</li>");
}
};
var run = function (input, ok, err) {
console.profile();
return interpret.exec(
evaluation.evaluateText(input),
globalCtx,
function(x, ctx) {
console.profileEnd();
return ok(x, ctx);
},
function(x, ctx) {
console.profileEnd();
return err(x, ctx);
},
err);
};
/* Code Mirror
******************************************************************************/
var doc = CodeMirror(document.getElementById('input'), {
'mode': 'javascript',
'lineNumbers': true
}).doc;
/*
******************************************************************************/
var globalCtx = interpret.exec(
compute.sequence(
global.initialize(),
global_operations.enterGlobal(),
compute.computeContext),
context.ComputeContext.empty,
function(x) { return x },
function(x) { return x });
$(function(){
$('button#eval-button').on('click', function(e){
run(doc.getValue(), out.write, errorOut.write);
});
});
});