opal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ build
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "opal"
8
+ gem.summary = %q{Ruby runtime for the browser}
9
+ gem.description = %q{Ruby runtime for the browser}
10
+ gem.email = "adam@adambeynon.com"
11
+ gem.homepage = "http://github.com/adambeynon/opal"
12
+ gem.authors = ["Adam Beynon"]
13
+ gem.add_development_dependency "vienna", ">= 0.0.3"
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "opal #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/docs/jarv.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ == JARV
2
+
3
+ JARV is a (bad) name for the op codes used by this ruby implementation. It is heavily influenced by the opcodes used by ruby. JARV stands for (Javascript/Just/JSON) Another Ruby Vm. Hence the prepended "bad name". JARV takes out some of the data encoded within the instruction sequences, to provide the bare minimum to run the opcodes successfully. The following in a structure of an ISeq, which is represented as an array at runtime in javascript:
4
+
5
+ [args, locals, name, filename, type, local_names, args, catch, jumps, opcodes]
6
+
7
+ === args
8
+
9
+ The total number of args that the iseq takes. For methods, this is simply the number of method arguments. Some iseqs, like top or class, do not actually take
10
+ any arguments, so this will be 0.
11
+
12
+ === locals
13
+
14
+ The total number of locals in the iseq. For every var defined, a local is needed, so this represents the size of the local var. GETLOCAL etc reference an index in this set, so an array is essentially used to store these. Args and locals are stored together and referenced using the same idx path, where args are references then locals, in a joint array.
15
+
16
+
17
+
18
+ s = "["
19
+ s << %{#{@args.length},}
20
+ s << %{#{@locals.length},}
21
+ s << %{"#{@name}",}
22
+ s << %{"#{@filename}",}
23
+ s << %{#{@type},}
24
+ s << %{0,}
25
+ s << %{[],}
26
+ s << %{[#{@opcodes.join(",")}]}
27
+ s << %{]}
data/lib/opal.rb ADDED
@@ -0,0 +1,29 @@
1
+ #
2
+ # opal.rb
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
+ module Opal
28
+
29
+ end
data/runtime/array.js ADDED
@@ -0,0 +1,153 @@
1
+ /*
2
+ * array.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
+ var rb_cArray;
28
+
29
+ if (!Array.prototype.indexOf){
30
+ Array.prototype.indexOf = function(obj){
31
+ for (var i = 0; i< this.length; i++){
32
+ if (this[i] == obj){
33
+ return i;
34
+ }
35
+ }
36
+ return -1;
37
+ }
38
+ }
39
+
40
+ function rb_ary_each(ary) {
41
+ var i;
42
+ // if (!rb_block_given_p()) {
43
+ // throw "return enumerator thingy"
44
+ // }
45
+ for (i = 0; i < ary.length; i++) {
46
+ rb_yield(ary[i]);
47
+ // console.log("should yield: " + ary[i]);
48
+ }
49
+ return ary;
50
+ }
51
+
52
+ function Init_Array() {
53
+
54
+ rb_cArray = rb_define_class("Array", rb_cObject);
55
+ Array.prototype.klass = rb_cArray;
56
+
57
+ // rb_include_module(rb_cArray, rb_mEnumerable);
58
+
59
+ // rb_define_alloc_func(rb_cArray, rb_ary_alloc);
60
+ // rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
61
+ // rb_define_singleton_method(rb_cArray, "try_convert", rb_ary_s_try_convert, 1);
62
+ // rb_define_method(rb_cArray, "initialize", rb_ary_initialize, -1);
63
+ // rb_define_method(rb_cArray, "initialize_copy", rb_ary_replace, 1);
64
+
65
+ // rb_define_method(rb_cArray, "to_s", rb_ary_inspect, 0);
66
+ // rb_define_method(rb_cArray, "inspect", rb_ary_inspect, 0);
67
+ // rb_define_method(rb_cArray, "to_a", rb_ary_to_a, 0);
68
+ // rb_define_method(rb_cArray, "to_ary", rb_ary_to_ary_m, 0);
69
+ // rb_define_method(rb_cArray, "frozen?", rb_ary_frozen_p, 0);
70
+
71
+ // rb_define_method(rb_cArray, "==", rb_ary_equal, 1);
72
+ // rb_define_method(rb_cArray, "eql?", rb_ary_eql, 1);
73
+ // rb_define_method(rb_cArray, "hash", rb_ary_hash, 0);
74
+
75
+ // rb_define_method(rb_cArray, "[]", rb_ary_aref, -1);
76
+ // rb_define_method(rb_cArray, "[]=", rb_ary_aset, -1);
77
+ // rb_define_method(rb_cArray, "at", rb_ary_at, 1);
78
+ // rb_define_method(rb_cArray, "fetch", rb_ary_fetch, -1);
79
+ // rb_define_method(rb_cArray, "first", rb_ary_first, -1);
80
+ // rb_define_method(rb_cArray, "last", rb_ary_last, -1);
81
+ // rb_define_method(rb_cArray, "concat", rb_ary_concat, 1);
82
+ // rb_define_method(rb_cArray, "<<", rb_ary_push, 1);
83
+ // rb_define_method(rb_cArray, "push", rb_ary_push_m, -1);
84
+ // rb_define_method(rb_cArray, "pop", rb_ary_pop_m, -1);
85
+ // rb_define_method(rb_cArray, "shift", rb_ary_shift_m, -1);
86
+ // rb_define_method(rb_cArray, "unshift", rb_ary_unshift_m, -1);
87
+ // rb_define_method(rb_cArray, "insert", rb_ary_insert, -1);
88
+ rb_define_method(rb_cArray, "each", rb_ary_each, 0);
89
+ // rb_define_method(rb_cArray, "each_index", rb_ary_each_index, 0);
90
+ // rb_define_method(rb_cArray, "reverse_each", rb_ary_reverse_each, 0);
91
+ // rb_define_method(rb_cArray, "length", rb_ary_length, 0);
92
+ // rb_define_alias(rb_cArray, "size", "length");
93
+ // rb_define_method(rb_cArray, "empty?", rb_ary_empty_p, 0);
94
+ // rb_define_method(rb_cArray, "find_index", rb_ary_index, -1);
95
+ // rb_define_method(rb_cArray, "index", rb_ary_index, -1);
96
+ // rb_define_method(rb_cArray, "rindex", rb_ary_rindex, -1);
97
+ // rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
98
+ // rb_define_method(rb_cArray, "reverse", rb_ary_reverse_m, 0);
99
+ // rb_define_method(rb_cArray, "reverse!", rb_ary_reverse_bang, 0);
100
+ // rb_define_method(rb_cArray, "sort", rb_ary_sort, 0);
101
+ // rb_define_method(rb_cArray, "sort!", rb_ary_sort_bang, 0);
102
+ // rb_define_method(rb_cArray, "collect", rb_ary_collect, 0);
103
+ // rb_define_method(rb_cArray, "collect!", rb_ary_collect_bang, 0);
104
+ // rb_define_method(rb_cArray, "map", rb_ary_collect, 0);
105
+ // rb_define_method(rb_cArray, "map!", rb_ary_collect_bang, 0);
106
+ // rb_define_method(rb_cArray, "select", rb_ary_select, 0);
107
+ // rb_define_method(rb_cArray, "values_at", rb_ary_values_at, -1);
108
+ // rb_define_method(rb_cArray, "delete", rb_ary_delete, 1);
109
+ // rb_define_method(rb_cArray, "delete_at", rb_ary_delete_at_m, 1);
110
+ // rb_define_method(rb_cArray, "delete_if", rb_ary_delete_if, 0);
111
+ // rb_define_method(rb_cArray, "reject", rb_ary_reject, 0);
112
+ // rb_define_method(rb_cArray, "reject!", rb_ary_reject_bang, 0);
113
+ // rb_define_method(rb_cArray, "zip", rb_ary_zip, -1);
114
+ // rb_define_method(rb_cArray, "transpose", rb_ary_transpose, 0);
115
+ // rb_define_method(rb_cArray, "replace", rb_ary_replace, 1);
116
+ // rb_define_method(rb_cArray, "clear", rb_ary_clear, 0);
117
+ // rb_define_method(rb_cArray, "fill", rb_ary_fill, -1);
118
+ // rb_define_method(rb_cArray, "include?", rb_ary_includes, 1);
119
+ // rb_define_method(rb_cArray, "<=>", rb_ary_cmp, 1);
120
+
121
+ // rb_define_method(rb_cArray, "slice", rb_ary_aref, -1);
122
+ // rb_define_method(rb_cArray, "slice!", rb_ary_slice_bang, -1);
123
+
124
+ // rb_define_method(rb_cArray, "assoc", rb_ary_assoc, 1);
125
+ // rb_define_method(rb_cArray, "rassoc", rb_ary_rassoc, 1);
126
+
127
+ // rb_define_method(rb_cArray, "+", rb_ary_plus, 1);
128
+ // rb_define_method(rb_cArray, "*", rb_ary_times, 1);
129
+
130
+ // rb_define_method(rb_cArray, "-", rb_ary_diff, 1);
131
+ // rb_define_method(rb_cArray, "&", rb_ary_and, 1);
132
+ // rb_define_method(rb_cArray, "|", rb_ary_or, 1);
133
+
134
+ // rb_define_method(rb_cArray, "uniq", rb_ary_uniq, 0);
135
+ // rb_define_method(rb_cArray, "uniq!", rb_ary_uniq_bang, 0);
136
+ // rb_define_method(rb_cArray, "compact", rb_ary_compact, 0);
137
+ // rb_define_method(rb_cArray, "compact!", rb_ary_compact_bang, 0);
138
+ // rb_define_method(rb_cArray, "flatten", rb_ary_flatten, -1);
139
+ // rb_define_method(rb_cArray, "flatten!", rb_ary_flatten_bang, -1);
140
+ // rb_define_method(rb_cArray, "count", rb_ary_count, -1);
141
+ // rb_define_method(rb_cArray, "shuffle!", rb_ary_shuffle_bang, 0);
142
+ // rb_define_method(rb_cArray, "shuffle", rb_ary_shuffle, 0);
143
+ // rb_define_method(rb_cArray, "sample", rb_ary_sample, -1);
144
+ // rb_define_method(rb_cArray, "cycle", rb_ary_cycle, -1);
145
+ // rb_define_method(rb_cArray, "permutation", rb_ary_permutation, -1);
146
+ // rb_define_method(rb_cArray, "combination", rb_ary_combination, 1);
147
+ // rb_define_method(rb_cArray, "product", rb_ary_product, -1);
148
+
149
+ // rb_define_method(rb_cArray, "take", rb_ary_take, 1);
150
+ // rb_define_method(rb_cArray, "take_while", rb_ary_take_while, 0);
151
+ // rb_define_method(rb_cArray, "drop", rb_ary_drop, 1);
152
+ // rb_define_method(rb_cArray, "drop_while", rb_ary_drop_while, 0);
153
+ }
data/runtime/class.js ADDED
@@ -0,0 +1,469 @@
1
+ /*
2
+ * class.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
+ function rb_class_inherited(super_class, klass) {
29
+ if (!super_class) super_class = rb_cObject ;
30
+ // return rb_funcall(super_class, "inherited", klass);
31
+ };
32
+
33
+ function rb_define_class(id, super_class) {
34
+ var k;
35
+ // if already defined, just ensure right type then return existing class/mod.
36
+ if (rb_const_defined(rb_cObject, id)) {
37
+ k = rb_const_get(rb_cObject, id);
38
+ if (!(k.flags & T_CLASS)) {
39
+ throw id + " is not a class"
40
+ }
41
+ if (k.sup != super_class) {
42
+ if (k != rb_cObject) {
43
+ throw id + " is already defined"
44
+ }
45
+ }
46
+ return k
47
+ }
48
+ if (!super_class) {
49
+ console.log("no superclass given for " + id + " . Object assumed");
50
+ }
51
+ k = rb_define_class_id(id, super_class);
52
+ rb_class_tbl[id] = k;
53
+
54
+ // class bundle...?
55
+ // rb_ivar_set(k, '__bundle__', window.vn_current_bundle);
56
+
57
+ rb_name_class(k, id);
58
+ rb_const_set(rb_cObject, id, k);
59
+ rb_class_inherited(super_class, k);
60
+ return k;
61
+ }
62
+
63
+ function rb_define_class_under(outer, id, super_klass) {
64
+ var klass;
65
+ // if already defined in context... just ensure it is a macthing class def
66
+ /**
67
+ this should be const_defined_at
68
+ */
69
+ if (rb_const_defined_at(outer, id)) {
70
+ // klass = VN.const_get_at(outer, id);
71
+ /**
72
+ this should be const_get_at
73
+ */
74
+ // klass = outer.$c_g_a(id);
75
+ klass = rb_const_get_at(outer, id);
76
+ // console.log(klass);
77
+ // if (!(klass.flags & VN.CLASS) {
78
+ // VN.type_error(id + ' is not a class');
79
+ // }
80
+ // if (RClass.real(klass.$super) != super_klass) {
81
+ // // avoid error for cObject
82
+ // if (klass != cObject) {
83
+ // VN.name_error(id + ' is already defined');
84
+ // }
85
+ //
86
+ // }
87
+ return klass;
88
+ }
89
+ // not existing...
90
+ if (!super_klass) {
91
+ VN.warning('no super class for `' + VN.class2name(outer), + '::' + id + '`, Object assumed');
92
+ }
93
+ klass = rb_define_class_id(id, super_klass);
94
+
95
+ rb_name_class(klass, id);
96
+ rb_const_set(outer, id, klass);
97
+ rb_class_inherited(super_klass, klass);
98
+
99
+ return klass;
100
+ };
101
+
102
+ RClass.class2name = function(klass) {
103
+ return klass.$class_name();
104
+ };
105
+
106
+ RClass.obj_classname = function(obj) {
107
+ return VN.class2name(obj.$klass);
108
+ };
109
+
110
+ function make_metametaclass(metaclass) {
111
+ console.log("wwowow");
112
+ var metametaclass, super_of_metaclass;
113
+
114
+ if (metaclass.klass == metaclass) {
115
+ // console.log(1);
116
+ metametaclass = rb_class_boot(null);
117
+ metametaclass.klass = metametaclass;
118
+ }
119
+ else {
120
+ // console.log(2);
121
+ metametaclass = rb_class_boot(null);
122
+ metametaclass.klass = metaclass.klass.klass == metaclass.klass ? make_metametaclass(metaclass.klass) : metaclass.klass.klass;
123
+ }
124
+ // console.log(1);
125
+ FL_SET(metametaclass, FL_SINGLETON);
126
+ // console.log(2);
127
+ rb_singleton_class_attached(metametaclass, metaclass);
128
+ metaclass.klass = metametaclass;
129
+
130
+ super_of_metaclass = metaclass.sup;
131
+ while (FL_TEST(super_of_metaclass, T_ICLASS)) {
132
+ super_of_metaclass = super_of_metaclass.sup;
133
+ }
134
+
135
+ metametaclass.sup = rb_ivar_get(super_of_metaclass.klass, '__attached__') == super_of_metaclass ? super_of_metaclass.klass : make_metametaclass(super_of_metaclass);
136
+ return metametaclass;
137
+ };
138
+
139
+ function rb_class_real(klass) {
140
+ while (klass.flags & FL_SINGLETON) klass = klass.sup;
141
+ return klass;
142
+ }
143
+
144
+ RClass.real = function(klass) {
145
+ while ((klass.$singleton == true) || (klass.$type == VN.ICLASS)) {
146
+ klass = klass.$super
147
+ }
148
+ return klass
149
+ };
150
+
151
+ function class_alloc(type, klass) {
152
+ var o = new RClass();
153
+ o.klass = klass;
154
+ o.flags |= type;
155
+ return o;
156
+ }
157
+
158
+ function rb_class_boot(super_class) {
159
+ var k = class_alloc(T_CLASS, rb_cClass);
160
+ k.sup = super_class;
161
+ return k;
162
+ }
163
+
164
+ function rb_check_inheritable(super_class) {
165
+ if (!FL_TEST(super_class, T_CLASS)) {
166
+ throw 'super class must be a Class (' + VN.obj_classname(super_klass) + ' given)';
167
+ }
168
+ if (super_class.flags & FL_SINGLETON) {
169
+ throw 'can\'t make a subclass of singleton class';
170
+ }
171
+ };
172
+
173
+ function rb_class_create(super_klass) {
174
+ rb_check_inheritable(super_klass);
175
+
176
+ if (super_klass == rb_cClass) {
177
+ VN.raise(VN.TypeError, "can't make subclass of Class")
178
+ }
179
+ return rb_class_boot(super_klass);
180
+ };
181
+
182
+ function rb_define_class_id(id, super_klass) {
183
+ var klass;
184
+ if (!super_klass) super_klass = rb_cObject;
185
+ klass = rb_class_create(super_klass);
186
+ rb_make_metaclass(klass, super_klass.klass);
187
+ return klass;
188
+ };
189
+
190
+ function rb_singleton_class(obj) {
191
+ var klass;
192
+ // console.log(obj);
193
+ // console.log("here");
194
+ if (FL_TEST(obj, T_NUMBER) || FL_TEST(obj, T_SYMBOL)) {
195
+ console.log(obj);
196
+ throw 'can\'t define singleton';
197
+ }
198
+ // console.log("yeap");
199
+ if (FL_TEST(obj.klass, FL_SINGLETON) && rb_ivar_get(obj.klass, '__attached__') == obj) {
200
+ klass = obj.klass;
201
+ }
202
+ else {
203
+ // klass = RClass.make_metaclass(obj, obj.$klass);
204
+ // console.log(obj);
205
+ // klass = obj.$make_metaclass(obj.$klass) ;
206
+ klass = rb_make_metaclass(obj, obj.klass);
207
+ }
208
+ // console.log("nearly done");
209
+
210
+ if (FL_TEST(obj, T_CLASS)) {
211
+ if (rb_ivar_get(klass.klass, '__attached__') != klass) {
212
+ // console.log("this far down");
213
+ // console.log(klass);
214
+
215
+ //FIXME: def need to fix this.!!!!!!!!!!!!! uncomment basically.
216
+ // make_metametaclass(klass);
217
+ }
218
+ }
219
+ // console.log("completely done");
220
+
221
+ return klass;
222
+ };
223
+
224
+ function rb_name_class(klass, id) {
225
+ rb_ivar_set(klass, '__classid__', id);
226
+ }
227
+
228
+ // RClass.prototype.$class_name = function() {
229
+ // return VN.class_path(klass.$real());
230
+ // };
231
+
232
+ function rb_make_metaclass(klass, super_class) {
233
+ if (FL_TEST(klass, T_CLASS) && FL_TEST(klass, FL_SINGLETON)) {
234
+ return make_metametaclass(klass);
235
+ }
236
+ else {
237
+ var meta = rb_class_boot(super_class);
238
+ FL_SET(meta, FL_SINGLETON);
239
+ klass.klass = meta;
240
+ rb_singleton_class_attached(meta, klass);
241
+
242
+ var metasuper = meta.klass;
243
+ if (metasuper) {
244
+ meta.klass = metasuper;
245
+ }
246
+ return meta;
247
+ }
248
+ }
249
+
250
+ function rb_singleton_class_attached(klass, obj) {
251
+ if (FL_TEST(klass, FL_SINGLETON)) {
252
+ rb_ivar_set(klass, '__attached__', obj);
253
+ }
254
+ }
255
+
256
+
257
+ // RClass.prototype.$ = function(id, args) {
258
+ // var method = this.$klass.$search_method(id);
259
+ // // console.log('searching for: ' + id);
260
+ // // console.log(this.$klass);
261
+ // if (!method) throw 'VN#funcall cannot find method: ' + id ;
262
+ // return method.apply(this, args) ;
263
+ // };
264
+ //
265
+ // /**
266
+ // cvar_get (klassvar_get)
267
+ // */
268
+ // RClass.prototype.$k_g = function(id) {
269
+ // var tmp = this;
270
+ // var value;
271
+ // while(tmp) {
272
+ // if (value = tmp.$iv_tbl[id]) {
273
+ // return value;
274
+ // }
275
+ // tmp = tmp.$super;
276
+ // }
277
+ // VN.name_error('uninitialized class variable ' + id + ' in ' + this);
278
+ // return nil ;
279
+ // };
280
+ //
281
+ // /**
282
+ // class var defined
283
+ // */
284
+ // RClass.prototype.$k_d = function(id) {
285
+ // var tmp = this;
286
+ // var value;
287
+ // while(tmp) {
288
+ // if (value = tmp.$iv_tbl[id]) {
289
+ // return true;
290
+ // }
291
+ // tmp = tmp.$super;
292
+ // }
293
+ // return false;
294
+ // }
295
+ //
296
+ // /**
297
+ // cvar_set (klassvar_set)
298
+ // */
299
+ // RClass.prototype.$k_s = function(id, val) {
300
+ // return this.$iv_tbl[id] = val;
301
+ // };
302
+ //
303
+ // RClass.prototype.$i_g = function(id) {
304
+ // return this.$iv_tbl[id];
305
+ // };
306
+ //
307
+ // RClass.prototype.$i_s = function(id, val) {
308
+ // this.$iv_tbl[id] = val;
309
+ // return val ;
310
+ // }
311
+
312
+ /**
313
+ Define 'normal' method
314
+ */
315
+ function rb_define_method(klass, name, func, argc) {
316
+ func.rb_argc = argc;
317
+ rb_add_method(klass, name, func, NOEX_PUBLIC);
318
+ }
319
+
320
+ function rb_define_private_method(klass, name, func, argc) {
321
+ func.rb_argc = argc;
322
+ rb_add_method(klass, name, func, NOEX_PRIVATE);
323
+ }
324
+
325
+ function rb_define_private_method(klass, name, func, argc) {
326
+ func.rb_argc = argc;
327
+ rb_add_method(klass, name, func, NOEX_PROTECTED);
328
+ }
329
+
330
+ function rb_define_singleton_method(klass, name, func, argc) {
331
+ rb_define_method(rb_singleton_class(klass), name, func, argc);
332
+ }
333
+
334
+ function rb_add_method(klass, name, func) {
335
+ klass.m_tbl[name] = func;
336
+ // func.displayName = klass.iv_tbl.__classid__ + "#" + name;
337
+ }
338
+
339
+ function rb_define_alloc_func(klass, func) {
340
+ rb_define_method(rb_singleton_class(klass), 'allocate', func, 0);
341
+ }
342
+
343
+
344
+ // RClass.prototype.$def = function(name, func) {
345
+ // this.$add_method(name, func);
346
+ // };
347
+ //
348
+ // RClass.prototype.$define_protected_method = function(name, func) {
349
+ // this.$add_method(name, func);
350
+ // };
351
+ //
352
+ // RClass.prototype.$define_private_method = function(name, func) {
353
+ // this.$add_method(name, func);
354
+ // };
355
+ //
356
+ // RClass.prototype.$undef_method = function(name, func) {
357
+ // this.$add_method(name, func);
358
+ // };
359
+ //
360
+ // RClass.prototype.$add_method = function(name, func) {
361
+ // this.$m_tbl[name] = func;
362
+ // };
363
+
364
+ /**
365
+ Define singleton
366
+ */
367
+ // RClass.prototype.$def_s = function(name, func) {
368
+ // RClass.singleton_class(this).$def(name, func);
369
+ // };
370
+ //
371
+ // RClass.prototype.$define_alias = function(id1, id2) {
372
+ //
373
+ // };
374
+ //
375
+ // RClass.prototype.$define_alloc_func = function(func) {
376
+ // RClass.singleton_class(this).$add_method('allocate', func);
377
+ // };
378
+ //
379
+ // RClass.prototype.$undef_alloc_func = function() {
380
+ // RClass.singleton_class(this).$add_method('allocate', null);
381
+ // };
382
+ //
383
+ // RClass.prototype.$search_method = function search_method(id) {
384
+ // // console.log('checking ' + id);
385
+ // // console.log(this);
386
+ // var klass = this; var func ;
387
+ // // console.log(id);
388
+ // // console.log(klass);
389
+ // // return null ;
390
+ // while (!(func = klass.$m_tbl[id])) {
391
+ // klass = klass.$super;
392
+ // // console.log(this.$super.__classid__);
393
+ // if (!klass) return undefined;
394
+ // }
395
+ // // console.log('returning true for ' + id);
396
+ // return func;
397
+ // };
398
+ //
399
+ // RClass.prototype.$search_super_method = function(from,id) {
400
+ // // get current
401
+ //
402
+ // /**
403
+ // Match func = from, to match current function
404
+ // THEN search by name from there up, otherwise, chains of more then
405
+ // 2 supers will keep rematching second super
406
+ // */
407
+ // var klass = this; var func;
408
+ // while (!((func = klass.$m_tbl[id]) && func == from)) {
409
+ // klass = klass.$super;
410
+ // if (!klass) return undefined;
411
+ // }
412
+ // // now skip up one
413
+ // klass = klass.$super;
414
+ // if (!klass) return undefined;
415
+ // while (!(func = klass.$m_tbl[id])) {
416
+ // klass = klass.$super;
417
+ // if(!klass) return undefined;
418
+ // }
419
+ // return func;
420
+ //
421
+ // //
422
+ // // var klass = this; var func;
423
+ // // while (!((func = klass.$m_tbl[id]) && func != from)) {
424
+ // // klass = klass.$super;
425
+ // // if(!klass) return undefined;
426
+ // // }
427
+ // //
428
+ // // var klass = this; var func;
429
+ // // // console.log('from');
430
+ // // // console.log(from);
431
+ // // // console.log('views');
432
+ // // // console.log(klass.$m_tbl[id]);
433
+ // // // console.log(klass.$m_tbl[id] === from);
434
+ // // // console.log(klass.$m_tbl[id]);
435
+ // // while (!((func = klass.$m_tbl[id]) && func != from)) {
436
+ // // klass = klass.$super;
437
+ // // if(!klass) return undefined;
438
+ // // }
439
+ // // // return func = klass.$m_tbl[id];
440
+ // // // return func = klass.$m_tbl[id];
441
+ // // return func;
442
+ //
443
+ // // var klass = this; var func ;
444
+ // //
445
+ // // while (!(func = klass.$m_tbl[id])) {
446
+ // // klass = klass.$super;
447
+ // // if (!klass) return undefined;
448
+ // // }
449
+ // // console.log('this point');
450
+ // // // we have the current impl, now we need to search for the super from this point..
451
+ // // klass = klass.$super;
452
+ // // if (!klass) return undefined;
453
+ // // while (!(func = klass.$m_tbl[id])) {
454
+ // // klass = klass.$super;
455
+ // // if (!klass) return undefined;
456
+ // // }
457
+ // // return func;
458
+ // };
459
+ //
460
+ // RClass.prototype.$ = function(id, args) {
461
+ // // var method = this.$search_method(this.$klass, id);
462
+ // var method = this.$klass.$search_method(id);
463
+ // if (!method) throw 'VN#funcall cannot find method: ' + id ;
464
+ // return method.apply(this, args) ;
465
+ // };
466
+
467
+ /**
468
+ $const_set
469
+ */