opal 0.3.6 → 0.3.9
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 +69 -97
- data/bin/opal +2 -2
- data/{lib/core → corelib}/array.rb +85 -56
- data/corelib/boolean.rb +20 -0
- data/corelib/class.rb +58 -0
- data/{lib → corelib}/core.rb +2 -50
- data/corelib/dir.rb +22 -0
- data/{lib/core → corelib}/enumerable.rb +0 -0
- data/corelib/error.rb +19 -0
- data/{lib/core → corelib}/file.rb +7 -9
- data/{lib/core → corelib}/hash.rb +104 -144
- data/{lib/core → corelib}/kernel.rb +38 -44
- data/corelib/load_order +21 -0
- data/{lib/core → corelib}/match_data.rb +0 -0
- data/{lib/core → corelib}/module.rb +12 -8
- data/{lib/core → corelib}/nil_class.rb +2 -2
- data/{lib/core → corelib}/numeric.rb +37 -100
- data/corelib/object.rb +37 -0
- data/{lib/core → corelib}/proc.rb +3 -3
- data/corelib/range.rb +27 -0
- data/{lib/core → corelib}/regexp.rb +1 -1
- data/{lib/core → corelib}/string.rb +16 -107
- data/{lib/core → corelib}/top_self.rb +0 -0
- data/lib/opal.rb +7 -0
- data/lib/opal/browserify.rb +34 -0
- data/{opal_lib → lib}/opal/builder.rb +70 -24
- data/lib/opal/command.rb +52 -0
- data/lib/opal/context.rb +197 -0
- data/{opal_lib/opal/ruby/parser.rb → lib/opal/lexer.rb} +20 -4
- data/{opal_lib/opal/ruby → lib/opal}/nodes.rb +238 -127
- data/lib/opal/parser.rb +4894 -0
- data/{opal_lib/opal/ruby/ruby_parser.y → lib/opal/parser.y} +38 -18
- data/lib/rbp.rb +2 -0
- data/lib/rbp/package.rb +49 -0
- data/runtime/class.js +216 -189
- data/runtime/fs.js +2 -2
- data/runtime/init.js +242 -244
- data/runtime/loader.js +78 -99
- data/runtime/module.js +34 -40
- data/runtime/post.js +2 -2
- data/runtime/pre.js +1 -1
- data/runtime/runtime.js +129 -135
- data/{lib → stdlib}/dev.rb +10 -10
- data/{lib → stdlib}/racc/parser.rb +0 -6
- data/{lib → stdlib}/strscan.rb +4 -4
- metadata +57 -105
- data/lib/core/basic_object.rb +0 -51
- data/lib/core/class.rb +0 -38
- data/lib/core/dir.rb +0 -26
- data/lib/core/error.rb +0 -75
- data/lib/core/false_class.rb +0 -81
- data/lib/core/object.rb +0 -6
- data/lib/core/range.rb +0 -27
- data/lib/core/symbol.rb +0 -42
- data/lib/core/true_class.rb +0 -41
- data/lib/ospec.rb +0 -7
- data/lib/ospec/autorun.rb +0 -8
- data/lib/ospec/dsl.rb +0 -15
- data/lib/ospec/example.rb +0 -11
- data/lib/ospec/example/before_and_after_hooks.rb +0 -56
- data/lib/ospec/example/errors.rb +0 -17
- data/lib/ospec/example/example_group.rb +0 -12
- data/lib/ospec/example/example_group_factory.rb +0 -18
- data/lib/ospec/example/example_group_hierarchy.rb +0 -21
- data/lib/ospec/example/example_group_methods.rb +0 -100
- data/lib/ospec/example/example_group_proxy.rb +0 -15
- data/lib/ospec/example/example_methods.rb +0 -46
- data/lib/ospec/example/example_proxy.rb +0 -18
- data/lib/ospec/expectations.rb +0 -19
- data/lib/ospec/expectations/errors.rb +0 -8
- data/lib/ospec/expectations/fail_with.rb +0 -9
- data/lib/ospec/expectations/handler.rb +0 -33
- data/lib/ospec/helpers/scratch.rb +0 -18
- data/lib/ospec/matchers.rb +0 -24
- data/lib/ospec/matchers/be.rb +0 -1
- data/lib/ospec/matchers/generated_descriptions.rb +0 -20
- data/lib/ospec/matchers/operator_matcher.rb +0 -54
- data/lib/ospec/matchers/raise_error.rb +0 -38
- data/lib/ospec/runner.rb +0 -90
- data/lib/ospec/runner/example_group_runner.rb +0 -41
- data/lib/ospec/runner/formatter/html_formatter.rb +0 -139
- data/lib/ospec/runner/formatter/terminal_formatter.rb +0 -48
- data/lib/ospec/runner/options.rb +0 -34
- data/lib/ospec/runner/reporter.rb +0 -82
- data/opal_lib/opal.rb +0 -16
- data/opal_lib/opal/build_methods.rb +0 -51
- data/opal_lib/opal/bundle.rb +0 -70
- data/opal_lib/opal/command.rb +0 -68
- data/opal_lib/opal/context.rb +0 -81
- data/opal_lib/opal/context/console.rb +0 -10
- data/opal_lib/opal/context/file_system.rb +0 -34
- data/opal_lib/opal/context/loader.rb +0 -135
- data/opal_lib/opal/gem.rb +0 -84
- data/opal_lib/opal/rake/builder_task.rb +0 -44
- data/opal_lib/opal/rake/spec_task.rb +0 -32
- data/opal_lib/opal/ruby/ruby_parser.rb +0 -4862
- data/opal_lib/opal/version.rb +0 -4
- data/runtime/debug.js +0 -84
data/runtime/fs.js
CHANGED
|
@@ -102,7 +102,7 @@ Fs.extname = function(file_name) {
|
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
Fs.exist_p = function(path) {
|
|
105
|
-
return
|
|
105
|
+
return Op.loader.factories[fs_expand_path(path)] ? true : false;
|
|
106
106
|
};
|
|
107
107
|
|
|
108
108
|
/**
|
|
@@ -135,7 +135,7 @@ Fs.glob = function() {
|
|
|
135
135
|
*/
|
|
136
136
|
function fs_glob_to_regexp(glob) {
|
|
137
137
|
if (typeof glob !== 'string') {
|
|
138
|
-
|
|
138
|
+
raise(eException, "file_glob_to_regexp: glob must be a string");
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// make sure absolute
|
data/runtime/init.js
CHANGED
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
@param {Object} val
|
|
8
8
|
@return {Object} returns the set value
|
|
9
9
|
*/
|
|
10
|
-
function
|
|
11
|
-
klass.$
|
|
12
|
-
klass.$const_table[id] = val;
|
|
10
|
+
function rb_const_set(klass, id, val) {
|
|
11
|
+
klass.$c[id] = val;
|
|
13
12
|
return val;
|
|
14
13
|
}
|
|
15
14
|
|
|
@@ -20,15 +19,14 @@ function const_set(klass, id, val) {
|
|
|
20
19
|
@param {RClass} klass
|
|
21
20
|
@param {String} id
|
|
22
21
|
*/
|
|
23
|
-
function
|
|
22
|
+
function rb_const_get(klass, id) {
|
|
24
23
|
if (klass.$c[id]) {
|
|
25
24
|
return (klass.$c[id]);
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
var parent = klass.$parent;
|
|
29
28
|
|
|
30
|
-
while (parent
|
|
31
|
-
// while (parent) {
|
|
29
|
+
while (parent) {
|
|
32
30
|
if (parent.$c[id] !== undefined) {
|
|
33
31
|
return parent.$c[id];
|
|
34
32
|
}
|
|
@@ -36,10 +34,10 @@ function const_get(klass, id) {
|
|
|
36
34
|
parent = parent.$parent;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
rb_raise(rb_eNameError, 'uninitialized constant ' + id);
|
|
40
38
|
};
|
|
41
39
|
|
|
42
|
-
Rt.const_get =
|
|
40
|
+
Rt.const_get = rb_const_get;
|
|
43
41
|
|
|
44
42
|
/**
|
|
45
43
|
Returns true or false depending whether a constant named `id` is defined
|
|
@@ -49,7 +47,7 @@ Rt.const_get = const_get;
|
|
|
49
47
|
@param {String} id
|
|
50
48
|
@return {true, false}
|
|
51
49
|
*/
|
|
52
|
-
function
|
|
50
|
+
function rb_const_defined(klass, id) {
|
|
53
51
|
if (klass.$c[id]) {
|
|
54
52
|
return true;
|
|
55
53
|
}
|
|
@@ -68,7 +66,7 @@ function const_defined(klass, id) {
|
|
|
68
66
|
- getter
|
|
69
67
|
- setter
|
|
70
68
|
*/
|
|
71
|
-
var
|
|
69
|
+
var rb_global_tbl = {};
|
|
72
70
|
|
|
73
71
|
/**
|
|
74
72
|
Defines a hooked/global variable.
|
|
@@ -78,7 +76,7 @@ var global_tbl = {};
|
|
|
78
76
|
@param {Function} setter The setter function used for setting the var
|
|
79
77
|
@return {null}
|
|
80
78
|
*/
|
|
81
|
-
function
|
|
79
|
+
function rb_define_hooked_variable(name, getter, setter) {
|
|
82
80
|
var entry = {
|
|
83
81
|
"name": name,
|
|
84
82
|
"value": Qnil,
|
|
@@ -86,7 +84,7 @@ function define_hooked_variable(name, getter, setter) {
|
|
|
86
84
|
"setter": setter
|
|
87
85
|
};
|
|
88
86
|
|
|
89
|
-
|
|
87
|
+
rb_global_tbl[name] = entry;
|
|
90
88
|
};
|
|
91
89
|
|
|
92
90
|
/**
|
|
@@ -94,15 +92,15 @@ function define_hooked_variable(name, getter, setter) {
|
|
|
94
92
|
name error with the given id. This can be used for variables that should
|
|
95
93
|
not be altered.
|
|
96
94
|
*/
|
|
97
|
-
function
|
|
98
|
-
|
|
95
|
+
function rb_gvar_readonly_setter(id, value) {
|
|
96
|
+
rb_raise(rb_eNameError, id + " is a read-only variable");
|
|
99
97
|
};
|
|
100
98
|
|
|
101
99
|
/**
|
|
102
100
|
Retrieve a global variable. This will use the assigned getter.
|
|
103
101
|
*/
|
|
104
|
-
function
|
|
105
|
-
var entry =
|
|
102
|
+
function rb_gvar_get(id) {
|
|
103
|
+
var entry = rb_global_tbl[id];
|
|
106
104
|
if (!entry) { return Qnil; }
|
|
107
105
|
return entry.getter(id);
|
|
108
106
|
};
|
|
@@ -110,67 +108,67 @@ function gvar_get(id) {
|
|
|
110
108
|
/**
|
|
111
109
|
Set a global. If not already set, then we assign basic getters and setters.
|
|
112
110
|
*/
|
|
113
|
-
function
|
|
114
|
-
var entry =
|
|
111
|
+
function rb_gvar_set(id, value) {
|
|
112
|
+
var entry = rb_global_tbl[id];
|
|
115
113
|
if (entry) { return entry.setter(id, value); }
|
|
116
114
|
|
|
117
|
-
|
|
115
|
+
rb_define_hooked_variable(id,
|
|
118
116
|
|
|
119
117
|
function(id) {
|
|
120
|
-
return
|
|
118
|
+
return rb_global_tbl[id].value;
|
|
121
119
|
},
|
|
122
120
|
|
|
123
121
|
function(id, value) {
|
|
124
|
-
return (
|
|
122
|
+
return (rb_global_tbl[id].value = value);
|
|
125
123
|
}
|
|
126
124
|
);
|
|
127
125
|
|
|
128
|
-
return
|
|
126
|
+
return rb_gvar_set(id, value);
|
|
129
127
|
};
|
|
130
128
|
|
|
131
129
|
/**
|
|
132
130
|
Every object has a unique id. This count is used as the next id for the
|
|
133
131
|
next created object. Therefore, first ruby object has id 0, next has 1 etc.
|
|
134
132
|
*/
|
|
135
|
-
var
|
|
133
|
+
var rb_hash_yield = 0;
|
|
136
134
|
|
|
137
135
|
/**
|
|
138
136
|
Yield the next object id, updating the count, and returning it.
|
|
139
137
|
*/
|
|
140
|
-
function
|
|
141
|
-
return
|
|
138
|
+
function rb_yield_hash() {
|
|
139
|
+
return rb_hash_yield++;
|
|
142
140
|
};
|
|
143
141
|
|
|
144
|
-
var
|
|
142
|
+
var rb_cHash;
|
|
145
143
|
|
|
146
144
|
/**
|
|
147
145
|
Returns a new hash with values passed from the runtime.
|
|
148
146
|
*/
|
|
149
147
|
Rt.H = function() {
|
|
150
|
-
var hash = new
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
hash
|
|
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;
|
|
154
152
|
|
|
155
153
|
for (var i = 0, ii = args.length; i < ii; i++) {
|
|
156
154
|
k = args[i];
|
|
157
155
|
v = args[i + 1];
|
|
158
156
|
i++;
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
keys.push(k);
|
|
158
|
+
assocs[k.$h()] = v;
|
|
161
159
|
}
|
|
162
160
|
|
|
163
161
|
return hash;
|
|
164
162
|
};
|
|
165
163
|
|
|
166
|
-
var
|
|
167
|
-
var body = klass.$
|
|
164
|
+
var rb_alias_method = Rt.alias_method = function(klass, new_name, old_name) {
|
|
165
|
+
var body = klass.$a.prototype['m$' + old_name];
|
|
168
166
|
|
|
169
167
|
if (!body) {
|
|
170
|
-
|
|
168
|
+
rb_raise(rb_eNameError, "undefined method `" + old_name + "' for class `" + klass.__classid__ + "'");
|
|
171
169
|
}
|
|
172
170
|
|
|
173
|
-
|
|
171
|
+
rb_define_raw_method(klass, 'm$' + new_name, body);
|
|
174
172
|
return Qnil;
|
|
175
173
|
};
|
|
176
174
|
|
|
@@ -179,13 +177,10 @@ var alias_method = Rt.alias_method = function(klass, new_name, old_name) {
|
|
|
179
177
|
singleton_method_added etc. define_method does that.
|
|
180
178
|
|
|
181
179
|
*/
|
|
182
|
-
function
|
|
183
|
-
var public_name = '$' + private_name;
|
|
180
|
+
function rb_define_raw_method(klass, name, body) {
|
|
184
181
|
|
|
185
|
-
klass.$
|
|
186
|
-
klass.$
|
|
187
|
-
|
|
188
|
-
klass.$method_table[private_name] = private_body;
|
|
182
|
+
klass.$a.prototype[name] = body;
|
|
183
|
+
klass.$m[name] = body;
|
|
189
184
|
|
|
190
185
|
var included_in = klass.$included_in, includee;
|
|
191
186
|
|
|
@@ -193,144 +188,162 @@ function define_raw_method(klass, private_name, private_body, public_body) {
|
|
|
193
188
|
for (var i = 0, ii = included_in.length; i < ii; i++) {
|
|
194
189
|
includee = included_in[i];
|
|
195
190
|
|
|
196
|
-
|
|
191
|
+
rb_define_raw_method(includee, name, body);
|
|
197
192
|
}
|
|
198
193
|
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
Rt.private_methods = function(klass, args) {
|
|
202
|
-
return;
|
|
203
|
-
|
|
204
|
-
if (args.length) {
|
|
205
|
-
var proto = klass.allocator.prototype;
|
|
206
194
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (!proto[mid] || proto[mid].$rbMM) {
|
|
213
|
-
raise(eNameError, "undefined method `" + arg +
|
|
214
|
-
"' for class `" + klass.__classid__ + "'");
|
|
215
|
-
}
|
|
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
|
+
}
|
|
216
200
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
this.$m$inspect());
|
|
222
|
-
}
|
|
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;
|
|
223
205
|
|
|
224
|
-
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
// set
|
|
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;
|
|
229
210
|
}
|
|
230
211
|
}
|
|
231
212
|
}
|
|
232
|
-
else {
|
|
233
|
-
// no args - set klass mode to private
|
|
234
|
-
klass.$mode = FL_PRIVATE;
|
|
235
|
-
}
|
|
236
213
|
};
|
|
237
214
|
|
|
238
|
-
function
|
|
239
|
-
|
|
215
|
+
function rb_define_alias(base, new_name, old_name) {
|
|
216
|
+
rb_define_method(base, new_name, base.$m_tbl[old_name]);
|
|
240
217
|
return Qnil;
|
|
241
218
|
};
|
|
242
219
|
|
|
243
|
-
function obj_alloc(klass) {
|
|
244
|
-
var result = new RObject(klass);
|
|
245
|
-
return result;
|
|
246
|
-
};
|
|
247
|
-
|
|
248
220
|
/**
|
|
249
221
|
Raise the exception class with the given string message.
|
|
250
222
|
*/
|
|
251
|
-
function
|
|
223
|
+
function rb_raise(exc, str) {
|
|
252
224
|
if (str === undefined) {
|
|
253
225
|
str = exc;
|
|
254
|
-
exc =
|
|
226
|
+
exc = rb_eException;
|
|
255
227
|
}
|
|
256
228
|
|
|
257
|
-
var exception = exc
|
|
258
|
-
|
|
229
|
+
var exception = exc.m$new(str);
|
|
230
|
+
rb_raise_exc(exception);
|
|
259
231
|
};
|
|
260
232
|
|
|
261
|
-
Rt.raise =
|
|
233
|
+
Rt.raise = rb_raise;
|
|
262
234
|
|
|
263
235
|
/**
|
|
264
236
|
Raise an exception instance (DO NOT pass strings to this)
|
|
265
237
|
*/
|
|
266
|
-
function
|
|
238
|
+
function rb_raise_exc(exc) {
|
|
267
239
|
throw exc;
|
|
268
240
|
};
|
|
269
241
|
|
|
270
|
-
|
|
242
|
+
var rb_cString;
|
|
271
243
|
|
|
272
|
-
var cString, cSymbol;
|
|
273
244
|
|
|
274
245
|
/**
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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;
|
|
279
255
|
|
|
280
|
-
|
|
281
|
-
|
|
256
|
+
/**
|
|
257
|
+
Standard jump exceptions to save re-creating them everytime they are needed
|
|
282
258
|
*/
|
|
283
|
-
var
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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.
|
|
287
267
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return res;
|
|
268
|
+
@param {RubyObject} value The break value.
|
|
269
|
+
*/
|
|
270
|
+
Rt.B = function(value) {
|
|
271
|
+
rb_eBreakInstance.$value = value;
|
|
272
|
+
rb_raise_exc(eBreakInstance);
|
|
294
273
|
};
|
|
295
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
|
+
};
|
|
296
284
|
|
|
297
|
-
|
|
285
|
+
/**
|
|
286
|
+
Get global by id
|
|
287
|
+
*/
|
|
288
|
+
Rt.gg = function(id) {
|
|
289
|
+
return rb_gvar_get(id);
|
|
290
|
+
};
|
|
298
291
|
|
|
299
|
-
|
|
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) {
|
|
300
319
|
switch (id) {
|
|
301
320
|
case "$stdout":
|
|
302
|
-
return
|
|
321
|
+
return rb_stdout;
|
|
303
322
|
case "$stdin":
|
|
304
|
-
return
|
|
323
|
+
return rb_stdin;
|
|
305
324
|
case "$stderr":
|
|
306
|
-
return
|
|
325
|
+
return rb_stderr;
|
|
307
326
|
default:
|
|
308
|
-
|
|
327
|
+
rb_raise(rb_eRuntimeError, "stdout_setter being used for bad variable");
|
|
309
328
|
}
|
|
310
329
|
};
|
|
311
330
|
|
|
312
|
-
function
|
|
313
|
-
|
|
331
|
+
function rb_stdio_setter(id, value) {
|
|
332
|
+
rb_raise(rb_eException, "stdio_setter cannot currently set stdio variables");
|
|
314
333
|
|
|
315
334
|
switch (id) {
|
|
316
335
|
case "$stdout":
|
|
317
|
-
return
|
|
336
|
+
return rb_stdout = value;
|
|
318
337
|
case "$stdin":
|
|
319
|
-
return
|
|
338
|
+
return rb_stdin = value;
|
|
320
339
|
case "$stderr":
|
|
321
|
-
return
|
|
340
|
+
return rb_stderr = value;
|
|
322
341
|
default:
|
|
323
|
-
|
|
342
|
+
rb_raise(rb_eRuntimeError, "stdout_setter being used for bad variable: " + id);
|
|
324
343
|
}
|
|
325
344
|
};
|
|
326
345
|
|
|
327
|
-
|
|
328
|
-
var regexp = new cRegexp.allocator();
|
|
329
|
-
regexp.$re = re;
|
|
330
|
-
return regexp;
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
var cProc;
|
|
346
|
+
var rb_cProc;
|
|
334
347
|
|
|
335
348
|
/**
|
|
336
349
|
Block passing - holds current block for runtime
|
|
@@ -339,15 +352,15 @@ var cProc;
|
|
|
339
352
|
p: proc
|
|
340
353
|
y: yield error
|
|
341
354
|
*/
|
|
342
|
-
var
|
|
355
|
+
var rb_block = Rt.P = {
|
|
343
356
|
f: null,
|
|
344
357
|
p: null,
|
|
345
358
|
y: function() {
|
|
346
|
-
|
|
359
|
+
rb_raise(rb_eLocalJumpError, "no block given");
|
|
347
360
|
}
|
|
348
361
|
};
|
|
349
362
|
|
|
350
|
-
|
|
363
|
+
rb_block.y.$self = rb_block.y;
|
|
351
364
|
|
|
352
365
|
/**
|
|
353
366
|
Turns the given proc/function into a lambda. This is useful for the
|
|
@@ -371,7 +384,7 @@ block.y.$proc = [block.y];
|
|
|
371
384
|
@param {Function} proc The proc/function to lambdafy.
|
|
372
385
|
@return {Function} Wrapped lambda function.
|
|
373
386
|
*/
|
|
374
|
-
|
|
387
|
+
function rb_make_lambda(proc) {
|
|
375
388
|
if (proc.$lambda) return proc;
|
|
376
389
|
|
|
377
390
|
var wrap = function() {
|
|
@@ -380,30 +393,28 @@ Rt.lambda = function(proc) {
|
|
|
380
393
|
};
|
|
381
394
|
|
|
382
395
|
wrap.$lambda = true;
|
|
383
|
-
wrap
|
|
396
|
+
wrap.o$s = proc.o$s;
|
|
384
397
|
|
|
385
|
-
return
|
|
398
|
+
return proc;
|
|
386
399
|
};
|
|
387
400
|
|
|
388
|
-
var
|
|
401
|
+
var rb_cRange;
|
|
389
402
|
|
|
390
403
|
/**
|
|
391
404
|
Returns a new ruby range. G for ranGe.
|
|
392
405
|
*/
|
|
393
406
|
Rt.G = function(beg, end, exc) {
|
|
394
|
-
var range =
|
|
395
|
-
range
|
|
396
|
-
range
|
|
397
|
-
range
|
|
407
|
+
var range = rb_obj_alloc(cRange);
|
|
408
|
+
range.beg = beg;
|
|
409
|
+
range.end = end;
|
|
410
|
+
range.exc = exc;
|
|
398
411
|
return range;
|
|
399
412
|
};
|
|
400
413
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
};
|
|
406
|
-
|
|
414
|
+
/**
|
|
415
|
+
Print to console - this is overriden upon init so that it will print to
|
|
416
|
+
stdout
|
|
417
|
+
*/
|
|
407
418
|
var puts = function(str) {
|
|
408
419
|
console.log(str);
|
|
409
420
|
};
|
|
@@ -413,146 +424,133 @@ var puts = function(str) {
|
|
|
413
424
|
all the core objects and classes and required runtime features.
|
|
414
425
|
*/
|
|
415
426
|
function init() {
|
|
416
|
-
if (typeof OPAL_DEBUG != "undefined" && OPAL_DEBUG) {
|
|
417
|
-
init_debug();
|
|
418
|
-
}
|
|
419
|
-
|
|
420
427
|
var metaclass;
|
|
421
428
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
const_set(cObject, 'BasicObject', cBasicObject);
|
|
428
|
-
|
|
429
|
-
metaclass = make_metaclass(cBasicObject, cClass);
|
|
430
|
-
metaclass = make_metaclass(cObject, metaclass);
|
|
431
|
-
metaclass = make_metaclass(cModule, metaclass);
|
|
432
|
-
metaclass = make_metaclass(cClass, metaclass);
|
|
433
|
-
|
|
434
|
-
boot_defmetametaclass(cModule, metaclass);
|
|
435
|
-
boot_defmetametaclass(cObject, metaclass);
|
|
436
|
-
boot_defmetametaclass(cBasicObject, metaclass);
|
|
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);
|
|
437
433
|
|
|
438
|
-
|
|
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);
|
|
439
438
|
|
|
440
|
-
|
|
441
|
-
|
|
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
442
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
443
|
+
// fix superclasses..
|
|
444
|
+
rb_cObject.$s = null;
|
|
445
|
+
rb_cModule.$s = rb_cObject;
|
|
446
|
+
rb_cClass.$s = rb_cModule;
|
|
446
447
|
|
|
447
|
-
|
|
448
|
-
|
|
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);
|
|
449
451
|
|
|
450
|
-
|
|
451
|
-
Rt.Qfalse = Qfalse = obj_alloc(cFalseClass);
|
|
452
|
-
Qfalse.$r = false;
|
|
452
|
+
rb_mKernel = rb_define_module('Kernel');
|
|
453
453
|
|
|
454
|
-
|
|
455
|
-
|
|
454
|
+
rb_top_self = new rb_cObject.$a();
|
|
455
|
+
Rt.top = rb_top_self;
|
|
456
456
|
|
|
457
|
-
|
|
458
|
-
|
|
457
|
+
rb_cNilClass = rb_define_class('NilClass', rb_cObject);
|
|
458
|
+
Rt.Qnil = Qnil = new rb_cNilClass.$a();
|
|
459
|
+
Qnil.toString = function() {
|
|
460
|
+
return "nil";
|
|
459
461
|
};
|
|
460
462
|
|
|
461
|
-
|
|
463
|
+
rb_cBoolean = rb_bridge_class(Boolean.prototype, T_OBJECT, 'Boolean', rb_cObject);
|
|
462
464
|
|
|
463
|
-
|
|
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;
|
|
465
477
|
|
|
466
|
-
|
|
467
|
-
T_OBJECT | T_STRING, 'String', cObject);
|
|
478
|
+
rb_cHash = rb_define_class('Hash', rb_cObject);
|
|
468
479
|
|
|
469
|
-
|
|
480
|
+
rb_cNumeric = rb_bridge_class(Number.prototype,
|
|
481
|
+
T_OBJECT | T_NUMBER, 'Numeric', rb_cObject);
|
|
470
482
|
|
|
471
|
-
|
|
472
|
-
T_OBJECT |
|
|
483
|
+
rb_cString = rb_bridge_class(String.prototype,
|
|
484
|
+
T_OBJECT | T_STRING, 'String', rb_cObject);
|
|
473
485
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
cRange = define_class('Range', cObject);
|
|
486
|
+
rb_cProc = rb_bridge_class(Function.prototype,
|
|
487
|
+
T_OBJECT | T_PROC, 'Proc', rb_cObject);
|
|
479
488
|
|
|
480
|
-
|
|
481
|
-
T_OBJECT, 'Regexp', cObject);
|
|
489
|
+
rb_cRange = rb_define_class('Range', rb_cObject);
|
|
482
490
|
|
|
483
|
-
|
|
484
|
-
|
|
491
|
+
rb_cRegexp = rb_bridge_class(RegExp.prototype,
|
|
492
|
+
T_OBJECT, 'Regexp', rb_cObject);
|
|
485
493
|
|
|
486
|
-
|
|
494
|
+
rb_cMatch = rb_define_class('MatchData', rb_cObject);
|
|
495
|
+
rb_define_hooked_variable('$~', rb_regexp_match_getter, rb_gvar_readonly_setter);
|
|
487
496
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
eLocalJumpError = define_class("LocalJumpError", eStandardError);
|
|
491
|
-
Rt.TypeError = eTypeError = define_class("TypeError", eStandardError);
|
|
497
|
+
rb_eException = rb_bridge_class(Error.prototype,
|
|
498
|
+
T_OBJECT, 'Exception', rb_cObject);
|
|
492
499
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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);
|
|
496
504
|
|
|
497
|
-
|
|
498
|
-
|
|
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);
|
|
499
508
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
eRangeError = define_class("RangeError", eStandardError);
|
|
509
|
+
rb_eScriptError = rb_define_class('ScriptError', rb_eException);
|
|
510
|
+
rb_eLoadError = rb_define_class('LoadError', rb_eScriptError);
|
|
503
511
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
// dont need this anymore???
|
|
508
|
-
eBreakInstance.$keyword = 2;
|
|
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);
|
|
509
515
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
516
|
+
rb_eBreakInstance = new Error('unexpected break');
|
|
517
|
+
rb_eBreakInstance.$k = rb_eLocalJumpError;
|
|
518
|
+
rb_block.b = rb_eBreakInstance;
|
|
513
519
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
eNextInstance.$keyword = 3;
|
|
520
|
+
rb_eReturnInstance = new Error('unexpected return');
|
|
521
|
+
rb_eReturnInstance.$k = rb_eLocalJumpError;
|
|
517
522
|
|
|
518
|
-
|
|
519
|
-
|
|
523
|
+
rb_eNextInstance = new Error('unexpected next');
|
|
524
|
+
rb_eNextInstance.$k = rb_eLocalJumpError;
|
|
520
525
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
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();
|
|
525
530
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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);
|
|
529
534
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
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);
|
|
533
538
|
|
|
534
|
-
|
|
535
|
-
|
|
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);
|
|
536
541
|
|
|
537
542
|
Op.loader = new Loader(Op);
|
|
538
543
|
Op.cache = {};
|
|
539
544
|
|
|
540
|
-
|
|
541
|
-
|
|
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);
|
|
542
551
|
|
|
543
552
|
puts = function(str) {
|
|
544
|
-
|
|
553
|
+
rb_stdout.m$puts(str);
|
|
545
554
|
};
|
|
546
|
-
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
Symbol table. All symbols are stored here.
|
|
551
|
-
*/
|
|
552
|
-
var symbol_table = { };
|
|
553
|
-
|
|
554
|
-
function class_s_new(cls, sup) {
|
|
555
|
-
var klass = define_class_id("AnonClass", sup || cObject);
|
|
556
|
-
return klass;
|
|
557
555
|
};
|
|
558
556
|
|