-
Notifications
You must be signed in to change notification settings - Fork 1
/
scope.js
48 lines (48 loc) · 1.35 KB
/
scope.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
let types = {};
let funcs = {};
module.exports = class Scope {
get(name, isTS = false) {
if (types['__ctord_' + name] && isTS) return '__ctord_' + name;
if (types[name]) return name;
if (this.scope[name]) return this.scope[name];
if (this.upstream == null) return 'undefined';
return this.upstream.get(name);
}
creat(name, type) {
this.scope[name] = type;
}
force(name, type) {
if (this.scope[name]) {
this.scope[name] = type;
this.ik(name, type);
return;
}
if (this.upstream == null) return;
this.upstream.force(name, type);
}
ik(name, type) {
if (this.ikdict[name]) {
this.scope[name] = type;
this.ikdict[name](type);
}
if (this.upstream == null) return;
this.upstream.ik(name, type);
}
creatTBI(name, ik) {
this.scope[name] = 'unk';
this.ikdict[name] = ik;
}
constructor() {
this.scope = Object.create(null);
this.ikdict = {};
this.upstream = null;
}
createDownstream() {
let s = new Scope();
s.upstream = this;
return s;
}
};
module.exports.globalScope = new module.exports();
module.exports.types = types;
module.exports.funcs = funcs;