opal 0.3.10 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +47 -46
- data/lib/opal.rb +11 -3
- data/lib/opal/builder.rb +4 -46
- data/lib/opal/bundle.rb +11 -25
- data/lib/opal/command.rb +101 -22
- data/lib/opal/context.rb +16 -50
- data/lib/opal/lexer.rb +21 -2
- data/lib/opal/nodes.rb +134 -20
- data/lib/opal/parser.rb +7 -7
- data/lib/opal/parser.y +7 -7
- data/lib/opal/rake/bundle_task.rb +24 -23
- data/lib/opal/version.rb +3 -0
- data/opal-parser.js +8343 -0
- data/opal.js +5685 -0
- data/stdlib/dev.rb +6 -4
- data/templates/init/Rakefile +7 -0
- data/templates/init/index.html +17 -0
- data/templates/init/lib/__NAME__.rb +2 -0
- metadata +9 -32
- data/corelib/array.rb +0 -1424
- data/corelib/boolean.rb +0 -20
- data/corelib/class.rb +0 -58
- data/corelib/core.rb +0 -66
- data/corelib/dir.rb +0 -22
- data/corelib/enumerable.rb +0 -33
- data/corelib/error.rb +0 -19
- data/corelib/file.rb +0 -60
- data/corelib/hash.rb +0 -729
- data/corelib/kernel.rb +0 -251
- data/corelib/load_order +0 -21
- data/corelib/match_data.rb +0 -33
- data/corelib/module.rb +0 -101
- data/corelib/nil_class.rb +0 -54
- data/corelib/numeric.rb +0 -352
- data/corelib/object.rb +0 -37
- data/corelib/proc.rb +0 -55
- data/corelib/range.rb +0 -27
- data/corelib/regexp.rb +0 -69
- data/corelib/string.rb +0 -300
- data/corelib/top_self.rb +0 -8
- data/runtime/class.js +0 -386
- data/runtime/fs.js +0 -199
- data/runtime/init.js +0 -556
- data/runtime/loader.js +0 -330
- data/runtime/module.js +0 -103
- data/runtime/post.js +0 -10
- data/runtime/pre.js +0 -7
- data/runtime/runtime.js +0 -345
data/runtime/runtime.js
DELETED
@@ -1,345 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
All methods and properties available to ruby/js sources at runtime. These
|
3
|
-
are kept in their own namespace to keep the opal namespace clean.
|
4
|
-
*/
|
5
|
-
var Rt = Op.runtime = {};
|
6
|
-
|
7
|
-
Rt.opal = Op;
|
8
|
-
|
9
|
-
/**
|
10
|
-
Opal platform - this is overriden in gem context and nodejs context. These
|
11
|
-
are the default values used in the browser, `opal-browser'.
|
12
|
-
*/
|
13
|
-
var PLATFORM_PLATFORM = "opal";
|
14
|
-
var PLATFORM_ENGINE = "opal-browser";
|
15
|
-
var PLATFORM_VERSION = "1.9.2";
|
16
|
-
var PLATFORM_ARGV = [];
|
17
|
-
|
18
|
-
// Minimize js types
|
19
|
-
var ArrayProto = Array.prototype,
|
20
|
-
ObjectProto = Object.prototype,
|
21
|
-
|
22
|
-
ArraySlice = ArrayProto.slice,
|
23
|
-
|
24
|
-
hasOwnProperty = ObjectProto.hasOwnProperty;
|
25
|
-
|
26
|
-
/**
|
27
|
-
Core runtime classes, objects and literals.
|
28
|
-
*/
|
29
|
-
var rb_cBasirb_cObject, rb_cObject, rb_cModule, rb_cClass,
|
30
|
-
rb_mKernel, rb_cNilClass, rb_cBoolean,
|
31
|
-
rb_cArray, rb_cNumeric,
|
32
|
-
rb_cRegexp, rb_cMatch, rb_top_self, Qnil,
|
33
|
-
|
34
|
-
rb_cDir;
|
35
|
-
|
36
|
-
/**
|
37
|
-
Core object type flags. Added as local variables, and onto runtime.
|
38
|
-
*/
|
39
|
-
var T_CLASS = 1,
|
40
|
-
T_MODULE = 2,
|
41
|
-
T_OBJECT = 4,
|
42
|
-
T_BOOLEAN = 8,
|
43
|
-
T_STRING = 16,
|
44
|
-
T_ARRAY = 32,
|
45
|
-
T_NUMBER = 64,
|
46
|
-
T_PROC = 128,
|
47
|
-
T_SYMBOL = 256,
|
48
|
-
T_HASH = 512,
|
49
|
-
T_RANGE = 1024,
|
50
|
-
T_ICLASS = 2056,
|
51
|
-
FL_SINGLETON = 4112;
|
52
|
-
|
53
|
-
/**
|
54
|
-
Define classes. This is the public API for defining classes, shift classes
|
55
|
-
and modules.
|
56
|
-
|
57
|
-
@param {RubyObject} base
|
58
|
-
@param {RClass} super_class
|
59
|
-
@param {String} id
|
60
|
-
@param {Function} body
|
61
|
-
@param {Number} flag
|
62
|
-
*/
|
63
|
-
Rt.dc = function(base, super_class, id, body, flag) {
|
64
|
-
var klass;
|
65
|
-
|
66
|
-
switch (flag) {
|
67
|
-
case 0:
|
68
|
-
if (base.$f & T_OBJECT) {
|
69
|
-
base = rb_class_real(base.$k);
|
70
|
-
}
|
71
|
-
|
72
|
-
if (super_class == Qnil) {
|
73
|
-
super_class = rb_cObject;
|
74
|
-
}
|
75
|
-
|
76
|
-
klass = rb_define_class_under(base, id, super_class);
|
77
|
-
break;
|
78
|
-
|
79
|
-
case 1:
|
80
|
-
klass = rb_singleton_class(base);
|
81
|
-
break;
|
82
|
-
|
83
|
-
case 2:
|
84
|
-
if (base.$f & T_OBJECT) {
|
85
|
-
base = rb_class_real(base.$k);
|
86
|
-
}
|
87
|
-
klass = rb_define_module_under(base, id);
|
88
|
-
break;
|
89
|
-
|
90
|
-
default:
|
91
|
-
rb_raise(rb_eException, "define_class got a unknown flag " + flag);
|
92
|
-
}
|
93
|
-
|
94
|
-
var res = body(klass);
|
95
|
-
|
96
|
-
return res;
|
97
|
-
};
|
98
|
-
|
99
|
-
/**
|
100
|
-
Regexp object. This holds the results of last regexp match.
|
101
|
-
X for regeXp.
|
102
|
-
*/
|
103
|
-
Rt.X = null;
|
104
|
-
|
105
|
-
/**
|
106
|
-
Undefine methods
|
107
|
-
*/
|
108
|
-
Rt.um = function(kls) {
|
109
|
-
var args = [].slice.call(arguments, 1);
|
110
|
-
|
111
|
-
for (var i = 0, ii = args.length; i < ii; i++) {
|
112
|
-
(function(mid) {
|
113
|
-
var func = function() {
|
114
|
-
rb_raise(rb_eNoMethodError, "undefined method `" + mid + "' for " + this.m$inspect());
|
115
|
-
};
|
116
|
-
|
117
|
-
kls.o$a.prototype['m$' + mid] = func;
|
118
|
-
|
119
|
-
})(args[i].m$to_s());
|
120
|
-
}
|
121
|
-
|
122
|
-
return Qnil;
|
123
|
-
};
|
124
|
-
|
125
|
-
/**
|
126
|
-
Define methods. Public method for defining a method on the given base.
|
127
|
-
|
128
|
-
@param {Object} klass The base to define method on
|
129
|
-
@param {String} name Ruby mid
|
130
|
-
@param {Function} body The method implementation
|
131
|
-
@param {Number} arity Method arity
|
132
|
-
@return {Qnil}
|
133
|
-
*/
|
134
|
-
Rt.dm = function(klass, name, body, arity) {
|
135
|
-
if (klass.$f & T_OBJECT) {
|
136
|
-
klass = klass.$k;
|
137
|
-
}
|
138
|
-
|
139
|
-
if (!body.$rbName) {
|
140
|
-
body.$rbName = name;
|
141
|
-
body.$arity = arity;
|
142
|
-
}
|
143
|
-
|
144
|
-
rb_define_raw_method(klass, 'm$' + name, body);
|
145
|
-
klass.$methods.push(name);
|
146
|
-
|
147
|
-
return Qnil;
|
148
|
-
};
|
149
|
-
|
150
|
-
/**
|
151
|
-
Define singleton method.
|
152
|
-
|
153
|
-
@param {Object} base The base to define method on
|
154
|
-
@param {String} method_id Method id
|
155
|
-
@param {Function} body Method implementation
|
156
|
-
@param {Number} arity Method arity
|
157
|
-
@return {Qnil}
|
158
|
-
*/
|
159
|
-
Rt.ds = function(base, method_id, body, arity) {
|
160
|
-
return Rt.dm(rb_singleton_class(base), method_id, body);
|
161
|
-
};
|
162
|
-
|
163
|
-
/**
|
164
|
-
Call a super method.
|
165
|
-
|
166
|
-
callee is the function that actually called super(). We use this to find
|
167
|
-
the right place in the tree to find the method that actually called super.
|
168
|
-
This is actually done in super_find.
|
169
|
-
*/
|
170
|
-
Rt.S = function(callee, self, args) {
|
171
|
-
var mid = 'm$' + callee.$rbName;
|
172
|
-
var func = rb_super_find(self.$k, callee, mid);
|
173
|
-
|
174
|
-
if (!func) {
|
175
|
-
rb_raise(rb_eNoMethodError, "super: no super class method `" + mid + "`" +
|
176
|
-
" for " + self.m$inspect());
|
177
|
-
}
|
178
|
-
|
179
|
-
// var args_to_send = [self].concat(args);
|
180
|
-
var args_to_send = [].concat(args);
|
181
|
-
return func.apply(self, args_to_send);
|
182
|
-
};
|
183
|
-
|
184
|
-
/**
|
185
|
-
Actually find super impl to call. Returns null if cannot find it.
|
186
|
-
*/
|
187
|
-
function rb_super_find(klass, callee, mid) {
|
188
|
-
var cur_method;
|
189
|
-
|
190
|
-
while (klass) {
|
191
|
-
if (klass.$m[mid]) {
|
192
|
-
if (klass.$m[mid] == callee) {
|
193
|
-
cur_method = klass.$m[mid];
|
194
|
-
break;
|
195
|
-
}
|
196
|
-
}
|
197
|
-
klass = klass.$s;
|
198
|
-
}
|
199
|
-
|
200
|
-
if (!(klass && cur_method)) { return null; }
|
201
|
-
|
202
|
-
klass = klass.$s;
|
203
|
-
|
204
|
-
while (klass) {
|
205
|
-
if (klass.$m[mid]) {
|
206
|
-
return klass.$m[mid];
|
207
|
-
}
|
208
|
-
|
209
|
-
klass = klass.$s;
|
210
|
-
}
|
211
|
-
|
212
|
-
return null;
|
213
|
-
};
|
214
|
-
|
215
|
-
/**
|
216
|
-
Exception classes. Some of these are used by runtime so they are here for
|
217
|
-
convenience.
|
218
|
-
*/
|
219
|
-
var rb_eException, rb_eStandardError, rb_eLocalJumpError, rb_eNameError,
|
220
|
-
rb_eNoMethodError, rb_eArgError, rb_eScriptError, rb_eLoadError,
|
221
|
-
rb_eRuntimeError, rb_eTypeError, rb_eIndexError, rb_eKeyError,
|
222
|
-
rb_eRangeError;
|
223
|
-
|
224
|
-
var rb_eExceptionInstance;
|
225
|
-
|
226
|
-
/**
|
227
|
-
Standard jump exceptions to save re-creating them everytime they are needed
|
228
|
-
*/
|
229
|
-
var rb_eReturnInstance,
|
230
|
-
rb_eBreakInstance,
|
231
|
-
rb_eNextInstance;
|
232
|
-
|
233
|
-
/**
|
234
|
-
Ruby break statement with the given value. When no break value is needed, nil
|
235
|
-
should be passed here. An undefined/null value is not valid and will cause an
|
236
|
-
internal error.
|
237
|
-
|
238
|
-
@param {RubyObject} value The break value.
|
239
|
-
*/
|
240
|
-
Rt.B = function(value) {
|
241
|
-
rb_eBreakInstance.$value = value;
|
242
|
-
rb_raise_exc(rb_eBreakInstance);
|
243
|
-
};
|
244
|
-
|
245
|
-
/**
|
246
|
-
Ruby return, with the given value. The func is the reference function which
|
247
|
-
represents the method that this statement must return from.
|
248
|
-
*/
|
249
|
-
Rt.R = function(value, func) {
|
250
|
-
rb_eReturnInstance.$value = value;
|
251
|
-
rb_eReturnInstance.$func = func;
|
252
|
-
throw rb_eReturnInstance;
|
253
|
-
};
|
254
|
-
|
255
|
-
/**
|
256
|
-
Get the given constant name from the given base
|
257
|
-
*/
|
258
|
-
Rt.cg = function(base, id) {
|
259
|
-
if (base.$f & T_OBJECT) {
|
260
|
-
base = rb_class_real(base.$k);
|
261
|
-
}
|
262
|
-
return rb_const_get(base, id);
|
263
|
-
};
|
264
|
-
|
265
|
-
/**
|
266
|
-
Set constant from runtime
|
267
|
-
*/
|
268
|
-
Rt.cs = function(base, id, val) {
|
269
|
-
if (base.$f & T_OBJECT) {
|
270
|
-
base = rb_class_real(base.$k);
|
271
|
-
}
|
272
|
-
return rb_const_set(base, id, val);
|
273
|
-
};
|
274
|
-
|
275
|
-
/**
|
276
|
-
Get global by id
|
277
|
-
*/
|
278
|
-
Rt.gg = function(id) {
|
279
|
-
return rb_gvar_get(id);
|
280
|
-
};
|
281
|
-
|
282
|
-
/**
|
283
|
-
Set global by id
|
284
|
-
*/
|
285
|
-
Rt.gs = function(id, value) {
|
286
|
-
return rb_gvar_set(id, value);
|
287
|
-
};
|
288
|
-
|
289
|
-
/**
|
290
|
-
Class variables table
|
291
|
-
*/
|
292
|
-
var rb_class_variables = {};
|
293
|
-
|
294
|
-
Rt.cvg = function(id) {
|
295
|
-
var v = rb_class_variables[id];
|
296
|
-
|
297
|
-
if (v) return v;
|
298
|
-
|
299
|
-
return Qnil;
|
300
|
-
};
|
301
|
-
|
302
|
-
Rt.cvs = function(id, val) {
|
303
|
-
return rb_class_variables[id] = val;
|
304
|
-
};
|
305
|
-
|
306
|
-
function rb_regexp_match_getter(id) {
|
307
|
-
var matched = Rt.X;
|
308
|
-
|
309
|
-
if (matched) {
|
310
|
-
if (matched.$md) {
|
311
|
-
return matched.$md;
|
312
|
-
} else {
|
313
|
-
var res = new cMatch.o$a();
|
314
|
-
res.$data = matched;
|
315
|
-
matched.$md = res;
|
316
|
-
return res;
|
317
|
-
}
|
318
|
-
} else {
|
319
|
-
return Qnil;
|
320
|
-
}
|
321
|
-
}
|
322
|
-
|
323
|
-
/**
|
324
|
-
An array of procs to call for at_exit()
|
325
|
-
|
326
|
-
@param {Function} proc implementation
|
327
|
-
*/
|
328
|
-
var rb_end_procs = [];
|
329
|
-
|
330
|
-
/**
|
331
|
-
Called upon exit: we need to run all of our registered procs
|
332
|
-
in reverse order: i.e. call last ones first.
|
333
|
-
|
334
|
-
FIXME: do we need to try/catch this??
|
335
|
-
*/
|
336
|
-
Rt.do_at_exit = function() {
|
337
|
-
var proc;
|
338
|
-
|
339
|
-
while (proc = rb_end_procs.pop()) {
|
340
|
-
proc.call(proc.$self);
|
341
|
-
}
|
342
|
-
|
343
|
-
return null;
|
344
|
-
};
|
345
|
-
|