opal 0.0.1

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/runtime/module.js ADDED
@@ -0,0 +1,98 @@
1
+ /*
2
+ * module.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+ var RModule = { } ;
29
+
30
+ function rb_define_module(id) {
31
+ var module;
32
+ if (rb_const_defined(rb_cObject, id)) {
33
+ // module = cObject.$c_g(id);
34
+ module = rb_const_get(rb_cObject, id);
35
+ if (FL_TEST(module, T_MODULE)) {
36
+ return module;
37
+ }
38
+ throw id + ' is not a module';
39
+ }
40
+ module = rb_define_module_id(id);
41
+ rb_class_tbl[id] = module;
42
+ rb_const_set(rb_cObject, id, module);
43
+
44
+ return module;
45
+ };
46
+
47
+ function rb_define_module_under(outer, id) {
48
+ var module;
49
+ if (VN.const_defined_at(outer, id)) {
50
+ module = VN.const_get_at(outer, id);
51
+ if (module.type == VN.MODULE) {
52
+ return module;
53
+ }
54
+ VN.type_error(id + ' is not a module');
55
+ }
56
+ module = VN.define_module_id(id);
57
+ VN.const_set(outer, id, module);
58
+ VN.set_class_path(module, outer, name);
59
+ return module;
60
+ };
61
+
62
+ function rb_define_module_id(id) {
63
+ var mdl = rb_mod_create();
64
+ rb_name_class(mdl, id);
65
+ // VN.name_class(mdl, id);
66
+ // mdl.$name(id);
67
+ // mdl.$name(id);
68
+ return mdl;
69
+ };
70
+
71
+ function rb_mod_create() {
72
+ var m = class_alloc(T_MODULE, rb_cModule);
73
+ m.sup = rb_cObject;
74
+ return m;
75
+ }
76
+
77
+ // RModule.create = function() {
78
+ // var mdl = RClass.alloc(VN.MODULE, cModule);
79
+ // mdl.$super = cObject;
80
+ // return mdl;
81
+ // };
82
+
83
+ function rb_include_module(klass, module) {
84
+ // FIXME: need to check if already included, or its a parent etc etc.
85
+ klass.sup = rb_include_class_new(module, klass);
86
+ }
87
+
88
+
89
+ function rb_include_class_new(mod, sup) {
90
+ var klass = class_alloc(T_ICLASS, rb_cClass);
91
+ klass.iv_tbl = mod.iv_tbl;
92
+ klass.m_tbl = mod.m_tbl;
93
+ klass.sup = sup.sup;
94
+ klass.klass = mod;
95
+ // console.log('included class');
96
+ // console.log(klass);
97
+ return klass;
98
+ };
data/runtime/number.js ADDED
@@ -0,0 +1,148 @@
1
+ /*
2
+ * number.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+ var rb_cNumber;
29
+
30
+ function rb_num_plus(a, b) {
31
+ return a + b;
32
+ }
33
+
34
+ function rb_num_minus(a, b) {
35
+ return a - b;
36
+ }
37
+
38
+ function rb_num_mul(a, b) {
39
+ return a * b;
40
+ }
41
+
42
+ function rb_num_div(a, b) {
43
+ return a / b;
44
+ }
45
+
46
+ function rb_num_modulo(a, b) {
47
+ return a % b;
48
+ }
49
+
50
+ function rb_num_pow(a, b) {
51
+ return Math.pow(a, b);
52
+ }
53
+
54
+
55
+
56
+
57
+
58
+
59
+ function rb_num_gt(a, b) {
60
+ return a > b;
61
+ }
62
+
63
+ function rb_num_ge(a, b) {
64
+ return a >= b;
65
+ }
66
+
67
+ function rb_num_lt(a, b) {
68
+ return a < b;
69
+ }
70
+
71
+ function rb_num_le(a, b) {
72
+ return a <= b;
73
+ }
74
+
75
+
76
+ function Init_Number() {
77
+
78
+ rb_cNumber = rb_define_class("Number", rb_cObject);
79
+ Number.prototype.klass = rb_cNumber;
80
+ Number.prototype.flags = T_NUMBER;
81
+
82
+ // rb_define_method(rb_cNumber, "singleton_method_added", rb_num_sadded, 1);
83
+ // rb_include_module(rb_cNumber, rb_mComparable);
84
+ // rb_define_method(rb_cNumber, "initialize_copy", rb_num_init_copy, 1);
85
+ // rb_define_method(rb_cNumber, "coerce", rb_num_coerce, 1);
86
+
87
+ // rb_define_method(rb_cNumber, "+@", rb_num_uplus, 0);
88
+ // rb_define_method(rb_cNumber, "-@", rb_num_uminus, 0);
89
+ // rb_define_method(rb_cNumber, "<=>", rb_num_cmp, 1);
90
+ // rb_define_method(rb_cNumber, "eql?", rb_num_eql, 1);
91
+ // rb_define_method(rb_cNumber, "quo", rb_num_quo, 1);
92
+ // rb_define_method(rb_cNumber, "fdiv", rb_num_fdiv, 1);
93
+ // rb_define_method(rb_cNumber, "div", rb_num_div, 1);
94
+ // rb_define_method(rb_cNumber, "divmod", rb_num_divmod, 1);
95
+ // rb_define_method(rb_cNumber, "modulo", rb_num_modulo, 1);
96
+ // rb_define_method(rb_cNumber, "remainder", rb_num_remainder, 1);
97
+ // rb_define_method(rb_cNumber, "abs", rb_num_abs, 0);
98
+ // rb_define_method(rb_cNumber, "magnitude", rb_num_abs, 0);
99
+ // rb_define_method(rb_cNumber, "to_int", rb_num_to_i, 0);
100
+
101
+ // rb_define_method(rb_cNumber, "real?", rb_num_real_p, 0);
102
+ // rb_define_method(rb_cNumber, "integer?", rb_num_int_p, 0);
103
+ // rb_define_method(rb_cNumber, "zero?", rb_num_zero_p, 0);
104
+ // rb_define_method(rb_cNumber, "nonzero?", rb_num_nonzero_p, 0);
105
+
106
+ // rb_define_method(rb_cNumber, "floor", rb_num_floor, 0);
107
+ // rb_define_method(rb_cNumber, "ceil", rb_num_ceil, 0);
108
+ // rb_define_method(rb_cNumber, "round", rb_num_round, -1);
109
+ // rb_define_method(rb_cNumber, "truncate", rb_num_truncate, 0);
110
+ // rb_define_method(rb_cNumber, "step", rb_num_step, -1);
111
+
112
+ // rb_define_method(rb_cNumber, "odd?", rb_num_odd_p, 0);
113
+ // rb_define_method(rb_cNumber, "even?", rb_num_even_p, 0);
114
+ // rb_define_method(rb_cNumber, "upto", rb_num_upto, 1);
115
+ // rb_define_method(rb_cNumber, "downto", rb_num_downto, 1);
116
+ // rb_define_method(rb_cNumber, "times", rb_num_dotimes, 0);
117
+ // rb_define_method(rb_cNumber, "succ", rb_num_succ, 0);
118
+ // rb_define_method(rb_cNumber, "next", rb_num_succ, 0);
119
+ // rb_define_method(rb_cNumber, "pred", rb_num_pred, 0);
120
+ // rb_define_method(rb_cNumber, "chr", rb_num_chr, -1);
121
+ // rb_define_method(rb_cNumber, "ord", rb_num_ord, 0);
122
+ // rb_define_method(rb_cNumber, "to_i", rb_num_to_i, 0);
123
+ // rb_define_method(rb_cNumber, "to_s", rb_num_to_s, -1);
124
+ // rb_define_method(rb_cNumber, "to_f", rb_num_to_f, 0);
125
+
126
+ rb_define_method(rb_cNumber, "+", rb_num_plus, 1);
127
+ rb_define_method(rb_cNumber, "-", rb_num_minus, 1);
128
+ rb_define_method(rb_cNumber, "*", rb_num_mul, 1);
129
+ rb_define_method(rb_cNumber, "/", rb_num_div, 1);
130
+ rb_define_method(rb_cNumber, "%", rb_num_modulo, 1);
131
+ rb_define_method(rb_cNumber, "**", rb_num_pow, 1);
132
+
133
+ // rb_define_method(rb_cNumber, "==", rb_num_equal, 1);
134
+ // rb_define_method(rb_cNumber, "<=>", rb_num_cmp, 1);
135
+ rb_define_method(rb_cNumber, ">", rb_num_gt, 1);
136
+ rb_define_method(rb_cNumber, ">=", rb_num_ge, 1);
137
+ rb_define_method(rb_cNumber, "<", rb_num_lt, 1);
138
+ rb_define_method(rb_cNumber, "<=", rb_num_le, 1);
139
+
140
+ // rb_define_method(rb_cNumber, "~", rb_num_rev, 0);
141
+ // rb_define_method(rb_cNumber, "&", rb_num_and, 1);
142
+ // rb_define_method(rb_cNumber, "|", rb_num_or, 1);
143
+ // rb_define_method(rb_cNumber, "^", rb_num_xor, 1);
144
+ // rb_define_method(rb_cNumber, "[]", rb_num_aref, 1);
145
+
146
+ // rb_define_method(rb_cNumber, "<<", rb_num_lshift, 1);
147
+ // rb_define_method(rb_cNumber, ">>", rb_num_rshift, 1);
148
+ }
data/runtime/object.js ADDED
@@ -0,0 +1,522 @@
1
+ /*
2
+ * object.js
3
+ * opal
4
+ *
5
+ * Created by Adam Beynon.
6
+ * Copyright 2010 Adam Beynon.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+
28
+ /**
29
+ Core objects
30
+ */
31
+
32
+ var rb_cBasicObject, rb_cObject, rb_cModule, rb_cClass;
33
+ var rb_cNilClass;
34
+
35
+
36
+
37
+ // /**
38
+ // For compatibility
39
+ // */
40
+ // RObject.prototype.$i_g = function(id) {
41
+ // if (this.$iv_tbl[id] == undefined || this.$iv_tbl[id] == null) {
42
+ // return nil;
43
+ // }
44
+ // return this.$iv_tbl[id];
45
+ // };
46
+ //
47
+ // /*
48
+ // $ - call method
49
+ // @param id - method name
50
+ // @param args - array of all arguments
51
+ // */
52
+ // RObject.prototype.$ = function(id, args) {
53
+ // var method = this.$klass.$search_method(id);
54
+ //
55
+ // if (!method) {
56
+ // console.log(this);
57
+ // throw 'RObject#call cannot find method: ' + id ;
58
+ // }
59
+ // return method.apply(this, args) ;
60
+ // };
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+ /**
69
+ Call super method
70
+ */
71
+ var rb_supcall = function rb_supcall(from, self, id, args) {
72
+ var method = self.$klass.$search_super_method(from, id);
73
+ if (!method) throw 'RObject#call cannot find super method for: ' + id ;
74
+
75
+ switch(args.length) {
76
+ case 0: return method(self, id);
77
+ case 1: return method(self, id, args[0]);
78
+ case 2: return method(self, id, args[0], args[1]);
79
+ case 3: return method(self, id, args[0], args[1], args[2]);
80
+ case 4: return method(self, id, args[0], args[1], args[2], args[3]);
81
+ }
82
+
83
+ return method.apply(self, arguments);
84
+ };
85
+
86
+
87
+
88
+ // RClass.prototype.$search_super_method = function(from,id) {
89
+ // // get current
90
+ //
91
+ // /**
92
+ // Match func = from, to match current function
93
+ // THEN search by name from there up, otherwise, chains of more then
94
+ // 2 supers will keep rematching second super
95
+ // */
96
+ // var klass = this; var func;
97
+ // while (!((func = klass.$m_tbl[id]) && func == from)) {
98
+ // klass = klass.$super;
99
+ // if (!klass) return undefined;
100
+ // }
101
+ // // now skip up one
102
+ // klass = klass.$super;
103
+ // if (!klass) return undefined;
104
+ // while (!(func = klass.$m_tbl[id])) {
105
+ // klass = klass.$super;
106
+ // if(!klass) return undefined;
107
+ // }
108
+ // return func;
109
+ //
110
+ // //
111
+ // // var klass = this; var func;
112
+ // // while (!((func = klass.$m_tbl[id]) && func != from)) {
113
+ // // klass = klass.$super;
114
+ // // if(!klass) return undefined;
115
+ // // }
116
+ // //
117
+ // // var klass = this; var func;
118
+ // // // console.log('from');
119
+ // // // console.log(from);
120
+ // // // console.log('views');
121
+ // // // console.log(klass.$m_tbl[id]);
122
+ // // // console.log(klass.$m_tbl[id] === from);
123
+ // // // console.log(klass.$m_tbl[id]);
124
+ // // while (!((func = klass.$m_tbl[id]) && func != from)) {
125
+ // // klass = klass.$super;
126
+ // // if(!klass) return undefined;
127
+ // // }
128
+ // // // return func = klass.$m_tbl[id];
129
+ // // // return func = klass.$m_tbl[id];
130
+ // // return func;
131
+ //
132
+ // // var klass = this; var func ;
133
+ // //
134
+ // // while (!(func = klass.$m_tbl[id])) {
135
+ // // klass = klass.$super;
136
+ // // if (!klass) return undefined;
137
+ // // }
138
+ // // console.log('this point');
139
+ // // // we have the current impl, now we need to search for the super from this point..
140
+ // // klass = klass.$super;
141
+ // // if (!klass) return undefined;
142
+ // // while (!(func = klass.$m_tbl[id])) {
143
+ // // klass = klass.$super;
144
+ // // if (!klass) return undefined;
145
+ // // }
146
+ // // return func;
147
+ // };
148
+
149
+ // /**
150
+ // For compatibility
151
+ // */
152
+ // var VN$sup = rb_supcall;
153
+ //
154
+ // /**
155
+ // Call super
156
+ // - from = callee
157
+ // */
158
+ // RObject.prototype.$sup = function(from, id, args) {
159
+ // // console.log('callee');
160
+ // // console.log(from);
161
+ // var method = this.$klass.$search_super_method(from, id);
162
+ // if (!method) throw 'RObject#call cannot find super method for: ' + id ;
163
+ // // console.log('got super');
164
+ // // console.log(method);
165
+ // return method.apply(this, args) ;
166
+ // };
167
+ //
168
+ // /**
169
+ // We need to copy some of RClass' methods for singletons
170
+ // */
171
+ // RObject.prototype.$def_s = RClass.prototype.$def_s;
172
+ // RObject.prototype.$make_metaclass = RClass.prototype.$make_metaclass;
173
+
174
+
175
+ /*
176
+ * object.js
177
+ * vienna
178
+ *
179
+ * Created by Adam Beynon.
180
+ * Copyright 2009 Adam Beynon.
181
+ *
182
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
183
+ * of this software and associated documentation files (the "Software"), to deal
184
+ * in the Software without restriction, including without limitation the rights
185
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
186
+ * copies of the Software, and to permit persons to whom the Software is
187
+ * furnished to do so, subject to the following conditions:
188
+ *
189
+ * The above copyright notice and this permission notice shall be included in
190
+ * all copies or substantial portions of the Software.
191
+ *
192
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
193
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
194
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
195
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
196
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
197
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
198
+ * THE SOFTWARE.
199
+ */
200
+
201
+ function rb_obj_alloc(klass) {
202
+ return rb_class_allocate_instance(klass);
203
+ // return rb_funcall(klass, 'allocate', 0);
204
+ }
205
+
206
+ function rb_obj_dummy() {
207
+ return nil;
208
+ }
209
+
210
+ function rb_class_allocate_instance(klass) {
211
+ var o = new RObject();
212
+ o.klass = klass;
213
+ FL_SET(o, T_OBJECT);
214
+ return o;
215
+ }
216
+
217
+ function rb_obj_equal(self, obj) {
218
+ if (self == obj) return true;
219
+ return false;
220
+ }
221
+
222
+ function rb_obj_not(self) {
223
+ return RTEST(self) ? false : true;
224
+ }
225
+
226
+ function rb_obj_not_equal(self, obj) {
227
+ var r = rb_funcall(self, "==", obj);
228
+ return RTEST(r) ? false : true;
229
+ }
230
+
231
+ function rb_false() {
232
+ return false;
233
+ }
234
+
235
+ function rb_true() {
236
+ return true;
237
+ }
238
+
239
+ function rb_equal(self, obj) {
240
+ var r;
241
+ if (self == obj) return true;
242
+ r = rb_funcall(self, "==", obj);
243
+ if (RTEST(r)) return true;
244
+ return false;
245
+ }
246
+
247
+ function rb_obj_match() {
248
+ return nil;
249
+ }
250
+
251
+ function rb_obj_not_match(self, obj) {
252
+ var r = rb_funcall(self, "=~", obj);
253
+ return RTEST(r) ? false : true;
254
+ }
255
+
256
+ function rb_class_real(klass) {
257
+ if (!klass) return nil;
258
+ while (FL_TEST(klass, FL_SINGLETON) || FL_TEST(klass, T_ICLASS)) {
259
+ klass = klass.sup;
260
+ }
261
+ return klass;
262
+ }
263
+
264
+ function rb_obj_class(self) {
265
+ return rb_class_real(self.klass);
266
+ }
267
+
268
+ function rb_obj_clone(self) {
269
+ return self;
270
+ }
271
+
272
+ function rb_obj_dup(self) {
273
+ return self;
274
+ }
275
+
276
+ function rb_obj_init_copy(self) {
277
+ return self;
278
+ }
279
+
280
+ function rb_any_to_s(self) {
281
+ var c = rb_obj_classname(self);
282
+ return "<" + c + ":0x000000>";
283
+ }
284
+
285
+ function rb_obj_inspect(self) {
286
+ return rb_any_to_s(self);
287
+ }
288
+
289
+ function rb_class_new_instance(argc, argv, klass) {
290
+ var o = rb_obj_alloc(klass);
291
+ // initialize..
292
+ var call_args = [o, "initialize", argc];
293
+ for (var i = 0; i < argc; i++) {
294
+ call_args.push(argv[i]);
295
+ }
296
+ rb_funcall.apply(o, call_args);
297
+
298
+ return o;
299
+ };
300
+
301
+ function rb_f_puts(argc, argv, recv) {
302
+ for (var i = 0; i < argc; i++) {
303
+ console.log(argv[i]);
304
+ }
305
+ };
306
+
307
+ function rb_mod_attr_reader(argc, argv, recv) {
308
+ for (var i = 0; i < argc; i++) {
309
+ var s = argv[i].ptr;
310
+ var f = new Function('r', 'return rb_ivar_get(r, "@' + s + '");');
311
+ rb_define_method(recv, s, f, 0);
312
+ }
313
+ return nil;
314
+ };
315
+
316
+ function rb_mod_attr_writer(argc, argv, recv) {
317
+ for (var i = 0; i < argc; i++) {
318
+ var s = argv[i].ptr;
319
+ var f = new Function('r', 'v', 'return rb_ivar_set(r, "@' + s + '", v);');
320
+ rb_define_method(recv, s + '=', f, 1);
321
+ }
322
+ return nil;
323
+ };
324
+
325
+ function rb_mod_attr_accessor(argc, argv, recv) {
326
+ rb_mod_attr_reader(argc, argv, recv);
327
+ rb_mod_attr_writer(argc, argv, recv);
328
+ return nil;
329
+ };
330
+
331
+ function rb_mod_const_set(mod, id, val) {
332
+ // FIXME: should really check that id is valid... i.e. does it start with an
333
+ // uppercase letter.
334
+ rb_const_set(mod, id, val);
335
+ return val;
336
+ };
337
+
338
+ function rb_obj_respond_to(argc, argv, obj) {
339
+ // first arg is a symbol to use
340
+ var id = argv[0].ptr;
341
+ var f = rb_search_method(obj.klass, id);
342
+ if (f) return true;
343
+ return false;
344
+ };
345
+
346
+
347
+
348
+
349
+
350
+ function Init_Object() {
351
+ var metaclass;
352
+ rb_cBasicObject = boot_defclass('BasicObject', null);
353
+ rb_cObject = boot_defclass('Object', rb_cBasicObject);
354
+ rb_cModule = boot_defclass('Module', rb_cObject);
355
+ rb_cClass = boot_defclass('Class', rb_cModule);
356
+
357
+ // hmm, we jhave to set the const again... or should we?
358
+ rb_const_set(rb_cObject, "BaiscObject", rb_cBasicObject);
359
+
360
+ metaclass = rb_make_metaclass(rb_cBasicObject, rb_cClass);
361
+ metaclass = rb_make_metaclass(rb_cObject, metaclass);
362
+ metaclass = rb_make_metaclass(rb_cModule, metaclass);
363
+ metaclass = rb_make_metaclass(rb_cClass, metaclass);
364
+
365
+ boot_defmetametaclass(rb_cModule, metaclass);
366
+ boot_defmetametaclass(rb_cObject, metaclass);
367
+ boot_defmetametaclass(rb_cBasicObject, metaclass);
368
+
369
+ rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_dummy, 0);
370
+ // FIXME: wtf made this break?
371
+ // rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance);
372
+ rb_define_method(rb_cBasicObject, "==", rb_obj_equal, 1);
373
+ rb_define_method(rb_cBasicObject, "equal?", rb_obj_equal, 1);
374
+ rb_define_method(rb_cBasicObject, "!", rb_obj_not, 0);
375
+ rb_define_method(rb_cBasicObject, "!=", rb_obj_not_equal, 1);
376
+
377
+ rb_define_private_method(rb_cBasicObject, "singleton_method_added", rb_obj_dummy, 1);
378
+ rb_define_private_method(rb_cBasicObject, "singleton_method_removed", rb_obj_dummy, 1);
379
+ rb_define_private_method(rb_cBasicObject, "singleton_method_undefined", rb_obj_dummy, 1);
380
+
381
+ rb_mKernel = rb_define_module("Kernel");
382
+ rb_include_module(rb_cObject, rb_mKernel);
383
+ rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
384
+ rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1);
385
+ rb_define_private_method(rb_cModule, "extended", rb_obj_dummy, 1);
386
+ rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
387
+ rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
388
+ rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
389
+
390
+ rb_define_method(rb_mKernel, "nil?", rb_false, 0);
391
+ rb_define_method(rb_mKernel, "===", rb_equal, 1);
392
+ rb_define_method(rb_mKernel, "=~", rb_obj_match, 1);
393
+ rb_define_method(rb_mKernel, "!~", rb_obj_not_match, 1);
394
+ rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
395
+
396
+ rb_define_method(rb_mKernel, "class", rb_obj_class, 0);
397
+ rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);
398
+ rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0);
399
+ rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);
400
+
401
+ // rb_define_method(rb_mKernel, "taint", rb_obj_taint, 0);
402
+ // rb_define_method(rb_mKernel, "tainted?", rb_obj_tainted, 0);
403
+ // rb_define_method(rb_mKernel, "untaint", rb_obj_untaint, 0);
404
+ // rb_define_method(rb_mKernel, "untrust", rb_obj_untrust, 0);
405
+ // rb_define_method(rb_mKernel, "untrusted?", rb_obj_untrusted, 0);
406
+ // rb_define_method(rb_mKernel, "trust", rb_obj_trust, 0);
407
+ // rb_define_method(rb_mKernel, "freeze", rb_obj_freeze, 0);
408
+ // rb_define_method(rb_mKernel, "frozen?", rb_obj_frozen_p, 0);
409
+
410
+ rb_define_method(rb_mKernel, "respond_to?", rb_obj_respond_to, -1);
411
+
412
+ rb_define_method(rb_mKernel, "puts", rb_f_puts, -1);
413
+
414
+ rb_define_method(rb_mKernel, "to_s", rb_any_to_s, 0);
415
+ rb_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0);
416
+ // rb_define_method(rb_mKernel, "methods", rb_obj_methods, -1);
417
+ // rb_define_method(rb_mKernel, "singleton_methods", rb_obj_singleton_methods, -1);
418
+ // rb_define_method(rb_mKernel, "protected_methods", rb_obj_protected_methods, -1);
419
+ // rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, -1);
420
+ // rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, -1);
421
+ // rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0);
422
+ // rb_define_method(rb_mKernel, "instance_variable_get", rb_obj_ivar_get, 1);
423
+ // rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set, 2);
424
+ // rb_define_method(rb_mKernel, "instance_variable_defined?", rb_obj_ivar_defined, 1);
425
+ // rb_define_private_method(rb_mKernel, "remove_instance_variable", rb_obj_remove_instance_variable, 1);
426
+ //
427
+ // rb_define_method(rb_mKernel, "instance_of?", rb_obj_is_instance_of, 1);
428
+ // rb_define_method(rb_mKernel, "kind_of?", rb_obj_is_kind_of, 1);
429
+ // rb_define_method(rb_mKernel, "is_a?", rb_obj_is_kind_of, 1);
430
+ // rb_define_method(rb_mKernel, "tap", rb_obj_tap, 0);
431
+ //
432
+ // rb_define_global_function("sprintf", rb_f_sprintf, -1);
433
+ // rb_define_global_function("format", rb_f_sprintf, -1);
434
+ //
435
+ // rb_define_global_function("Integer", rb_f_integer, 1);
436
+ // rb_define_global_function("Float", rb_f_float, 1);
437
+ //
438
+ // rb_define_global_function("String", rb_f_string, 1);
439
+ // rb_define_global_function("Array", rb_f_array, 1);
440
+
441
+ rb_cNilClass = rb_define_class("NilClass", rb_cObject);
442
+ // rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0);
443
+ // rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0);
444
+ // rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0);
445
+ // rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0);
446
+ // rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0);
447
+ // rb_define_method(rb_cNilClass, "&", false_and, 1);
448
+ // rb_define_method(rb_cNilClass, "|", false_or, 1);
449
+ // rb_define_method(rb_cNilClass, "^", false_xor, 1);
450
+ nil = { flags: T_OBJECT, klass: rb_cNilClass };
451
+ //
452
+ // rb_define_method(rb_cNilClass, "nil?", rb_true, 0);
453
+ // rb_undef_alloc_func(rb_cNilClass);
454
+ // rb_undef_method(rb_cNilClass.klass, "new");
455
+ // rb_define_global_const("NIL", Qnil);
456
+ //
457
+ // rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0);
458
+ // rb_define_method(rb_cModule, "===", rb_mod_eqq, 1);
459
+ // rb_define_method(rb_cModule, "==", rb_obj_equal, 1);
460
+ // rb_define_method(rb_cModule, "<=>", rb_mod_cmp, 1);
461
+ // rb_define_method(rb_cModule, "<", rb_mod_lt, 1);
462
+ // rb_define_method(rb_cModule, "<=", rb_class_inherited_p, 1);
463
+ // rb_define_method(rb_cModule, ">", rb_mod_gt, 1);
464
+ // rb_define_method(rb_cModule, ">=", rb_mod_ge, 1);
465
+ // rb_define_method(rb_cModule, "initialize_copy", rb_mod_init_copy, 1);
466
+ // rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0);
467
+ // rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0);
468
+ // rb_define_method(rb_cModule, "include?", rb_mod_include_p, 1);
469
+ // rb_define_method(rb_cModule, "name", rb_mod_name, 0);
470
+ // rb_define_method(rb_cModule, "ancestors", rb_mod_ancestors, 0);
471
+ //
472
+ // rb_define_private_method(rb_cModule, "attr", rb_mod_attr, -1);
473
+ rb_define_private_method(rb_cModule, "attr_reader", rb_mod_attr_reader, -1);
474
+ rb_define_private_method(rb_cModule, "attr_writer", rb_mod_attr_writer, -1);
475
+ rb_define_private_method(rb_cModule, "attr_accessor", rb_mod_attr_accessor, -1);
476
+ //
477
+ // rb_define_alloc_func(rb_cModule, rb_module_s_alloc);
478
+ // rb_define_method(rb_cModule, "initialize", rb_mod_initialize, 0);
479
+ // rb_define_method(rb_cModule, "instance_methods", rb_class_instance_methods, -1);
480
+ // rb_define_method(rb_cModule, "public_instance_methods", rb_class_public_instance_methods, -1);
481
+ // rb_define_method(rb_cModule, "protected_instance_methods", rb_class_protected_instance_methods, -1);
482
+ // rb_define_method(rb_cModule, "private_instance_methods", rb_class_private_instance_methods, -1);
483
+ //
484
+ // rb_define_method(rb_cModule, "constants", rb_mod_constants, -1);
485
+ // rb_define_method(rb_cModule, "const_get", rb_mod_const_get, -1);
486
+ rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2);
487
+ // rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, -1);
488
+ // rb_define_private_method(rb_cModule, "remove_const", rb_mod_remove_const, 1);
489
+ // rb_define_method(rb_cModule, "const_missing", rb_mod_const_missing, 1);
490
+ // rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0);
491
+ // rb_define_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1);
492
+ // rb_define_method(rb_cModule, "class_variable_get", rb_mod_cvar_get, 1);
493
+ // rb_define_method(rb_cModule, "class_variable_set", rb_mod_cvar_set, 2);
494
+ // rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
495
+ //
496
+ rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
497
+ rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
498
+ // rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
499
+ // rb_define_method(rb_cClass, "initialize_copy", rb_class_init_copy, 1);
500
+ // rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
501
+ // rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
502
+ // rb_undef_method(rb_cClass, "extend_object");
503
+ // rb_undef_method(rb_cClass, "append_features");
504
+ //
505
+ // rb_cTrueClass = rb_define_class("TrueClass", rb_cObject);
506
+ // rb_define_method(rb_cTrueClass, "to_s", true_to_s, 0);
507
+ // rb_define_method(rb_cTrueClass, "&", true_and, 1);
508
+ // rb_define_method(rb_cTrueClass, "|", true_or, 1);
509
+ // rb_define_method(rb_cTrueClass, "^", true_xor, 1);
510
+ // rb_undef_alloc_func(rb_cTrueClass);
511
+ // rb_undef_method(rb_cTrueClass.klass, "new");
512
+ // rb_define_global_const("TRUE", true);
513
+ //
514
+ // rb_cFalseClass = rb_define_class("FalseClass", rb_cObject);
515
+ // rb_define_method(rb_cFalseClass, "to_s", false_to_s, 0);
516
+ // rb_define_method(rb_cFalseClass, "&", false_and, 1);
517
+ // rb_define_method(rb_cFalseClass, "|", false_or, 1);
518
+ // rb_define_method(rb_cFalseClass, "^", false_xor, 1);
519
+ // rb_undef_alloc_func(rb_cFalseClass);
520
+ // rb_undef_method(rb_cFalseClass.klass, "new");
521
+ // rb_define_global_const("FALSE", false);
522
+ }