This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
events.js
120 lines (101 loc) · 2.59 KB
/
events.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
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
'use strict';
let nextEventId = 0;
class Event {
constructor(sourceLoc, env) {
this.id = nextEventId++;
this.sourceLoc = sourceLoc;
this.env = env;
this.children = [];
}
toMicroVizString() {
throw new Error('abstract method!');
}
_valueString(v) {
if (typeof v === 'function') {
return '{function}';
} else if (v === undefined) {
return 'undefined';
} else {
return JSON.stringify(v);
}
}
subsumes(that) {
return false;
}
}
class ProgramEvent extends Event {
constructor(sourceLoc) {
super(sourceLoc, null);
// also: activationEnv
}
}
class SendEvent extends Event {
constructor(sourceLoc, env, recv, selector, args) {
super(sourceLoc, env);
this.recv = recv;
this.selector = selector;
this.args = args;
// also: activationEnv, returnValue
}
}
class VarDeclEvent extends Event {
constructor(sourceLoc, env, name, value) {
super(sourceLoc, env);
this.name = name;
this.value = value;
}
toMicroVizString() {
return this.name + ' = ' + this._valueString(this.value);
}
}
class VarAssignmentEvent extends Event {
constructor(sourceLoc, env, declEnv, name, value) {
super(sourceLoc, env);
this.declEnv = declEnv;
this.name = name;
this.value = value;
}
subsumes(that) {
return (that instanceof VarAssignmentEvent || that instanceof VarDeclEvent) &&
this.name === that.name && this.declEnv === that.declEnv;
}
toMicroVizString() {
return this.name + ' = ' + this._valueString(this.value);
}
}
class InstVarAssignmentEvent extends Event {
constructor(sourceLoc, env, obj, name, value) {
super(sourceLoc, env);
this.obj = obj;
this.name = name;
this.value = value;
}
subsumes(that) {
return that instanceof InstVarAssignmentEvent &&
this.receiver === that.receiver && this.name === that.name;
}
toMicroVizString() {
return this._valueString(this.obj) + '.' + this.name + ' = ' + this._valueString(this.value);
}
}
class InstantiationEvent extends Event {
// TODO: how should we handle the call to init?
constructor(sourceLoc, env, _class, args, newInstance) {
super(sourceLoc, env);
this.class = _class;
this.args = args;
this.newInstance = newInstance;
}
toMicroVizString() {
return 'new ' + this._valueString(this.class) + ' -> ' + this._valueString(this.newInstance);
}
}
class ReturnEvent extends Event {
constructor(sourceLoc, env, value) {
super(sourceLoc, env);
this.value = value;
}
toMicroVizString() {
return 'return ' + this._valueString(this.value);
}
}