Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50663 views
1
// Generated by CoffeeScript 1.12.6
2
(function() {
3
var Scope,
4
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
5
6
exports.Scope = Scope = (function() {
7
function Scope(parent, expressions, method, referencedVars) {
8
var ref, ref1;
9
this.parent = parent;
10
this.expressions = expressions;
11
this.method = method;
12
this.referencedVars = referencedVars;
13
this.variables = [
14
{
15
name: 'arguments',
16
type: 'arguments'
17
}
18
];
19
this.positions = {};
20
if (!this.parent) {
21
this.utilities = {};
22
}
23
this.root = (ref = (ref1 = this.parent) != null ? ref1.root : void 0) != null ? ref : this;
24
}
25
26
Scope.prototype.add = function(name, type, immediate) {
27
if (this.shared && !immediate) {
28
return this.parent.add(name, type, immediate);
29
}
30
if (Object.prototype.hasOwnProperty.call(this.positions, name)) {
31
return this.variables[this.positions[name]].type = type;
32
} else {
33
return this.positions[name] = this.variables.push({
34
name: name,
35
type: type
36
}) - 1;
37
}
38
};
39
40
Scope.prototype.namedMethod = function() {
41
var ref;
42
if (((ref = this.method) != null ? ref.name : void 0) || !this.parent) {
43
return this.method;
44
}
45
return this.parent.namedMethod();
46
};
47
48
Scope.prototype.find = function(name, type) {
49
if (type == null) {
50
type = 'var';
51
}
52
if (this.check(name)) {
53
return true;
54
}
55
this.add(name, type);
56
return false;
57
};
58
59
Scope.prototype.parameter = function(name) {
60
if (this.shared && this.parent.check(name, true)) {
61
return;
62
}
63
return this.add(name, 'param');
64
};
65
66
Scope.prototype.check = function(name) {
67
var ref;
68
return !!(this.type(name) || ((ref = this.parent) != null ? ref.check(name) : void 0));
69
};
70
71
Scope.prototype.temporary = function(name, index, single) {
72
var diff, endCode, letter, newCode, num, startCode;
73
if (single == null) {
74
single = false;
75
}
76
if (single) {
77
startCode = name.charCodeAt(0);
78
endCode = 'z'.charCodeAt(0);
79
diff = endCode - startCode;
80
newCode = startCode + index % (diff + 1);
81
letter = String.fromCharCode(newCode);
82
num = Math.floor(index / (diff + 1));
83
return "" + letter + (num || '');
84
} else {
85
return "" + name + (index || '');
86
}
87
};
88
89
Scope.prototype.type = function(name) {
90
var i, len, ref, v;
91
ref = this.variables;
92
for (i = 0, len = ref.length; i < len; i++) {
93
v = ref[i];
94
if (v.name === name) {
95
return v.type;
96
}
97
}
98
return null;
99
};
100
101
Scope.prototype.freeVariable = function(name, options) {
102
var index, ref, temp;
103
if (options == null) {
104
options = {};
105
}
106
index = 0;
107
while (true) {
108
temp = this.temporary(name, index, options.single);
109
if (!(this.check(temp) || indexOf.call(this.root.referencedVars, temp) >= 0)) {
110
break;
111
}
112
index++;
113
}
114
if ((ref = options.reserve) != null ? ref : true) {
115
this.add(temp, 'var', true);
116
}
117
return temp;
118
};
119
120
Scope.prototype.assign = function(name, value) {
121
this.add(name, {
122
value: value,
123
assigned: true
124
}, true);
125
return this.hasAssignments = true;
126
};
127
128
Scope.prototype.hasDeclarations = function() {
129
return !!this.declaredVariables().length;
130
};
131
132
Scope.prototype.declaredVariables = function() {
133
var v;
134
return ((function() {
135
var i, len, ref, results;
136
ref = this.variables;
137
results = [];
138
for (i = 0, len = ref.length; i < len; i++) {
139
v = ref[i];
140
if (v.type === 'var') {
141
results.push(v.name);
142
}
143
}
144
return results;
145
}).call(this)).sort();
146
};
147
148
Scope.prototype.assignedVariables = function() {
149
var i, len, ref, results, v;
150
ref = this.variables;
151
results = [];
152
for (i = 0, len = ref.length; i < len; i++) {
153
v = ref[i];
154
if (v.type.assigned) {
155
results.push(v.name + " = " + v.type.value);
156
}
157
}
158
return results;
159
};
160
161
return Scope;
162
163
})();
164
165
}).call(this);
166
167