opal 0.3.10 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/fs.js
DELETED
@@ -1,199 +0,0 @@
|
|
1
|
-
// ..........................................................
|
2
|
-
// FILE SYSTEM
|
3
|
-
//
|
4
|
-
|
5
|
-
/**
|
6
|
-
FileSystem namespace. Overiden in gem and node.js contexts
|
7
|
-
*/
|
8
|
-
var Fs = Op.fs = {};
|
9
|
-
|
10
|
-
/**
|
11
|
-
RegExp for splitting filenames into their dirname, basename and ext.
|
12
|
-
This currently only supports unix style filenames as this is what is
|
13
|
-
used internally when running in the browser.
|
14
|
-
*/
|
15
|
-
var PATH_RE = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
|
16
|
-
|
17
|
-
/**
|
18
|
-
Holds the current cwd for the application.
|
19
|
-
|
20
|
-
@type {String}
|
21
|
-
*/
|
22
|
-
Fs.cwd = '/';
|
23
|
-
|
24
|
-
/**
|
25
|
-
Join the given args using the default separator. The returned path
|
26
|
-
is not expanded.
|
27
|
-
|
28
|
-
@param {String} parts
|
29
|
-
@return {String}
|
30
|
-
*/
|
31
|
-
function fs_join(parts) {
|
32
|
-
parts = [].slice.call(arguments, 0);
|
33
|
-
return parts.join('/');
|
34
|
-
}
|
35
|
-
|
36
|
-
/**
|
37
|
-
Normalize the given path by removing '..' and '.' parts etc.
|
38
|
-
|
39
|
-
@param {String} path Path to normalize
|
40
|
-
@param {String} base Optional base to normalize with
|
41
|
-
@return {String}
|
42
|
-
*/
|
43
|
-
function fs_expand_path(path, base) {
|
44
|
-
if (!base) {
|
45
|
-
if (path.charAt(0) !== '/') {
|
46
|
-
base = Fs.cwd;
|
47
|
-
}
|
48
|
-
else {
|
49
|
-
base = '';
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
path = fs_join(base, path);
|
54
|
-
|
55
|
-
var parts = path.split('/'), result = [], part;
|
56
|
-
|
57
|
-
// initial /
|
58
|
-
if (parts[0] === '') result.push('');
|
59
|
-
|
60
|
-
for (var i = 0, ii = parts.length; i < ii; i++) {
|
61
|
-
part = parts[i];
|
62
|
-
|
63
|
-
if (part == '..') {
|
64
|
-
result.pop();
|
65
|
-
}
|
66
|
-
else if (part == '.' || part == '') {
|
67
|
-
|
68
|
-
}
|
69
|
-
else {
|
70
|
-
result.push(part);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
return result.join('/');
|
75
|
-
}
|
76
|
-
|
77
|
-
/**
|
78
|
-
Return all of the path components except the last one.
|
79
|
-
|
80
|
-
@param {String} path
|
81
|
-
@return {String}
|
82
|
-
*/
|
83
|
-
var fs_dirname = Fs.dirname = function(path) {
|
84
|
-
var dirname = PATH_RE.exec(path)[1];
|
85
|
-
|
86
|
-
if (!dirname) return '.';
|
87
|
-
else if (dirname === '/') return dirname;
|
88
|
-
else return dirname.substring(0, dirname.length - 1);
|
89
|
-
};
|
90
|
-
|
91
|
-
/**
|
92
|
-
Returns the file extension of the given `file_name`.
|
93
|
-
|
94
|
-
@param {String} file_name
|
95
|
-
@return {String}
|
96
|
-
*/
|
97
|
-
Fs.extname = function(file_name) {
|
98
|
-
var extname = PATH_RE.exec(file_name)[3];
|
99
|
-
|
100
|
-
if (!extname || extname === '.') return '';
|
101
|
-
else return extname;
|
102
|
-
};
|
103
|
-
|
104
|
-
Fs.exist_p = function(path) {
|
105
|
-
return Op.loader.factories[fs_expand_path(path)] ? true : false;
|
106
|
-
};
|
107
|
-
|
108
|
-
/**
|
109
|
-
Glob
|
110
|
-
*/
|
111
|
-
Fs.glob = function() {
|
112
|
-
var globs = [].slice.call(arguments);
|
113
|
-
|
114
|
-
var result = [], files = opal.loader.factories;
|
115
|
-
|
116
|
-
for (var i = 0, ii = globs.length; i < ii; i++) {
|
117
|
-
var glob = globs[i];
|
118
|
-
|
119
|
-
var re = fs_glob_to_regexp(glob);
|
120
|
-
// console.log("glob: " + glob);
|
121
|
-
// console.log("re : " + re);
|
122
|
-
|
123
|
-
for (var file in files) {
|
124
|
-
if (re.exec(file)) {
|
125
|
-
result.push(file);
|
126
|
-
}
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
return result;
|
131
|
-
};
|
132
|
-
|
133
|
-
/**
|
134
|
-
Turns a glob string into a regexp
|
135
|
-
*/
|
136
|
-
function fs_glob_to_regexp(glob) {
|
137
|
-
if (typeof glob !== 'string') {
|
138
|
-
raise(eException, "file_glob_to_regexp: glob must be a string");
|
139
|
-
}
|
140
|
-
|
141
|
-
// make sure absolute
|
142
|
-
glob = fs_expand_path(glob);
|
143
|
-
// console.log("full glob is: " + glob);
|
144
|
-
|
145
|
-
var parts = glob.split(''), length = parts.length, result = '';
|
146
|
-
|
147
|
-
var opt_group_stack = 0;
|
148
|
-
|
149
|
-
for (var i = 0; i < length; i++) {
|
150
|
-
var cur = parts[i];
|
151
|
-
|
152
|
-
switch (cur) {
|
153
|
-
case '*':
|
154
|
-
if (parts[i + 1] == '*') {
|
155
|
-
result += '.*';
|
156
|
-
i++;
|
157
|
-
}
|
158
|
-
else {
|
159
|
-
result += '[^/]*';
|
160
|
-
}
|
161
|
-
break;
|
162
|
-
|
163
|
-
case '.':
|
164
|
-
result += '\\';
|
165
|
-
result += cur;
|
166
|
-
break;
|
167
|
-
|
168
|
-
case ',':
|
169
|
-
if (opt_group_stack) {
|
170
|
-
result += '|';
|
171
|
-
}
|
172
|
-
else {
|
173
|
-
result += ',';
|
174
|
-
}
|
175
|
-
break;
|
176
|
-
|
177
|
-
case '{':
|
178
|
-
result += '(';
|
179
|
-
opt_group_stack++;
|
180
|
-
break;
|
181
|
-
|
182
|
-
case '}':
|
183
|
-
if (opt_group_stack) {
|
184
|
-
result += ')';
|
185
|
-
opt_group_stack--;
|
186
|
-
}
|
187
|
-
else {
|
188
|
-
result += '}'
|
189
|
-
}
|
190
|
-
break;
|
191
|
-
|
192
|
-
default:
|
193
|
-
result += cur;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
return new RegExp('^' + result + '$');
|
198
|
-
};
|
199
|
-
|
data/runtime/init.js
DELETED
@@ -1,556 +0,0 @@
|
|
1
|
-
|
2
|
-
/**
|
3
|
-
Sets the constant value `val` on the given `klass` as `id`.
|
4
|
-
|
5
|
-
@param {RClass} klass
|
6
|
-
@param {String} id
|
7
|
-
@param {Object} val
|
8
|
-
@return {Object} returns the set value
|
9
|
-
*/
|
10
|
-
function rb_const_set(klass, id, val) {
|
11
|
-
klass.$c[id] = val;
|
12
|
-
return val;
|
13
|
-
}
|
14
|
-
|
15
|
-
/**
|
16
|
-
Lookup a constant named `id` on the `klass`. This will throw an error if
|
17
|
-
the constant cannot be found.
|
18
|
-
|
19
|
-
@param {RClass} klass
|
20
|
-
@param {String} id
|
21
|
-
*/
|
22
|
-
function rb_const_get(klass, id) {
|
23
|
-
if (klass.$c[id]) {
|
24
|
-
return (klass.$c[id]);
|
25
|
-
}
|
26
|
-
|
27
|
-
var parent = klass.$parent;
|
28
|
-
|
29
|
-
while (parent) {
|
30
|
-
if (parent.$c[id] !== undefined) {
|
31
|
-
return parent.$c[id];
|
32
|
-
}
|
33
|
-
|
34
|
-
parent = parent.$parent;
|
35
|
-
}
|
36
|
-
|
37
|
-
rb_raise(rb_eNameError, 'uninitialized constant ' + id);
|
38
|
-
};
|
39
|
-
|
40
|
-
Rt.const_get = rb_const_get;
|
41
|
-
|
42
|
-
/**
|
43
|
-
Returns true or false depending whether a constant named `id` is defined
|
44
|
-
on the receiver `klass`.
|
45
|
-
|
46
|
-
@param {RClass} klass
|
47
|
-
@param {String} id
|
48
|
-
@return {true, false}
|
49
|
-
*/
|
50
|
-
function rb_const_defined(klass, id) {
|
51
|
-
if (klass.$c[id]) {
|
52
|
-
return true;
|
53
|
-
}
|
54
|
-
|
55
|
-
return false;
|
56
|
-
};
|
57
|
-
|
58
|
-
/**
|
59
|
-
This table holds all the global variables accessible from ruby.
|
60
|
-
|
61
|
-
Entries are mapped by their global id => an object that contains the
|
62
|
-
given keys:
|
63
|
-
|
64
|
-
- name
|
65
|
-
- value
|
66
|
-
- getter
|
67
|
-
- setter
|
68
|
-
*/
|
69
|
-
var rb_global_tbl = {};
|
70
|
-
|
71
|
-
/**
|
72
|
-
Defines a hooked/global variable.
|
73
|
-
|
74
|
-
@param {String} name The global name (e.g. '$:')
|
75
|
-
@param {Function} getter The getter function to return the variable
|
76
|
-
@param {Function} setter The setter function used for setting the var
|
77
|
-
@return {null}
|
78
|
-
*/
|
79
|
-
function rb_define_hooked_variable(name, getter, setter) {
|
80
|
-
var entry = {
|
81
|
-
"name": name,
|
82
|
-
"value": Qnil,
|
83
|
-
"getter": getter,
|
84
|
-
"setter": setter
|
85
|
-
};
|
86
|
-
|
87
|
-
rb_global_tbl[name] = entry;
|
88
|
-
};
|
89
|
-
|
90
|
-
/**
|
91
|
-
A default read only getter for a global variable. This will simply throw a
|
92
|
-
name error with the given id. This can be used for variables that should
|
93
|
-
not be altered.
|
94
|
-
*/
|
95
|
-
function rb_gvar_readonly_setter(id, value) {
|
96
|
-
rb_raise(rb_eNameError, id + " is a read-only variable");
|
97
|
-
};
|
98
|
-
|
99
|
-
/**
|
100
|
-
Retrieve a global variable. This will use the assigned getter.
|
101
|
-
*/
|
102
|
-
function rb_gvar_get(id) {
|
103
|
-
var entry = rb_global_tbl[id];
|
104
|
-
if (!entry) { return Qnil; }
|
105
|
-
return entry.getter(id);
|
106
|
-
};
|
107
|
-
|
108
|
-
/**
|
109
|
-
Set a global. If not already set, then we assign basic getters and setters.
|
110
|
-
*/
|
111
|
-
function rb_gvar_set(id, value) {
|
112
|
-
var entry = rb_global_tbl[id];
|
113
|
-
if (entry) { return entry.setter(id, value); }
|
114
|
-
|
115
|
-
rb_define_hooked_variable(id,
|
116
|
-
|
117
|
-
function(id) {
|
118
|
-
return rb_global_tbl[id].value;
|
119
|
-
},
|
120
|
-
|
121
|
-
function(id, value) {
|
122
|
-
return (rb_global_tbl[id].value = value);
|
123
|
-
}
|
124
|
-
);
|
125
|
-
|
126
|
-
return rb_gvar_set(id, value);
|
127
|
-
};
|
128
|
-
|
129
|
-
/**
|
130
|
-
Every object has a unique id. This count is used as the next id for the
|
131
|
-
next created object. Therefore, first ruby object has id 0, next has 1 etc.
|
132
|
-
*/
|
133
|
-
var rb_hash_yield = 0;
|
134
|
-
|
135
|
-
/**
|
136
|
-
Yield the next object id, updating the count, and returning it.
|
137
|
-
*/
|
138
|
-
function rb_yield_hash() {
|
139
|
-
return rb_hash_yield++;
|
140
|
-
};
|
141
|
-
|
142
|
-
var rb_cHash;
|
143
|
-
|
144
|
-
/**
|
145
|
-
Returns a new hash with values passed from the runtime.
|
146
|
-
*/
|
147
|
-
Rt.H = function() {
|
148
|
-
var hash = new rb_cHash.$a(), k, v, args = Array.prototype.slice.call(arguments);
|
149
|
-
var keys = hash.k = [];
|
150
|
-
var assocs = hash.a = {};
|
151
|
-
hash.d = Qnil;
|
152
|
-
|
153
|
-
for (var i = 0, ii = args.length; i < ii; i++) {
|
154
|
-
k = args[i];
|
155
|
-
v = args[i + 1];
|
156
|
-
i++;
|
157
|
-
keys.push(k);
|
158
|
-
assocs[k.$h()] = v;
|
159
|
-
}
|
160
|
-
|
161
|
-
return hash;
|
162
|
-
};
|
163
|
-
|
164
|
-
var rb_alias_method = Rt.alias_method = function(klass, new_name, old_name) {
|
165
|
-
var body = klass.$a.prototype['m$' + old_name];
|
166
|
-
|
167
|
-
if (!body) {
|
168
|
-
rb_raise(rb_eNameError, "undefined method `" + old_name + "' for class `" + klass.__classid__ + "'");
|
169
|
-
}
|
170
|
-
|
171
|
-
rb_define_raw_method(klass, 'm$' + new_name, body);
|
172
|
-
return Qnil;
|
173
|
-
};
|
174
|
-
|
175
|
-
/**
|
176
|
-
This does the main work, but does not call runtime methods like
|
177
|
-
singleton_method_added etc. define_method does that.
|
178
|
-
|
179
|
-
*/
|
180
|
-
function rb_define_raw_method(klass, name, body) {
|
181
|
-
|
182
|
-
klass.$a.prototype[name] = body;
|
183
|
-
klass.$m[name] = body;
|
184
|
-
|
185
|
-
var included_in = klass.$included_in, includee;
|
186
|
-
|
187
|
-
if (included_in) {
|
188
|
-
for (var i = 0, ii = included_in.length; i < ii; i++) {
|
189
|
-
includee = included_in[i];
|
190
|
-
|
191
|
-
rb_define_raw_method(includee, name, body);
|
192
|
-
}
|
193
|
-
}
|
194
|
-
|
195
|
-
// This class is toll free bridged, so add method to native
|
196
|
-
// prototype as well
|
197
|
-
if (klass.$bridge_prototype) {
|
198
|
-
klass.$bridge_prototype[name] = body;
|
199
|
-
}
|
200
|
-
|
201
|
-
// If we are dealing with Object, then we need to donate to
|
202
|
-
// all of our bridged prototypes as well.
|
203
|
-
if (klass === rb_cObject) {
|
204
|
-
var bridged = rb_bridged_classes;
|
205
|
-
|
206
|
-
for (var i = 0, ii = bridged.length; i < ii; i++) {
|
207
|
-
// do not overwrite bridged methods' implementation
|
208
|
-
if (!bridged[i][name]) {
|
209
|
-
bridged[i][name] = body;
|
210
|
-
}
|
211
|
-
}
|
212
|
-
}
|
213
|
-
};
|
214
|
-
|
215
|
-
function rb_define_alias(base, new_name, old_name) {
|
216
|
-
rb_define_method(base, new_name, base.$m_tbl[old_name]);
|
217
|
-
return Qnil;
|
218
|
-
};
|
219
|
-
|
220
|
-
/**
|
221
|
-
Raise the exception class with the given string message.
|
222
|
-
*/
|
223
|
-
function rb_raise(exc, str) {
|
224
|
-
if (str === undefined) {
|
225
|
-
str = exc;
|
226
|
-
exc = rb_eException;
|
227
|
-
}
|
228
|
-
|
229
|
-
var exception = exc.m$new(str);
|
230
|
-
rb_raise_exc(exception);
|
231
|
-
};
|
232
|
-
|
233
|
-
Rt.raise = rb_raise;
|
234
|
-
|
235
|
-
/**
|
236
|
-
Raise an exception instance (DO NOT pass strings to this)
|
237
|
-
*/
|
238
|
-
function rb_raise_exc(exc) {
|
239
|
-
throw exc;
|
240
|
-
};
|
241
|
-
|
242
|
-
var rb_cString;
|
243
|
-
|
244
|
-
|
245
|
-
/**
|
246
|
-
Exception classes. Some of these are used by runtime so they are here for
|
247
|
-
convenience.
|
248
|
-
*/
|
249
|
-
var rb_eException, rb_eStandardError, rb_eLocalJumpError, rb_eNameError,
|
250
|
-
rb_eNoMethodError, rb_eArgError, rb_eScriptError, rb_eLoadError,
|
251
|
-
rb_eRuntimeError, rb_eTypeError, rb_eIndexError, rb_eKeyError,
|
252
|
-
rb_eRangeError;
|
253
|
-
|
254
|
-
var rb_eExceptionInstance;
|
255
|
-
|
256
|
-
/**
|
257
|
-
Standard jump exceptions to save re-creating them everytime they are needed
|
258
|
-
*/
|
259
|
-
var rb_eReturnInstance,
|
260
|
-
rb_eBreakInstance,
|
261
|
-
rb_eNextInstance;
|
262
|
-
|
263
|
-
/**
|
264
|
-
Ruby break statement with the given value. When no break value is needed, nil
|
265
|
-
should be passed here. An undefined/null value is not valid and will cause an
|
266
|
-
internal error.
|
267
|
-
|
268
|
-
@param {RubyObject} value The break value.
|
269
|
-
*/
|
270
|
-
Rt.B = function(value) {
|
271
|
-
rb_eBreakInstance.$value = value;
|
272
|
-
rb_raise_exc(eBreakInstance);
|
273
|
-
};
|
274
|
-
|
275
|
-
/**
|
276
|
-
Ruby return, with the given value. The func is the reference function which
|
277
|
-
represents the method that this statement must return from.
|
278
|
-
*/
|
279
|
-
Rt.R = function(value, func) {
|
280
|
-
rb_eReturnInstance.$value = value;
|
281
|
-
rb_eReturnInstance.$func = func;
|
282
|
-
throw rb_eReturnInstance;
|
283
|
-
};
|
284
|
-
|
285
|
-
/**
|
286
|
-
Get global by id
|
287
|
-
*/
|
288
|
-
Rt.gg = function(id) {
|
289
|
-
return rb_gvar_get(id);
|
290
|
-
};
|
291
|
-
|
292
|
-
/**
|
293
|
-
Set global by id
|
294
|
-
*/
|
295
|
-
Rt.gs = function(id, value) {
|
296
|
-
return rb_gvar_set(id, value);
|
297
|
-
};
|
298
|
-
|
299
|
-
function rb_regexp_match_getter(id) {
|
300
|
-
var matched = Rt.X;
|
301
|
-
|
302
|
-
if (matched) {
|
303
|
-
if (matched.$md) {
|
304
|
-
return matched.$md;
|
305
|
-
} else {
|
306
|
-
var res = new rb_cMatch.o$a();
|
307
|
-
res.$data = matched;
|
308
|
-
matched.$md = res;
|
309
|
-
return res;
|
310
|
-
}
|
311
|
-
} else {
|
312
|
-
return Qnil;
|
313
|
-
}
|
314
|
-
}
|
315
|
-
|
316
|
-
var rb_cIO, rb_stdin, rb_stdout, rb_stderr;
|
317
|
-
|
318
|
-
function rb_stdio_getter(id) {
|
319
|
-
switch (id) {
|
320
|
-
case "$stdout":
|
321
|
-
return rb_stdout;
|
322
|
-
case "$stdin":
|
323
|
-
return rb_stdin;
|
324
|
-
case "$stderr":
|
325
|
-
return rb_stderr;
|
326
|
-
default:
|
327
|
-
rb_raise(rb_eRuntimeError, "stdout_setter being used for bad variable");
|
328
|
-
}
|
329
|
-
};
|
330
|
-
|
331
|
-
function rb_stdio_setter(id, value) {
|
332
|
-
rb_raise(rb_eException, "stdio_setter cannot currently set stdio variables");
|
333
|
-
|
334
|
-
switch (id) {
|
335
|
-
case "$stdout":
|
336
|
-
return rb_stdout = value;
|
337
|
-
case "$stdin":
|
338
|
-
return rb_stdin = value;
|
339
|
-
case "$stderr":
|
340
|
-
return rb_stderr = value;
|
341
|
-
default:
|
342
|
-
rb_raise(rb_eRuntimeError, "stdout_setter being used for bad variable: " + id);
|
343
|
-
}
|
344
|
-
};
|
345
|
-
|
346
|
-
var rb_cProc;
|
347
|
-
|
348
|
-
/**
|
349
|
-
Block passing - holds current block for runtime
|
350
|
-
|
351
|
-
f: function
|
352
|
-
p: proc
|
353
|
-
y: yield error
|
354
|
-
*/
|
355
|
-
var rb_block = Rt.P = {
|
356
|
-
f: null,
|
357
|
-
p: null,
|
358
|
-
y: function() {
|
359
|
-
rb_raise(rb_eLocalJumpError, "no block given");
|
360
|
-
}
|
361
|
-
};
|
362
|
-
|
363
|
-
rb_block.y.$self = rb_block.y;
|
364
|
-
|
365
|
-
/**
|
366
|
-
Turns the given proc/function into a lambda. This is useful for the
|
367
|
-
Proc#lambda method, but also for blocks that are turned into
|
368
|
-
methods, in Module#define_method, for example. Lambdas and methods
|
369
|
-
from blocks are the same thing. Lambdas basically wrap the passed
|
370
|
-
block function and perform stricter arg checking to make sure the
|
371
|
-
right number of args are passed. Procs are liberal in their arg
|
372
|
-
checking, and simply turned ommited args into nil. Lambdas and
|
373
|
-
methods MUST check args and throw an error if the wrong number are
|
374
|
-
given. Also, lambdas/methods must catch return statements as lambdas
|
375
|
-
capture returns.
|
376
|
-
|
377
|
-
FIXME: wrap must detect if we are the receiver of a block, and fix
|
378
|
-
the block to send it to the proc.
|
379
|
-
|
380
|
-
FIXME: need to be strict on checking proc arity
|
381
|
-
|
382
|
-
FIXME: need to catch return statements which may be thrown.
|
383
|
-
|
384
|
-
@param {Function} proc The proc/function to lambdafy.
|
385
|
-
@return {Function} Wrapped lambda function.
|
386
|
-
*/
|
387
|
-
function rb_make_lambda(proc) {
|
388
|
-
if (proc.$lambda) return proc;
|
389
|
-
|
390
|
-
var wrap = function() {
|
391
|
-
var args = Array.prototype.slice.call(arguments, 0);
|
392
|
-
return proc.apply(null, args);
|
393
|
-
};
|
394
|
-
|
395
|
-
wrap.$lambda = true;
|
396
|
-
wrap.o$s = proc.o$s;
|
397
|
-
|
398
|
-
return proc;
|
399
|
-
};
|
400
|
-
|
401
|
-
var rb_cRange;
|
402
|
-
|
403
|
-
/**
|
404
|
-
Returns a new ruby range. G for ranGe.
|
405
|
-
*/
|
406
|
-
Rt.G = function(beg, end, exc) {
|
407
|
-
var range = rb_obj_alloc(cRange);
|
408
|
-
range.beg = beg;
|
409
|
-
range.end = end;
|
410
|
-
range.exc = exc;
|
411
|
-
return range;
|
412
|
-
};
|
413
|
-
|
414
|
-
/**
|
415
|
-
Print to console - this is overriden upon init so that it will print to
|
416
|
-
stdout
|
417
|
-
*/
|
418
|
-
var puts = function(str) {
|
419
|
-
console.log(str);
|
420
|
-
};
|
421
|
-
|
422
|
-
/**
|
423
|
-
Main init method. This is called once this file has fully loaded. It setups
|
424
|
-
all the core objects and classes and required runtime features.
|
425
|
-
*/
|
426
|
-
function init() {
|
427
|
-
var metaclass;
|
428
|
-
|
429
|
-
// The *instances* of core objects..
|
430
|
-
rb_boot_Object = rb_boot_defclass('Object');
|
431
|
-
rb_boot_Module = rb_boot_defclass('Module', rb_boot_Object);
|
432
|
-
rb_boot_Class = rb_boot_defclass('Class', rb_boot_Module);
|
433
|
-
|
434
|
-
// The *classes* of core objects..
|
435
|
-
rb_cObject = rb_boot_makemeta('Object', rb_boot_Object, rb_boot_Class);
|
436
|
-
rb_cModule = rb_boot_makemeta('Module', rb_boot_Module, rb_cObject.constructor);
|
437
|
-
rb_cClass = rb_boot_makemeta('Class', rb_boot_Class, rb_cModule.constructor);
|
438
|
-
|
439
|
-
rb_boot_defmetameta(rb_cObject, rb_cClass);
|
440
|
-
rb_boot_defmetameta(rb_cModule, rb_cClass);
|
441
|
-
rb_boot_defmetameta(rb_cClass, rb_cClass);
|
442
|
-
|
443
|
-
// fix superclasses..
|
444
|
-
rb_cObject.$s = null;
|
445
|
-
rb_cModule.$s = rb_cObject;
|
446
|
-
rb_cClass.$s = rb_cModule;
|
447
|
-
|
448
|
-
rb_const_set(rb_cObject, 'Object', rb_cObject);
|
449
|
-
rb_const_set(rb_cObject, 'Module', rb_cModule);
|
450
|
-
rb_const_set(rb_cObject, 'Class', rb_cClass);
|
451
|
-
|
452
|
-
rb_mKernel = rb_define_module('Kernel');
|
453
|
-
|
454
|
-
rb_top_self = new rb_cObject.$a();
|
455
|
-
Rt.top = rb_top_self;
|
456
|
-
|
457
|
-
rb_cNilClass = rb_define_class('NilClass', rb_cObject);
|
458
|
-
Rt.Qnil = Qnil = new rb_cNilClass.$a();
|
459
|
-
Qnil.toString = function() {
|
460
|
-
return "nil";
|
461
|
-
};
|
462
|
-
|
463
|
-
rb_cBoolean = rb_bridge_class(Boolean.prototype, T_OBJECT, 'Boolean', rb_cObject);
|
464
|
-
|
465
|
-
rb_cArray = rb_bridge_class(Array.prototype, T_OBJECT | T_ARRAY, 'Array', rb_cObject);
|
466
|
-
// array instances all get standard properties for subclasses to work
|
467
|
-
var ary_proto = Array.prototype, ary_inst = rb_cArray.$a.prototype;
|
468
|
-
ary_inst.$f = T_ARRAY | T_OBJECT;
|
469
|
-
ary_inst.push = ary_proto.push;
|
470
|
-
ary_inst.pop = ary_proto.pop;
|
471
|
-
ary_inst.slice = ary_proto.slice;
|
472
|
-
ary_inst.splice = ary_proto.splice;
|
473
|
-
ary_inst.concat = ary_proto.concat;
|
474
|
-
ary_inst.shift = ary_proto.shift;
|
475
|
-
ary_inst.unshift = ary_proto.unshift;
|
476
|
-
ary_inst.length = 0;
|
477
|
-
|
478
|
-
rb_cHash = rb_define_class('Hash', rb_cObject);
|
479
|
-
|
480
|
-
rb_cNumeric = rb_bridge_class(Number.prototype,
|
481
|
-
T_OBJECT | T_NUMBER, 'Numeric', rb_cObject);
|
482
|
-
|
483
|
-
rb_cString = rb_bridge_class(String.prototype,
|
484
|
-
T_OBJECT | T_STRING, 'String', rb_cObject);
|
485
|
-
|
486
|
-
rb_cProc = rb_bridge_class(Function.prototype,
|
487
|
-
T_OBJECT | T_PROC, 'Proc', rb_cObject);
|
488
|
-
|
489
|
-
rb_cRange = rb_define_class('Range', rb_cObject);
|
490
|
-
|
491
|
-
rb_cRegexp = rb_bridge_class(RegExp.prototype,
|
492
|
-
T_OBJECT, 'Regexp', rb_cObject);
|
493
|
-
|
494
|
-
rb_cMatch = rb_define_class('MatchData', rb_cObject);
|
495
|
-
rb_define_hooked_variable('$~', rb_regexp_match_getter, rb_gvar_readonly_setter);
|
496
|
-
|
497
|
-
rb_eException = rb_bridge_class(Error.prototype,
|
498
|
-
T_OBJECT, 'Exception', rb_cObject);
|
499
|
-
|
500
|
-
rb_eStandardError = rb_define_class("StandardError", rb_eException);
|
501
|
-
rb_eRuntimeError = rb_define_class("RuntimeError", rb_eException);
|
502
|
-
rb_eLocalJumpError = rb_define_class("LocalJumpError", rb_eStandardError);
|
503
|
-
rb_eTypeError = rb_define_class("TypeError", rb_eStandardError);
|
504
|
-
|
505
|
-
rb_eNameError = rb_define_class("NameError", rb_eStandardError);
|
506
|
-
rb_eNoMethodError = rb_define_class('NoMethodError', rb_eNameError);
|
507
|
-
rb_eArgError = rb_define_class('ArgumentError', rb_eStandardError);
|
508
|
-
|
509
|
-
rb_eScriptError = rb_define_class('ScriptError', rb_eException);
|
510
|
-
rb_eLoadError = rb_define_class('LoadError', rb_eScriptError);
|
511
|
-
|
512
|
-
rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
|
513
|
-
rb_eKeyError = rb_define_class("KeyError", rb_eIndexError);
|
514
|
-
rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
|
515
|
-
|
516
|
-
rb_eBreakInstance = new Error('unexpected break');
|
517
|
-
rb_eBreakInstance.$k = rb_eLocalJumpError;
|
518
|
-
rb_block.b = rb_eBreakInstance;
|
519
|
-
|
520
|
-
rb_eReturnInstance = new Error('unexpected return');
|
521
|
-
rb_eReturnInstance.$k = rb_eLocalJumpError;
|
522
|
-
|
523
|
-
rb_eNextInstance = new Error('unexpected next');
|
524
|
-
rb_eNextInstance.$k = rb_eLocalJumpError;
|
525
|
-
|
526
|
-
rb_cIO = rb_define_class('IO', rb_cObject);
|
527
|
-
rb_stdin = new rb_cIO.$a();
|
528
|
-
rb_stdout = new rb_cIO.$a();
|
529
|
-
rb_stderr = new rb_cIO.$a();
|
530
|
-
|
531
|
-
rb_const_set(rb_cObject, 'STDIN', rb_stdin);
|
532
|
-
rb_const_set(rb_cObject, 'STDOUT', rb_stdout);
|
533
|
-
rb_const_set(rb_cObject, 'STDERR', rb_stderr);
|
534
|
-
|
535
|
-
rb_define_hooked_variable('$stdin', rb_stdio_getter, rb_stdio_setter);
|
536
|
-
rb_define_hooked_variable('$stdout', rb_stdio_getter, rb_stdio_setter);
|
537
|
-
rb_define_hooked_variable('$stderr', rb_stdio_getter, rb_stdio_setter);
|
538
|
-
|
539
|
-
rb_define_hooked_variable('$:', rb_load_path_getter, rb_gvar_readonly_setter);
|
540
|
-
rb_define_hooked_variable('$LOAD_PATH', rb_load_path_getter, rb_gvar_readonly_setter);
|
541
|
-
|
542
|
-
Op.loader = new Loader(Op);
|
543
|
-
Op.cache = {};
|
544
|
-
|
545
|
-
rb_const_set(rb_cObject, 'RUBY_ENGINE', PLATFORM_ENGINE);
|
546
|
-
rb_const_set(rb_cObject, 'RUBY_PLATFORM', PLATFORM_PLATFORM);
|
547
|
-
rb_const_set(rb_cObject, 'RUBY_VERSION', PLATFORM_VERSION);
|
548
|
-
rb_const_set(rb_cObject, 'ARGV', PLATFORM_ARGV);
|
549
|
-
|
550
|
-
Op.run(core_lib);
|
551
|
-
|
552
|
-
puts = function(str) {
|
553
|
-
rb_stdout.m$puts(str);
|
554
|
-
};
|
555
|
-
};
|
556
|
-
|