-
Notifications
You must be signed in to change notification settings - Fork 8
/
name.sml
319 lines (273 loc) · 12.3 KB
/
name.sml
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
(*
* The following licensing terms and conditions apply and must be
* accepted in order to use the Reference Implementation:
*
* 1. This Reference Implementation is made available to all
* interested persons on the same terms as Ecma makes available its
* standards and technical reports, as set forth at
* http://www.ecma-international.org/publications/.
*
* 2. All liability and responsibility for any use of this Reference
* Implementation rests with the user, and not with any of the parties
* who contribute to, or who own or hold any copyright in, this Reference
* Implementation.
*
* 3. THIS REFERENCE IMPLEMENTATION IS PROVIDED BY THE COPYRIGHT
* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* End of Terms and Conditions
*
* Copyright (c) 2007 Adobe Systems Inc., The Mozilla Foundation, Opera
* Software ASA, and others.
*)
structure Name = struct
val (anonNsCounter:int ref) = ref 0
fun newAnonNS _ =
(* safe: will raise Overflow when we run out of namespaces. *)
(anonNsCounter := (!anonNsCounter) + 1;
(Ast.AnonUserNamespace (!anonNsCounter)))
val metaNS = newAnonNS ()
val magicNS = newAnonNS ()
val informativeNS = newAnonNS ()
val noNS = Ast.Public (Ustring.empty)
val intrinsicNS = Ast.Intrinsic
(*
* FIXME: mangling a name into a string is bad form. We really want to
* have derived namespaces like Private and Protected refer to their
* containing namespace-qualified name of their containing class, rather
* than the mangled form of their containing class.
*)
fun mangle (n:Ast.NAME) : Ast.IDENT =
Ustring.fromString (LogErr.name n)
fun make (id:Ast.IDENT) (ns:Ast.NAMESPACE) : Ast.NAME = { id = id, ns = ns }
fun meta (id:Ast.IDENT) : Ast.NAME = { id = id, ns = metaNS }
fun informative (id:Ast.IDENT) : Ast.NAME = { id = id, ns = informativeNS }
fun magic (id:Ast.IDENT) : Ast.NAME = { id = id, ns = magicNS }
fun intrinsic (id:Ast.IDENT) : Ast.NAME = { id = id, ns = intrinsicNS }
fun nons (id:Ast.IDENT) : Ast.NAME = { id = id, ns = noNS }
fun public (cls:Ast.NAME) (id:Ast.IDENT) : Ast.NAME = { id = id, ns = Ast.Public (mangle cls) }
fun private (cls:Ast.NAME) (id:Ast.IDENT) : Ast.NAME = { id = id, ns = Ast.Private (mangle cls) }
(*
* To reference a name as a type expression, you need
* a complicated structure.
*)
fun typename (n:Ast.NAME) =
Ast.TypeName (Ast.QualifiedIdentifier
{ ident = (#id n),
qual = Ast.LiteralExpr
(Ast.LiteralNamespace (#ns n)) })
(*
* Names that are supposed to be present in the global scope
* once we finish booting.
*)
(* From Type.es *)
val intrinsic_Type = intrinsic Ustring.Type_
(* From Interface.es *)
val intrinsic_Interface = intrinsic Ustring.Interface_
(* From Class.es *)
val intrinsic_Class = intrinsic Ustring.Class_
(* From Namespace.es *)
val intrinsic_Namespace = intrinsic Ustring.Namespace_
(* From Name.es *)
val intrinsic_Name = intrinsic Ustring.Name_
val nons_qualifier = nons Ustring.qualifier_
val nons_identifier = nons Ustring.identifier_
(* From Object.es *)
val nons_Object = nons Ustring.Object_
(* From Error.es *)
val nons_Error = nons Ustring.Error_
val nons_EvalError = nons Ustring.EvalError_
val nons_RangeError = nons Ustring.RangeError_
val nons_ReferenceError = nons Ustring.ReferenceError_
val nons_SyntaxError = nons Ustring.SyntaxError_
val nons_TypeError = nons Ustring.TypeError_
(* From Conversions.es *)
val intrinsic_ToPrimitive = intrinsic Ustring.ToPrimitive_
val intrinsic_ToBoolean = intrinsic Ustring.ToBoolean_
val intrinsic_ToInteger = intrinsic Ustring.ToInteger_
val intrinsic_ToInt = intrinsic Ustring.ToInt_
val intrinsic_ToUint = intrinsic Ustring.ToUint_
val intrinsic_ToDouble = intrinsic Ustring.ToDouble_
val intrinsic_ToDecimal = intrinsic Ustring.ToDecimal_
val intrinsic_ToString = intrinsic Ustring.ToString_
val intrinsic_ToObject = intrinsic Ustring.ToObject_
val intrinsic_ToNumeric = intrinsic Ustring.ToNumeric_
(* From Global.es *)
val intrinsic_NaN = intrinsic Ustring.NaN_
val intrinsic_Infinity = intrinsic Ustring.Infinity_
val intrinsic_undefined = intrinsic Ustring.undefined_
val intrinsic_eval = intrinsic Ustring.eval_
val intrinsic_parseInt = intrinsic Ustring.parseInt_
val intrinsic_parseFloat = intrinsic Ustring.parseFloat_
val intrinsic_isNaN = intrinsic Ustring.isNaN_
val intrinsic_isFinite = intrinsic Ustring.isFinite_
val intrinsic_decodeURI = intrinsic Ustring.decodeURI_
val intrinsic_decodeURIComponent = intrinsic Ustring.decodeURIComponent_
val intrinsic_encodeURI = intrinsic Ustring.encodeURI_
val intrinsic_encodeURIComponent = intrinsic Ustring.encodeURIComponent_
val nons_NaN = nons Ustring.NaN_
val nons_Infinity = nons Ustring.Infinity_
val nons_undefined = nons Ustring.undefined_
val nons_eval = nons Ustring.eval_
val nons_parseInt = nons Ustring.parseInt_
val nons_parseFloat = nons Ustring.parseFloat_
val nons_isNaN = nons Ustring.isNaN_
val nons_isFinite = nons Ustring.isFinite_
val nons_decodeURI = nons Ustring.decodeURI_
val nons_decodeURIComponent = nons Ustring.decodeURIComponent_
val nons_encodeURI = nons Ustring.encodeURI_
val nons_encodeURIComponent = nons Ustring.encodeURIComponent_
val intrinsic_print = intrinsic Ustring.print_
val intrinsic_load = intrinsic Ustring.load_
val intrinsic_assert = intrinsic Ustring.assert_
val intrinsic_typename = intrinsic Ustring.typename_
val intrinsic_readFile = intrinsic Ustring.readFile_
val intrinsic_beginBytes = intrinsic Ustring.beginBytes_
val intrinsic_pushByte = intrinsic Ustring.pushByte_
val intrinsic_writeBytes = intrinsic Ustring.writeBytes_
val intrinsic_writeFile = intrinsic Ustring.writeFile_
val intrinsic_explodeDouble = intrinsic Ustring.explodeDouble_
(* From Function.es *)
val nons_Function = nons Ustring.Function_
(* From Boolean.es *)
val nons_Boolean = nons Ustring.Boolean_
(* From boolean_primitive.es *)
val intrinsic_boolean = intrinsic Ustring.boolean_
(* From Number.es *)
val nons_Number = nons Ustring.Number_
(* From double.es *)
val intrinsic_double = intrinsic Ustring.double_
(* From int.es *)
val intrinsic_int = intrinsic Ustring.int_
(* From uint.es *)
val intrinsic_uint = intrinsic Ustring.uint_
(* From decimal.es *)
val intrinsic_decimal = intrinsic Ustring.decimal_
(* From Numeric.es *)
val intrinsic_Numeric = intrinsic Ustring.Numeric_
(* From String.es *)
val nons_String = nons Ustring.String_
(* From string_primitive.es *)
val intrinsic_string = intrinsic Ustring.string_
(* From Array.es *)
val nons_Array = nons Ustring.Array_
(* From ByteArray.es *)
val intrinsic_ByteArray = intrinsic Ustring.ByteArray_
(* From Date.es *)
val nons_Date = nons Ustring.Date_
(* From RegExp.es *)
val nons_RegExp = nons Ustring.RegExp_
(* From JSON.es *)
val JSON_emit = { ns = Ast.Public Ustring.JSON_, id = Ustring.emit_ }
val JSON_parse = { ns = Ast.Public Ustring.JSON_, id = Ustring.parse_ }
(*
* Natives
*)
val intrinsic_proto = intrinsic Ustring.proto_
val intrinsic_dumpFunc = intrinsic Ustring.dumpFunc_
val intrinsic_inspect = intrinsic Ustring.inspect_
val intrinsic_random = intrinsic Ustring.random_
val informative_acosDouble = informative Ustring.acosDouble_
val informative_acosDecimal = informative Ustring.acosDecimal_
val informative_asinDouble = informative Ustring.asinDouble_
val informative_asinDecimal = informative Ustring.asinDecimal_
val informative_atanDouble = informative Ustring.atanDouble_
val informative_atanDecimal = informative Ustring.atanDecimal_
val informative_atan2Double = informative Ustring.atan2Double_
val informative_atan2Decimal = informative Ustring.atan2Decimal_
val informative_ceilDouble = informative Ustring.ceilDouble_
val informative_ceilDecimal = informative Ustring.ceilDecimal_
val informative_cosDouble = informative Ustring.cosDouble_
val informative_cosDecimal = informative Ustring.cosDecimal_
val informative_expDouble = informative Ustring.expDouble_
val informative_expDecimal = informative Ustring.expDecimal_
val informative_floorDouble = informative Ustring.floorDouble_
val informative_floorDecimal = informative Ustring.floorDecimal_
val informative_logDouble = informative Ustring.logDouble_
val informative_logDecimal = informative Ustring.logDecimal_
val informative_powDouble = informative Ustring.powDouble_
val informative_powDecimal = informative Ustring.powDecimal_
val informative_roundDouble = informative Ustring.roundDouble_
val informative_roundDecimal = informative Ustring.roundDecimal_
val informative_sinDouble = informative Ustring.sinDouble_
val informative_sinDecimal = informative Ustring.sinDecimal_
val informative_sqrtDouble = informative Ustring.sqrtDouble_
val informative_sqrtDecimal = informative Ustring.sqrtDecimal_
val informative_tanDouble = informative Ustring.tanDouble_
val informative_tanDecimal = informative Ustring.tanDecimal_
val intrinsic_now = intrinsic Ustring.now_
val intrinsic_toPrecision = intrinsic Ustring.toPrecision_
val intrinsic_toExponential = intrinsic Ustring.toExponential_
val intrinsic_toFixedStep10 = intrinsic Ustring.toFixedStep10_
val intrinsic_set = intrinsic Ustring.set_
val intrinsic_get = intrinsic Ustring.get_
val nons_DaylightSavingsTA = nons Ustring.DaylightSavingsTA_
val nons_LocalTZA = nons Ustring.LocalTZA_
val magic_setByteArrayByte = magic Ustring.setByteArrayByte_
val magic_getByteArrayByte = magic Ustring.getByteArrayByte_
val magic_stringAppend = magic Ustring.stringAppend_
val magic_stringLength = magic Ustring.stringLength_
val magic_fromCharCode = magic Ustring.fromCharCode_
val magic_charCodeAt = magic Ustring.charCodeAt_
val magic_fnLength = magic Ustring.fnLength_
val magic_apply = magic Ustring.apply_
val magic_bindString = magic Ustring.bindString_
val magic_bindBoolean = magic Ustring.bindBoolean_
val magic_bindDecimal = magic Ustring.bindDecimal_
val magic_bindDouble = magic Ustring.bindDouble_
val magic_bindUInt = magic Ustring.bindUInt_
val magic_bindInt = magic Ustring.bindInt_
val magic_newString = magic Ustring.newString_
val magic_newBoolean = magic Ustring.newBoolean_
val magic_newInt = magic Ustring.newInt_
val magic_newUInt = magic Ustring.newUInt_
val magic_newDouble = magic Ustring.newDouble_
val magic_toPrimitive = magic Ustring.toPrimitive_
val magic_isPrimitive = magic Ustring.isPrimitive_
val magic_defaultValue = magic Ustring.defaultValue_
val magic_setPropertyIsDontEnum = magic Ustring.setPropertyIsDontEnum_
val magic_getPropertyIsDontDelete = magic Ustring.getPropertyIsDontDelete_
val magic_getPropertyIsDontEnum = magic Ustring.getPropertyIsDontEnum_
val magic_hasOwnProperty = magic Ustring.hasOwnProperty_
val magic_getPrototype = magic Ustring.getPrototype_
val magic_getSuperClass = magic Ustring.getSuperClass_
val magic_getSuperInterface = magic Ustring.getSuperInterface_
val magic_getImplementedInterface = magic Ustring.getImplementedInterface_
val magic_getClassOfObject = magic Ustring.getClassOfObject_
val magic_getClassName = magic Ustring.getClassName_
val magic_construct = magic Ustring.construct_
(*
* Property names that have special meanings to the interpreter.
*)
val nons_constructor = nons Ustring.constructor_
val nons_length = nons Ustring.length_
val nons_cursor = nons Ustring.cursor_
val private_Array__length = private nons_Array (Ustring.fromString "_length")
val nons_source = nons Ustring.source_
val nons_prototype = nons Ustring.prototype_
val nons_toString = nons Ustring.toString_
val nons_valueOf = nons Ustring.valueOf_
val nons_global = nons Ustring.global_
val meta_invoke = meta Ustring.invoke_
val meta_get = meta Ustring.get_
val meta_set = meta Ustring.set_
val meta_has = meta Ustring.has_
val meta_call = meta Ustring.call_
val meta_convert = meta Ustring.convert_
val this = nons Ustring.this_
val arguments = nons Ustring.arguments_
val empty = nons Ustring.empty
val meta_ = nons Ustring.meta_
val magic_ = nons Ustring.magic_
val informative_ = nons Ustring.informative_
end