opal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/runtime/range.js ADDED
@@ -0,0 +1,56 @@
1
+ /*
2
+ * range.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_cRange;
29
+
30
+ function Init_Range() {
31
+ rb_cRange = rb_define_class("Range", rb_cObject);
32
+ // rb_include_module(rb_cRange, rb_cEnumerable);
33
+
34
+ // rb_define_method(rb_cRange, "initialize", rb_range_initialize, -1);
35
+ // rb_define_method(rb_cRange, "initialize_copy",rb_range_initialize_copy, 1);
36
+ // rb_define_method(rb_cRange, "==", rb_range_eq, 1);
37
+ // rb_define_method(rb_cRange, "===", rb_range_eqq, 1);
38
+ // rb_define_method(rb_cRange, "eql?", rb_range_eql, 1);
39
+ // rb_define_method(rb_cRange, "hash", rb_range_hash, 0);
40
+ // rb_define_method(rb_cRange, "each", rb_range_each, 0);
41
+ // rb_define_method(rb_cRange, "step", rb_range_step, -1);
42
+ // rb_define_method(rb_cRange, "begin", rb_range_begin, 0);
43
+ // rb_define_method(rb_cRange, "end", rb_range_end, 0);
44
+ // rb_define_method(rb_cRange, "first", rb_range_first, -1);
45
+ // rb_define_method(rb_cRange, "last", rb_range_last, -1);
46
+ // rb_define_method(rb_cRange, "min", rb_range_min, 0);
47
+ // rb_define_method(rb_cRange, "max", rb_range_max, 0);
48
+ // rb_define_method(rb_cRange, "to_s", rb_range_to_s, 0);
49
+ // rb_define_method(rb_cRange, "inspect", rb_range_inspect, 0);
50
+
51
+ // rb_define_method(rb_cRange, "exclude_end?", rb_range_exclude_end_p, 0);
52
+
53
+ // rb_define_method(rb_cRange, "member?", rb_range_include, 1);
54
+ // rb_define_method(rb_cRange, "include?", rrb_ange_include, 1);
55
+ // rb_define_method(rb_cRange, "cover?", rb_range_cover, 1);
56
+ }
data/runtime/re.js ADDED
@@ -0,0 +1,91 @@
1
+ /*
2
+ * re.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_cRegexp, rb_eRegexpError, rb_cMatch;
29
+
30
+ function Init_Regexp() {
31
+ // rb_eRegexpError = rb_define_class("RegexpError", rb_eStandardError);
32
+
33
+ // rb_define_virtual_variable("$~", rb_match_getter, rb_match_setter);
34
+ // rb_define_virtual_variable("$&", rb_last_match_getter, 0);
35
+ // rb_define_virtual_variable("$`", rb_prematch_getter, 0);
36
+ // rb_define_virtual_variable("$'", rb_postmatch_getter, 0);
37
+ // rb_define_virtual_variable("$+", rb_last_paren_match_getter, 0);
38
+
39
+ // rb_define_virtual_variable("$=", rb_ignorecase_getter, rb_ignorecase_setter);
40
+ // rb_define_virtual_variable("$KCODE", rb_kcode_getter, rb_kcode_setter);
41
+ // rb_define_virtual_variable("$-K", rb_kcode_getter, rb_kcode_setter);
42
+
43
+ rb_cRegexp = rb_define_class("Regexp", rb_cObject);
44
+ // rb_define_alloc_func(rb_cRegexp, rb_reg_s_alloc);
45
+ // rb_define_singleton_method(rb_cRegexp, "compile", rb_class_new_instance, -1);
46
+ // rb_define_singleton_method(rb_cRegexp, "quote", rb_reg_s_quote, 1);
47
+ // rb_define_singleton_method(rb_cRegexp, "escape", rb_reg_s_quote, 1);
48
+ // rb_define_singleton_method(rb_cRegexp, "union", rb_reg_s_union_m, -2);
49
+ // rb_define_singleton_method(rb_cRegexp, "last_match", rb_reg_s_last_match, -1);
50
+ // rb_define_singleton_method(rb_cRegexp, "try_convert", rb_reg_s_try_convert, 1);
51
+
52
+ // rb_define_method(rb_cRegexp, "initialize", rb_reg_initialize_m, -1);
53
+ // rb_define_method(rb_cRegexp, "initialize_copy", rb_reg_init_copy, 1);
54
+ // rb_define_method(rb_cRegexp, "hash", rb_reg_hash, 0);
55
+ // rb_define_method(rb_cRegexp, "eql?", rb_reg_equal, 1);
56
+ // rb_define_method(rb_cRegexp, "==", rb_reg_equal, 1);
57
+ // rb_define_method(rb_cRegexp, "=~", rb_reg_match, 1);
58
+ // rb_define_method(rb_cRegexp, "===", rb_reg_eqq, 1);
59
+ // rb_define_method(rb_cRegexp, "~", rb_reg_match2, 0);
60
+ // rb_define_method(rb_cRegexp, "match", rb_reg_match_m, -1);
61
+ // rb_define_method(rb_cRegexp, "to_s", rb_reg_to_s, 0);
62
+ // rb_define_method(rb_cRegexp, "inspect", rb_reg_inspect, 0);
63
+ // rb_define_method(rb_cRegexp, "source", rb_reg_source, 0);
64
+ // rb_define_method(rb_cRegexp, "casefold?", rb_reg_casefold_p, 0);
65
+ // rb_define_method(rb_cRegexp, "options", rb_reg_options_m, 0);
66
+ // rb_define_method(rb_cRegexp, "encoding", rb_obj_encoding, 0);
67
+ // rb_define_method(rb_cRegexp, "fixed_encoding?", rb_reg_fixed_encoding_p, 0);
68
+ // rb_define_method(rb_cRegexp, "names", rb_reg_names, 0);
69
+ // rb_define_method(rb_cRegexp, "named_captures", rb_reg_named_captures, 0);
70
+
71
+ rb_cMatch = rb_define_class("MatchData", rb_cObject);
72
+ // rb_define_alloc_func(rb_cMatch, match_alloc);
73
+
74
+ // rb_define_method(rb_cMatch, "initialize_copy", match_init_copy, 1);
75
+ // rb_define_method(rb_cMatch, "regexp", match_regexp, 0);
76
+ // rb_define_method(rb_cMatch, "names", match_names, 0);
77
+ // rb_define_method(rb_cMatch, "size", match_size, 0);
78
+ // rb_define_method(rb_cMatch, "length", match_size, 0);
79
+ // rb_define_method(rb_cMatch, "offset", match_offset, 1);
80
+ // rb_define_method(rb_cMatch, "begin", match_begin, 1);
81
+ // rb_define_method(rb_cMatch, "end", match_end, 1);
82
+ // rb_define_method(rb_cMatch, "to_a", match_to_a, 0);
83
+ // rb_define_method(rb_cMatch, "[]", match_aref, -1);
84
+ // rb_define_method(rb_cMatch, "captures", match_captures, 0);
85
+ // rb_define_method(rb_cMatch, "values_at", match_values_at, -1);
86
+ // rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
87
+ // rb_define_method(rb_cMatch, "post_match", rb_reg_match_post, 0);
88
+ // rb_define_method(rb_cMatch, "to_s", match_to_s, 0);
89
+ // rb_define_method(rb_cMatch, "inspect", match_inspect, 0);
90
+ // rb_define_method(rb_cMatch, "string", match_string, 0);
91
+ }
data/runtime/string.js ADDED
@@ -0,0 +1,199 @@
1
+ /*
2
+ * string.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_cString, rb_cSymbol;
29
+
30
+ var RSymbol = function(ptr) {
31
+ this.klass = rb_cSymbol ;
32
+ // this.$type = T_SYMBOL;
33
+ this.toString = function() {
34
+ // hack, for associative js arrays, we need a unique string name :(
35
+ return "#<Symbol:0x000000 @ptr=" + this.ptr + ">";
36
+ };
37
+ this.ptr = ptr;
38
+ return this;
39
+ };
40
+
41
+ // Keys are ids, values are their associated instances of RSymbol
42
+ // 'adam' => [Obj]
43
+ // keys do not contain the ':'
44
+ var rb_sym_table = { };
45
+
46
+ function ID2SYM(id) {
47
+ if (rb_sym_table.hasOwnProperty(id)) {
48
+ return rb_sym_table[id];
49
+ }
50
+ var sym = new RSymbol(id);
51
+ rb_sym_table[id] = sym
52
+ return sym;
53
+ };
54
+
55
+ function rb_sym_to_s(sym) {
56
+ return sym.ptr;
57
+ };
58
+
59
+ function rb_sym_equal(sym1, sym2) {
60
+ if (sym1 === sym2) return true;
61
+ return false;
62
+ };
63
+
64
+ function Init_String() {
65
+
66
+ rb_cString = rb_define_class("String", rb_cObject);
67
+ // rb_include_module(rb_cString, rb_mComparable);
68
+ // rb_define_alloc_func(rb_cString, rb_str_alloc);
69
+
70
+ // rb_define_singleton_method(rb_cString, "try_convert", rb_str_s_try_convert, 1);
71
+ // rb_define_method(rb_cString, "initialize", rb_str_init, -1);
72
+ // rb_define_method(rb_cString, "initialize_copy", rb_str_replace, 1);
73
+ // rb_define_method(rb_cString, "<=>", rb_str_cmp_m, 1);
74
+ // rb_define_method(rb_cString, "==", rb_str_equal, 1);
75
+ // rb_define_method(rb_cString, "eql?", rb_str_eql, 1);
76
+ // rb_define_method(rb_cString, "hash", rb_str_hash_m, 0);
77
+ // rb_define_method(rb_cString, "casecmp", rb_str_casecmp, 1);
78
+ // rb_define_method(rb_cString, "+", rb_str_plus, 1);
79
+ // rb_define_method(rb_cString, "*", rb_str_times, 1);
80
+ // rb_define_method(rb_cString, "%", rb_str_format_m, 1);
81
+ // rb_define_method(rb_cString, "[]", rb_str_aref_m, -1);
82
+ // rb_define_method(rb_cString, "[]=", rb_str_aset_m, -1);
83
+ // rb_define_method(rb_cString, "insert", rb_str_insert, 2);
84
+ // rb_define_method(rb_cString, "length", rb_str_length, 0);
85
+ // rb_define_method(rb_cString, "size", rb_str_length, 0);
86
+ // rb_define_method(rb_cString, "bytesize", rb_str_bytesize, 0);
87
+ // rb_define_method(rb_cString, "empty?", rb_str_empty, 0);
88
+ // rb_define_method(rb_cString, "=~", rb_str_match, 1);
89
+ // rb_define_method(rb_cString, "match", rb_str_match_m, -1);
90
+ // rb_define_method(rb_cString, "succ", rb_str_succ, 0);
91
+ // rb_define_method(rb_cString, "succ!", rb_str_succ_bang, 0);
92
+ // rb_define_method(rb_cString, "next", rb_str_succ, 0);
93
+ // rb_define_method(rb_cString, "next!", rb_str_succ_bang, 0);
94
+ // rb_define_method(rb_cString, "upto", rb_str_upto, -1);
95
+ // rb_define_method(rb_cString, "index", rb_str_index_m, -1);
96
+ // rb_define_method(rb_cString, "rindex", rb_str_rindex_m, -1);
97
+ // rb_define_method(rb_cString, "replace", rb_str_replace, 1);
98
+ // rb_define_method(rb_cString, "clear", rb_str_clear, 0);
99
+ // rb_define_method(rb_cString, "chr", rb_str_chr, 0);
100
+ // rb_define_method(rb_cString, "getbyte", rb_str_getbyte, 1);
101
+ // rb_define_method(rb_cString, "setbyte", rb_str_setbyte, 2);
102
+
103
+ // rb_define_method(rb_cString, "to_i", rb_str_to_i, -1);
104
+ // rb_define_method(rb_cString, "to_f", rb_str_to_f, 0);
105
+ // rb_define_method(rb_cString, "to_s", rb_str_to_s, 0);
106
+ // rb_define_method(rb_cString, "to_str", rb_str_to_s, 0);
107
+ // rb_define_method(rb_cString, "inspect", rb_str_inspect, 0);
108
+ // rb_define_method(rb_cString, "dump", rb_str_dump, 0);
109
+
110
+ // rb_define_method(rb_cString, "upcase", rb_str_upcase, 0);
111
+ // rb_define_method(rb_cString, "downcase", rb_str_downcase, 0);
112
+ // rb_define_method(rb_cString, "capitalize", rb_str_capitalize, 0);
113
+ // rb_define_method(rb_cString, "swapcase", rb_str_swapcase, 0);
114
+
115
+ // rb_define_method(rb_cString, "hex", rb_str_hex, 0);
116
+ // rb_define_method(rb_cString, "oct", rb_str_oct, 0);
117
+ // rb_define_method(rb_cString, "split", rb_str_split_m, -1);
118
+ // rb_define_method(rb_cString, "lines", rb_str_each_line, -1);
119
+ // rb_define_method(rb_cString, "bytes", rb_str_each_byte, 0);
120
+ // rb_define_method(rb_cString, "chars", rb_str_each_char, 0);
121
+ // rb_define_method(rb_cString, "codepoints", rb_str_each_codepoint, 0);
122
+ // rb_define_method(rb_cString, "reverse", rb_str_reverse, 0);
123
+ // rb_define_method(rb_cString, "concat", rb_str_concat, 1);
124
+ // rb_define_method(rb_cString, "<<", rb_str_concat, 1);
125
+ // rb_define_method(rb_cString, "crypt", rb_str_crypt, 1);
126
+ // rb_define_method(rb_cString, "intern", rb_str_intern, 0);
127
+ // rb_define_method(rb_cString, "to_sym", rb_str_intern, 0);
128
+ // rb_define_method(rb_cString, "ord", rb_str_ord, 0);
129
+
130
+ // rb_define_method(rb_cString, "include?", rb_str_include, 1);
131
+ // rb_define_method(rb_cString, "start_with?", rb_str_start_with, -1);
132
+ // rb_define_method(rb_cString, "end_with?", rb_str_end_with, -1);
133
+
134
+ // rb_define_method(rb_cString, "scan", rb_str_scan, 1);
135
+
136
+ // rb_define_method(rb_cString, "ljust", rb_str_ljust, -1);
137
+ // rb_define_method(rb_cString, "rjust", rb_str_rjust, -1);
138
+ // rb_define_method(rb_cString, "center", rb_str_center, -1);
139
+
140
+ // rb_define_method(rb_cString, "sub", rb_str_sub, -1);
141
+ // rb_define_method(rb_cString, "gsub", rb_str_gsub, -1);
142
+ // rb_define_method(rb_cString, "chop", rb_str_chop, 0);
143
+ // rb_define_method(rb_cString, "chomp", rb_str_chomp, -1);
144
+ // rb_define_method(rb_cString, "strip", rb_str_strip, 0);
145
+ // rb_define_method(rb_cString, "lstrip", rb_str_lstrip, 0);
146
+ // rb_define_method(rb_cString, "rstrip", rb_str_rstrip, 0);
147
+
148
+ // rb_define_method(rb_cString, "tr", rb_str_tr, 2);
149
+ // rb_define_method(rb_cString, "tr_s", rb_str_tr_s, 2);
150
+ // rb_define_method(rb_cString, "delete", rb_str_delete, -1);
151
+ // rb_define_method(rb_cString, "squeeze", rb_str_squeeze, -1);
152
+ // rb_define_method(rb_cString, "count", rb_str_count, -1);
153
+
154
+ // rb_define_method(rb_cString, "each_line", rb_str_each_line, -1);
155
+ // rb_define_method(rb_cString, "each_byte", rb_str_each_byte, 0);
156
+ // rb_define_method(rb_cString, "each_char", rb_str_each_char, 0);
157
+ // rb_define_method(rb_cString, "each_codepoint", rb_str_each_codepoint, 0);
158
+
159
+ // rb_define_method(rb_cString, "sum", rb_str_sum, -1);
160
+
161
+ // rb_define_method(rb_cString, "slice", rb_str_aref_m, -1);
162
+
163
+ // rb_define_method(rb_cString, "partition", rb_str_partition, 1);
164
+ // rb_define_method(rb_cString, "rpartition", rb_str_rpartition, 1);
165
+
166
+
167
+
168
+ rb_cSymbol = rb_define_class("Symbol", rb_cObject);
169
+ // rb_include_module(rb_cSymbol, rb_mComparable);
170
+ // rb_undef_alloc_func(rb_cSymbol);
171
+ // rb_undef_method(rb_cSymbol.klass, "new");
172
+ // rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0);
173
+
174
+ rb_define_method(rb_cSymbol, "==", rb_sym_equal, 1);
175
+ // rb_define_method(rb_cSymbol, "inspect", rb_sym_inspect, 0);
176
+ rb_define_method(rb_cSymbol, "to_s", rb_sym_to_s, 0);
177
+ rb_define_method(rb_cSymbol, "id2name", rb_sym_to_s, 0);
178
+ // rb_define_method(rb_cSymbol, "intern", rb_sym_to_sym, 0);
179
+ // rb_define_method(rb_cSymbol, "to_sym", rb_sym_to_sym, 0);
180
+ // rb_define_method(rb_cSymbol, "to_proc", rb_sym_to_proc, 0);
181
+ // rb_define_method(rb_cSymbol, "succ", rb_sym_succ, 0);
182
+ // rb_define_method(rb_cSymbol, "next", rb_sym_succ, 0);
183
+
184
+ // rb_define_method(rb_cSymbol, "<=>", rb_sym_cmp, 1);
185
+ // rb_define_method(rb_cSymbol, "casecmp", rb_sym_casecmp, 1);
186
+ // rb_define_method(rb_cSymbol, "=~", rb_sym_match, 1);
187
+
188
+ // rb_define_method(rb_cSymbol, "[]", rb_sym_aref, -1);
189
+ // rb_define_method(rb_cSymbol, "slice", rb_sym_aref, -1);
190
+ // rb_define_method(rb_cSymbol, "length", rb_sym_length, 0);
191
+ // rb_define_method(rb_cSymbol, "size", rb_sym_length, 0);
192
+ // rb_define_method(rb_cSymbol, "empty?", rb_sym_empty, 0);
193
+ // rb_define_method(rb_cSymbol, "match", rb_sym_match, 1);
194
+
195
+ // rb_define_method(rb_cSymbol, "upcase", rb_sym_upcase, 0);
196
+ // rb_define_method(rb_cSymbol, "downcase", rb_sym_downcase, 0);
197
+ // rb_define_method(rb_cSymbol, "capitalize", rb_sym_capitalize, 0);
198
+ // rb_define_method(rb_cSymbol, "swapcase", rb_sym_swapcase, 0);
199
+ }
@@ -0,0 +1,184 @@
1
+ /*
2
+ * variable.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_ivar_set(obj, id, val) {
29
+ obj.iv_tbl[id] = val;
30
+ return val;
31
+ };
32
+
33
+ function rb_ivar_get(obj, id) {
34
+ if (obj.iv_tbl.hasOwnProperty(id)) {
35
+ return obj.iv_tbl[id];
36
+ }
37
+ return nil;
38
+ }
39
+
40
+ function rb_const_set(k, id, val) {
41
+ return rb_mod_av_set(k, id, val, true);
42
+ }
43
+
44
+ function rb_mod_av_set(k, id, val, isconst) {
45
+ return k.iv_tbl[id] = val;
46
+ }
47
+
48
+ function rb_const_set(k, id, val) {
49
+ return k.iv_tbl[id] = val;
50
+ }
51
+
52
+ function rb_const_get(k, id) {
53
+ var v, t = k;
54
+ while (t) {
55
+ if (v = t.iv_tbl[id]) return v;
56
+ t = t.sup;
57
+ }
58
+ // now try parent instead..
59
+ t = k.parent;
60
+ while (t) {
61
+ if (v = t.iv_tbl[id]) return v;
62
+ t = t.parent;
63
+ }
64
+ throw "NameError: uninitialized constant " + id + " in " + k.name
65
+ return nil;
66
+ }
67
+
68
+ function rb_const_get_full(k, id) {
69
+ var v, t = k;
70
+ while (t) {
71
+ if (v = t.iv_tbl[id]) return v;
72
+ t = t.sup;
73
+ }
74
+ // now try parent instead..
75
+ t = k.parent;
76
+ while (t) {
77
+ if (v = t.iv_tbl[id]) return v;
78
+ t = t.parent;
79
+ }
80
+ throw "NameError: uninitialized constant " + id + " in " + k.name
81
+ return nil;
82
+ }
83
+
84
+ function rb_const_defined(k, id) {
85
+ var v, t = k;
86
+ while (t) {
87
+ if (v = t.iv_tbl[id]) return true;
88
+ t = t.sup;
89
+ }
90
+ return false;
91
+ }
92
+
93
+ function rb_const_defined_full(k, id) {
94
+ var v, t = k;
95
+ while (t) {
96
+ if (v = t.iv_tbl[id]) return true;
97
+ t = t.sup;
98
+ }
99
+ // now try parent instead..
100
+ t = k.parent;
101
+ while (t) {
102
+ if (v = t.iv_tbl[id]) return true;
103
+ t = t.parent;
104
+ }
105
+ return false;
106
+ }
107
+
108
+ function rb_const_defined_at(k, id) {
109
+ return (k.iv_tbl[id]) ? true : false;
110
+ }
111
+
112
+ function rb_const_get_at(k, id) {
113
+ return (k.iv_tbl[id]) ? k.iv_tbl[id] : nil;
114
+ }
115
+
116
+
117
+
118
+ // function rb_funcall(self, id) {
119
+ // // console.log(id);
120
+ // // rb_funcall_stack.push(id);
121
+ // if (!self.klass) {
122
+ // console.log('ERROR: rb_funcall');
123
+ // console.log(self);
124
+ // console.log(id);
125
+ // }
126
+ //
127
+ // var method = rb_search_method(self.klass, id);
128
+ //
129
+ // if (!method) {
130
+ // console.log(self);
131
+ // throw 'RObject#call cannot find method: ' + id ;
132
+ // }
133
+ // // console.log(Array.prototype.slice.call(arguments));
134
+ // switch(arguments.length) {
135
+ // case 2: return method(self, id);
136
+ // case 3: return method(self, id, arguments[2]);
137
+ // case 4: return method(self, id, arguments[2], arguments[3]);
138
+ // case 5: return method(self, id, arguments[2], arguments[3], arguments[4]);
139
+ // }
140
+ //
141
+ // return method.apply(self, arguments);
142
+ // }
143
+ //
144
+ // /**
145
+ // For compatibility
146
+ // */
147
+ // var VN$ = rb_funcall;
148
+ //
149
+ // /**
150
+ // Call super method
151
+ // */
152
+ // var rb_supcall = function rb_supcall(from, self, id, args) {
153
+ // var method = self.$klass.$search_super_method(from, id);
154
+ // if (!method) throw 'RObject#call cannot find super method for: ' + id ;
155
+ //
156
+ // switch(args.length) {
157
+ // case 0: return method(self, id);
158
+ // case 1: return method(self, id, args[0]);
159
+ // case 2: return method(self, id, args[0], args[1]);
160
+ // case 3: return method(self, id, args[0], args[1], args[2]);
161
+ // case 4: return method(self, id, args[0], args[1], args[2], args[3]);
162
+ // }
163
+ //
164
+ // return method.apply(self, arguments);
165
+ // };
166
+
167
+ // /**
168
+ // For compatibility
169
+ // */
170
+ // var VN$sup = rb_supcall;
171
+ //
172
+ // /**
173
+ // Call super
174
+ // - from = callee
175
+ // */
176
+ // RObject.prototype.$sup = function(from, id, args) {
177
+ // // console.log('callee');
178
+ // // console.log(from);
179
+ // var method = this.$klass.$search_super_method(from, id);
180
+ // if (!method) throw 'RObject#call cannot find super method for: ' + id ;
181
+ // // console.log('got super');
182
+ // // console.log(method);
183
+ // return method.apply(this, args) ;
184
+ // };