-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtrampolined-evaluator.mjs
68 lines (58 loc) · 2.32 KB
/
trampolined-evaluator.mjs
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
import {ArraySet, HashMap, HashCode, Sets, Formatter, assert, assertDefinedNotNull, assertFalse} from './common.mjs';
export function createEvaluator(semantics)
{
const machine =
{
evaluate: (exp, benv, store, lkont, kont) => () => semantics.evaluate(exp, benv, store, lkont, kont, machine),
continue: (value, store, lkont, kont) => () => semantics.continue(value, store, lkont, kont, machine),
return: (value, store, lkont, kont) => () => semantics.return(value, store, lkont, kont, machine),
throw: (value, store, lkont, kont) => () => semantics.throw(value, store, lkont, kont, machine),
break: (store, lkont, kont) => () => semantics.break(store, lkont, kont, machine)
}
function evaluate_(exp, benv, store, lkont, kont)
{
let next = semantics.evaluate(exp, benv, store, lkont, kont, machine);
while (next.length > 0)
{
next = next.flatMap(f => f());
}
return result;
}
function continue_(value, store, lkont, kont)
{
let next = semantics.continue(value, store, lkont, kont, machine);
while (next.length > 0)
{
next = next.flatMap(f => f());
}
return result;
}
return {evaluate: evaluate_, continue: continue_};
}
function computeInitialCeskState(semantics, ...srcs)
{
const result = semantics.initialize(null,
{
continue: function (value, store, lkont, kont)
{
store = srcs.reduce((store, src) => semantics.enqueueScriptEvaluation(src, store), store);
const evaluator = createEvaluator(semantics, {errors:true, hardAsserts:true});
evaluator.continue(value, store, lkont, kont);
return {};
}
});
return new KontState(this.value, store, this.lkont, this.kont);
let s1 = srcs.reduce((state, src) => state.enqueueScriptEvaluation(src), s0);
const prelSystem = performExplore([s1]);
console.log("prelude time: " + prelSystem.time + " states " + prelSystem.states.length);
const prelResult = prelSystem.result;
if (prelResult.size !== 1) // maybe check this in a dedicated concExplore?
{
throw new Error("wrong number of prelude results: " + prelResult.size);
}
const prelState = [...prelResult][0];
const store = [...prelResult][0].store;
const kont = [...prelResult][0].kont;
const ceskState = {store, kont};
return ceskState;
}