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.
Files changed (98) hide show
  1. data/README.md +69 -97
  2. data/bin/opal +2 -2
  3. data/{lib/core → corelib}/array.rb +85 -56
  4. data/corelib/boolean.rb +20 -0
  5. data/corelib/class.rb +58 -0
  6. data/{lib → corelib}/core.rb +2 -50
  7. data/corelib/dir.rb +22 -0
  8. data/{lib/core → corelib}/enumerable.rb +0 -0
  9. data/corelib/error.rb +19 -0
  10. data/{lib/core → corelib}/file.rb +7 -9
  11. data/{lib/core → corelib}/hash.rb +104 -144
  12. data/{lib/core → corelib}/kernel.rb +38 -44
  13. data/corelib/load_order +21 -0
  14. data/{lib/core → corelib}/match_data.rb +0 -0
  15. data/{lib/core → corelib}/module.rb +12 -8
  16. data/{lib/core → corelib}/nil_class.rb +2 -2
  17. data/{lib/core → corelib}/numeric.rb +37 -100
  18. data/corelib/object.rb +37 -0
  19. data/{lib/core → corelib}/proc.rb +3 -3
  20. data/corelib/range.rb +27 -0
  21. data/{lib/core → corelib}/regexp.rb +1 -1
  22. data/{lib/core → corelib}/string.rb +16 -107
  23. data/{lib/core → corelib}/top_self.rb +0 -0
  24. data/lib/opal.rb +7 -0
  25. data/lib/opal/browserify.rb +34 -0
  26. data/{opal_lib → lib}/opal/builder.rb +70 -24
  27. data/lib/opal/command.rb +52 -0
  28. data/lib/opal/context.rb +197 -0
  29. data/{opal_lib/opal/ruby/parser.rb → lib/opal/lexer.rb} +20 -4
  30. data/{opal_lib/opal/ruby → lib/opal}/nodes.rb +238 -127
  31. data/lib/opal/parser.rb +4894 -0
  32. data/{opal_lib/opal/ruby/ruby_parser.y → lib/opal/parser.y} +38 -18
  33. data/lib/rbp.rb +2 -0
  34. data/lib/rbp/package.rb +49 -0
  35. data/runtime/class.js +216 -189
  36. data/runtime/fs.js +2 -2
  37. data/runtime/init.js +242 -244
  38. data/runtime/loader.js +78 -99
  39. data/runtime/module.js +34 -40
  40. data/runtime/post.js +2 -2
  41. data/runtime/pre.js +1 -1
  42. data/runtime/runtime.js +129 -135
  43. data/{lib → stdlib}/dev.rb +10 -10
  44. data/{lib → stdlib}/racc/parser.rb +0 -6
  45. data/{lib → stdlib}/strscan.rb +4 -4
  46. metadata +57 -105
  47. data/lib/core/basic_object.rb +0 -51
  48. data/lib/core/class.rb +0 -38
  49. data/lib/core/dir.rb +0 -26
  50. data/lib/core/error.rb +0 -75
  51. data/lib/core/false_class.rb +0 -81
  52. data/lib/core/object.rb +0 -6
  53. data/lib/core/range.rb +0 -27
  54. data/lib/core/symbol.rb +0 -42
  55. data/lib/core/true_class.rb +0 -41
  56. data/lib/ospec.rb +0 -7
  57. data/lib/ospec/autorun.rb +0 -8
  58. data/lib/ospec/dsl.rb +0 -15
  59. data/lib/ospec/example.rb +0 -11
  60. data/lib/ospec/example/before_and_after_hooks.rb +0 -56
  61. data/lib/ospec/example/errors.rb +0 -17
  62. data/lib/ospec/example/example_group.rb +0 -12
  63. data/lib/ospec/example/example_group_factory.rb +0 -18
  64. data/lib/ospec/example/example_group_hierarchy.rb +0 -21
  65. data/lib/ospec/example/example_group_methods.rb +0 -100
  66. data/lib/ospec/example/example_group_proxy.rb +0 -15
  67. data/lib/ospec/example/example_methods.rb +0 -46
  68. data/lib/ospec/example/example_proxy.rb +0 -18
  69. data/lib/ospec/expectations.rb +0 -19
  70. data/lib/ospec/expectations/errors.rb +0 -8
  71. data/lib/ospec/expectations/fail_with.rb +0 -9
  72. data/lib/ospec/expectations/handler.rb +0 -33
  73. data/lib/ospec/helpers/scratch.rb +0 -18
  74. data/lib/ospec/matchers.rb +0 -24
  75. data/lib/ospec/matchers/be.rb +0 -1
  76. data/lib/ospec/matchers/generated_descriptions.rb +0 -20
  77. data/lib/ospec/matchers/operator_matcher.rb +0 -54
  78. data/lib/ospec/matchers/raise_error.rb +0 -38
  79. data/lib/ospec/runner.rb +0 -90
  80. data/lib/ospec/runner/example_group_runner.rb +0 -41
  81. data/lib/ospec/runner/formatter/html_formatter.rb +0 -139
  82. data/lib/ospec/runner/formatter/terminal_formatter.rb +0 -48
  83. data/lib/ospec/runner/options.rb +0 -34
  84. data/lib/ospec/runner/reporter.rb +0 -82
  85. data/opal_lib/opal.rb +0 -16
  86. data/opal_lib/opal/build_methods.rb +0 -51
  87. data/opal_lib/opal/bundle.rb +0 -70
  88. data/opal_lib/opal/command.rb +0 -68
  89. data/opal_lib/opal/context.rb +0 -81
  90. data/opal_lib/opal/context/console.rb +0 -10
  91. data/opal_lib/opal/context/file_system.rb +0 -34
  92. data/opal_lib/opal/context/loader.rb +0 -135
  93. data/opal_lib/opal/gem.rb +0 -84
  94. data/opal_lib/opal/rake/builder_task.rb +0 -44
  95. data/opal_lib/opal/rake/spec_task.rb +0 -32
  96. data/opal_lib/opal/ruby/ruby_parser.rb +0 -4862
  97. data/opal_lib/opal/version.rb +0 -4
  98. data/runtime/debug.js +0 -84
@@ -1,4 +1,4 @@
1
- class Opal::RubyParser
1
+ class Opal::Parser < Racc::Parser
2
2
 
3
3
  token CLASS MODULE DEF UNDEF BEGIN RESCUE ENSURE END IF UNLESS
4
4
  THEN ELSIF ELSE CASE WHEN WHILE UNTIL FOR BREAK NEXT
@@ -14,7 +14,7 @@ token CLASS MODULE DEF UNDEF BEGIN RESCUE ENSURE END IF UNLESS
14
14
  '~' '%' '/' '+' '-' '<' '>' '|' '!' '^'
15
15
  '{@' '}' BACK_REF2 SYMBOL_BEG STRING_BEG XSTRING_BEG REGEXP_BEG
16
16
  WORDS_BEG AWORDS_BEG STRING_DBEG STRING_DVAR STRING_END STRING
17
- SYMBOL '\\n' '?' ':' ',' SPACE ';' LABEL
17
+ SYMBOL '\\n' '?' ':' ',' SPACE ';' LABEL UNDEFINED NULL
18
18
 
19
19
  prechigh
20
20
  right '!' '~' '+@'
@@ -150,11 +150,11 @@ expr:
150
150
  }
151
151
  | NOT expr
152
152
  {
153
- result = CallNode.new val[1], {:value => '!', :line => 0}, []
153
+ result = UnaryNode.new({:line => val[0][:line], :value => '!'} , val[1])
154
154
  }
155
155
  | '!' command_call
156
156
  {
157
- result = CallNode.new val[1], val[0], []
157
+ result = UnaryNode.new({:line => val[0][:line], :value => '!'} , val[1])
158
158
  }
159
159
  | arg
160
160
 
@@ -399,15 +399,13 @@ arg:
399
399
  {
400
400
  result = CallNode.new val[0], val[1], [[val[2]]]
401
401
  }
402
- | '-@NUM' INTEGER '**' arg
403
- | '-@NUM' FLOAT '**' arg
404
402
  | '+@' arg
405
403
  {
406
- result = CallNode.new val[1], val[0], []
404
+ result = UnaryNode.new({:line => val[0][:line], :value => '+'} , val[1])
407
405
  }
408
406
  | '-@' arg
409
407
  {
410
- result = CallNode.new val[1], val[0], []
408
+ result = UnaryNode.new({:line => val[0][:line], :value => '-'} , val[1])
411
409
  }
412
410
  | arg '|' arg
413
411
  {
@@ -427,23 +425,23 @@ arg:
427
425
  }
428
426
  | arg '>' arg
429
427
  {
430
- result = CallNode.new val[0], val[1], [[val[2]]]
428
+ result = ComparisonNode.new val[1], val[0], val[2]
431
429
  }
432
430
  | arg '>=' arg
433
431
  {
434
- result = CallNode.new val[0], val[1], [[val[2]]]
432
+ result = ComparisonNode.new val[1], val[0], val[2]
435
433
  }
436
434
  | arg '<' arg
437
435
  {
438
- result = CallNode.new val[0], val[1], [[val[2]]]
436
+ result = ComparisonNode.new val[1], val[0], val[2]
439
437
  }
440
438
  | arg '<=' arg
441
439
  {
442
- result = CallNode.new val[0], val[1], [[val[2]]]
440
+ result = ComparisonNode.new val[1], val[0], val[2]
443
441
  }
444
442
  | arg '==' arg
445
443
  {
446
- result = CallNode.new val[0], val[1], [[val[2]]]
444
+ result = ComparisonNode.new val[1], val[0], val[2]
447
445
  }
448
446
  | arg '===' arg
449
447
  {
@@ -451,7 +449,7 @@ arg:
451
449
  }
452
450
  | arg '!=' arg
453
451
  {
454
- result = CallNode.new val[0], val[1], [[val[2]]]
452
+ result = ComparisonNode.new val[1], val[0], val[2]
455
453
  }
456
454
  | arg '=~' arg
457
455
  {
@@ -463,7 +461,7 @@ arg:
463
461
  }
464
462
  | '!' arg
465
463
  {
466
- result = CallNode.new val[1], val[0], []
464
+ result = UnaryNode.new({:line => val[0][:line], :value => '!'} , val[1])
467
465
  }
468
466
  | '~' arg
469
467
  {
@@ -751,13 +749,16 @@ primary:
751
749
  | CASE opt_terms ELSE compstmt END
752
750
  | FOR block_var IN
753
751
  {
754
- result = "this.cond_push(1);"
752
+ cond_push 1
755
753
  }
756
754
  expr_value do
757
755
  {
758
- result = "this.cond_pop();"
756
+ cond_pop
759
757
  }
760
758
  compstmt END
759
+ {
760
+ result = ForNode.new val[0], val[1], val[4], val[7], val[8]
761
+ }
761
762
  | CLASS cpath superclass bodystmt END
762
763
  {
763
764
  result = ClassNode.new val[0], val[1], val[2], val[3], val[4]
@@ -1003,7 +1004,13 @@ exc_var:
1003
1004
 
1004
1005
  opt_ensure:
1005
1006
  ENSURE compstmt
1007
+ {
1008
+ result = val[1]
1009
+ }
1006
1010
  | none
1011
+ {
1012
+ result = nil
1013
+ }
1007
1014
 
1008
1015
  literal:
1009
1016
  numeric
@@ -1183,12 +1190,20 @@ variable:
1183
1190
  }
1184
1191
  | CVAR
1185
1192
  {
1186
- result = "result = ['cvar', val[0]];"
1193
+ result = CvarNode.new val[0]
1187
1194
  }
1188
1195
  | NIL
1189
1196
  {
1190
1197
  result = NilNode.new val[0]
1191
1198
  }
1199
+ | UNDEFINED
1200
+ {
1201
+ result = UndefinedNode.new val[0]
1202
+ }
1203
+ | NULL
1204
+ {
1205
+ result = NullNode.new val[0]
1206
+ }
1192
1207
  | SELF
1193
1208
  {
1194
1209
  result = SelfNode.new val[0]
@@ -1451,4 +1466,9 @@ none_block_pass:
1451
1466
 
1452
1467
  end
1453
1468
 
1469
+ ---- header
1470
+
1471
+ require 'opal/lexer'
1472
+ require 'opal/nodes'
1473
+
1454
1474
  ---- inner
data/lib/rbp.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'rbp/package'
2
+
@@ -0,0 +1,49 @@
1
+ require 'yaml'
2
+
3
+ module RBP
4
+
5
+ class Package
6
+
7
+ attr_reader :root
8
+
9
+ def initialize(root = Dir.getwd)
10
+ @root = root
11
+ __load_yml
12
+ end
13
+
14
+ def __load_yml
15
+ yml_path = File.join @root, 'package.yml'
16
+
17
+ unless File.exists? yml_path
18
+ raise "Missing package.yml in `#{@root}'"
19
+ end
20
+
21
+ @yml = YAML.load File.read(yml_path)
22
+
23
+ raise "Bad package.yml" unless @yml and @yml['name'] and @yml['version']
24
+ end
25
+
26
+ # Returns an array of lib files relative to the root of
27
+ # this package
28
+ def lib_files
29
+ libs = nil
30
+
31
+ Dir.chdir(File.join @root, 'lib') do
32
+ libs = Dir['**/*.rb']
33
+ end
34
+
35
+ libs
36
+ end
37
+
38
+ # package name
39
+ def name
40
+ @yml['name']
41
+ end
42
+
43
+ # package version
44
+ def version
45
+ @yml['version']
46
+ end
47
+ end
48
+ end
49
+
data/runtime/class.js CHANGED
@@ -1,303 +1,333 @@
1
1
  /**
2
- Every class in opal is an instance of RClass
2
+ Root of all objects and classes inside opalscript, except for
3
+ native toll free bridges.
4
+ */
5
+ var rb_boot_root = function() {};
3
6
 
4
- @param {RClass} klass
5
- @param {RClass} superklass
7
+ /**
8
+ Returns the hash value for the receiver. By default on regular
9
+ objects this is just the objects' id
6
10
  */
7
- var RClass = Rt.RClass = function(klass, superklass) {
8
- this.$id = yield_hash();
9
- this.$super = superklass;
11
+ rb_boot_root.$h = function() {
12
+ return this.$id;
13
+ };
10
14
 
11
- if (superklass) {
12
- var mtor = function() {};
13
- mtor.prototype = new superklass.$m_tor();
14
- this.$m_tbl = mtor.prototype;
15
- this.$m_tor = mtor;
15
+ /**
16
+ To benefit javascript debug consoles, the toString of any ruby
17
+ object is its' #inspect method.
18
+ */
19
+ rb_boot_root.toString = function() {
20
+ return this.m$inspect();
21
+ };
16
22
 
17
- var cctor = function() {};
18
- cctor.prototype = superklass.$c_prototype;
23
+ /**
24
+ Boot a base class. This is only used for the very core ruby
25
+ objects and classes (Object, Module, Class). This returns
26
+ what will be the actual instances of our root classes.
19
27
 
20
- var c_tor = function(){};
21
- c_tor.prototype = new cctor();
28
+ @param {String} id The class id
29
+ @param {RubyClass} superklass The super
30
+ */
31
+ function rb_boot_defclass(id, superklass) {
32
+ var cls = function() {
33
+ this.$id = rb_yield_hash();
34
+ return this;
35
+ };
22
36
 
23
- this.$c = new c_tor();
24
- this.$c_prototype = c_tor.prototype;
37
+ if (superklass) {
38
+ var ctor = function() {};
39
+ ctor.prototype = superklass.prototype;
40
+ cls.prototype = new ctor();
25
41
  }
26
42
  else {
27
- var mtor = function() {};
28
- this.$m_tbl = mtor.prototype;
29
- this.$m_tor = mtor;
30
-
31
- var ctor = function() {};
32
- this.$c = new ctor();
33
- this.$c_prototype = ctor.prototype;
43
+ cls.prototype = new rb_boot_root();
34
44
  }
35
45
 
36
- this.$method_table = {};
37
- this.$const_table = {};
46
+ cls.prototype.constructor = cls;
47
+ cls.prototype.$f = T_OBJECT;
38
48
 
39
- return this;
40
- };
49
+ cls.prototype.$h = function() {
50
+ return this.$id;
51
+ };
41
52
 
42
- // RClass prototype for minimizing
43
- var Rp = RClass.prototype;
53
+ return cls;
54
+ };
44
55
 
45
56
  /**
46
- Every RClass instance is just a T_CLASS.
47
- */
48
- Rp.$flags = T_CLASS;
57
+ Make the actual (meta) classes: Object, Class, Module.
49
58
 
50
- /**
51
- RClass truthiness
59
+ @param {String} id The class id
60
+ @param {RubyClass} klass The class of the result
61
+ @param {RubyClass} superklass The superklass
52
62
  */
53
- Rp.$r = true;
63
+ function rb_boot_makemeta(id, klass, superklass) {
64
+ var meta = function() {
65
+ this.$id = rb_yield_hash();
66
+ return this;
67
+ };
54
68
 
55
- /**
56
- Every object in opal (except toll free objects) are instances of RObject
69
+ var ctor = function() {};
70
+ ctor.prototype = superklass.prototype;
71
+ meta.prototype = new ctor();
72
+
73
+ var proto = meta.prototype;
74
+ proto.$included_in = [];
75
+ proto.$m = {};
76
+ proto.$methods = [];
77
+
78
+ proto.$a = klass;
79
+ proto.$f = T_CLASS;
80
+ proto.__classid__ = id;
81
+ proto.$s = superklass;
82
+ proto.constructor = meta;
83
+
84
+ // constants
85
+ if (superklass.prototype.$constants_alloc) {
86
+ proto.$c = new superklass.prototype.$constants_alloc();
87
+ proto.$constants_alloc = function() {};
88
+ proto.$constants_alloc.prototype = proto.$c;
89
+ }
90
+ else {
91
+ proto.$constants_alloc = function() {};
92
+ proto.$c = proto.$constants_alloc.prototype;
93
+ }
57
94
 
58
- @param {RClass} klass
59
- */
60
- var RObject = Rt.RObject = function(klass) {
61
- this.$id = yield_hash();
62
- this.$klass = klass;
63
- this.$m = klass.$m_tbl;
64
- return this;
95
+ var result = new meta();
96
+ klass.prototype.$k = result;
97
+ return result;
65
98
  };
66
99
 
67
- // For minimizing
68
- var Bp = RObject.prototype;
69
-
70
100
  /**
71
- Every RObject is a T_OBJECT
101
+ Fixes the class of boot classes to their meta.
72
102
  */
73
- Bp.$flags = T_OBJECT;
74
-
75
- /**
76
- RObject truthiness
77
- */
78
- Bp.$r = true;
79
-
80
- /**
81
- The hash of all objects and classes is sinple its id
82
- */
83
- Bp.$hash = Rp.$hash = function() {
84
- return this.$id;
103
+ function rb_boot_defmetameta(klass, meta) {
104
+ klass.$k = meta;
85
105
  };
86
106
 
87
107
  /**
88
- Like boot_defclass but for root object only (i.e. BasicObject)
89
- */
90
- function boot_defrootclass(id) {
91
- var cls = new RClass(null, null);
92
- cls.$flags = T_CLASS;
93
- name_class(cls, id);
94
- const_set((cObject || cls), id, cls);
95
- return cls;
96
- }
108
+ Boot class
97
109
 
98
- /**
99
- Boots core classes - Object, Module and Class
110
+ @param {RubyClass} superklass Class to inherit from
100
111
  */
101
- function boot_defclass(id, superklass) {
102
- var cls = class_boot(superklass);
103
- name_class(cls, id);
104
- const_set((cObject || cls), id, cls);
105
- return cls;
106
- }
112
+ function rb_class_boot(superklass) {
113
+ // instances
114
+ var cls = function() {
115
+ this.$id = rb_yield_hash();
116
+ return this;
117
+ };
107
118
 
108
- function class_boot(superklass) {
109
- if (superklass) {
110
- var ctor = function() {};
111
- ctor.prototype = superklass.constructor.prototype;
119
+ var ctor = function() {};
120
+ ctor.prototype = superklass.$a.prototype;
121
+ cls.prototype = new ctor();
112
122
 
113
- var result = function() {
114
- RClass.call(this, null, superklass);
115
- return this;
116
- };
117
- result.prototype = new ctor();
123
+ var proto = cls.prototype;
124
+ proto.constructor = cls;
125
+ proto.$f = T_OBJECT;
118
126
 
119
- var klass = new result();
120
- klass.$klass = cClass;
121
- return klass;
122
- }
123
- else {
124
- var result = new RClass(null, null);
125
- return result;
126
- }
127
- }
127
+ // class itself
128
+ var meta = function() {
129
+ this.$id = rb_yield_hash();
130
+ return this;
131
+ };
128
132
 
129
- function class_real(klass) {
130
- while (klass.$flags & FL_SINGLETON) { klass = klass.$super; }
131
- return klass;
133
+ var mtor = function() {};
134
+ mtor.prototype = superklass.constructor.prototype;
135
+ meta.prototype = new mtor();
136
+
137
+ proto = meta.prototype;
138
+ proto.$a = cls;
139
+ proto.$f = T_CLASS;
140
+ proto.$m = {};
141
+ proto.$methods = [];
142
+ proto.constructor = meta;
143
+ proto.$s = superklass;
144
+
145
+ // constants
146
+ proto.$c = new superklass.$constants_alloc();
147
+ proto.$constants_alloc = function() {};
148
+ proto.$constants_alloc.prototype = proto.$c;
149
+
150
+ var result = new meta();
151
+ cls.prototype.$k = result;
152
+ return result;
132
153
  };
133
154
 
134
- Rt.class_real = class_real;
155
+ /**
156
+ Get actual class ignoring singleton classes and iclasses.
157
+ */
158
+ function rb_class_real(klass) {
159
+ while (klass.$f & FL_SINGLETON) { klass = klass.$s; }
160
+ return klass;
161
+ };
135
162
 
136
163
  /**
137
164
  Name the class with the given id.
138
165
  */
139
- function name_class(klass, id) {
166
+ function rb_name_class(klass, id) {
140
167
  klass.__classid__ = id;
141
168
  };
142
169
 
143
170
  /**
144
171
  Make metaclass for the given class
145
172
  */
146
- function make_metaclass(klass, super_class) {
147
- if (klass.$flags & T_CLASS) {
148
- if ((klass.$flags & T_CLASS) && (klass.$flags & FL_SINGLETON)) {
149
- return make_metametaclass(klass);
173
+ function rb_make_metaclass(klass, super_class) {
174
+ if (klass.$f & T_CLASS) {
175
+ if ((klass.$f & T_CLASS) && (klass.$f & FL_SINGLETON)) {
176
+ return rb_make_metametaclass(klass);
150
177
  }
151
178
  else {
152
179
  // FIXME this needs fixinfg to remove hacked stuff now in make_singleton_class
153
- var meta = class_boot(super_class);
180
+ var meta = rb_class_boot(super_class);
154
181
  // remove this??!
155
- meta.$m = meta.$klass.$m_tbl;
156
- meta.$c = meta.$klass.$c_prototype;
157
- meta.$flags |= FL_SINGLETON;
182
+ meta.$a.prototype = klass.constructor.prototype;
183
+ meta.$c = meta.$k.$c_prototype;
184
+ meta.$f |= FL_SINGLETON;
158
185
  meta.__classid__ = "#<Class:" + klass.__classid__ + ">";
159
- klass.$klass = meta;
160
- klass.$m = meta.$m_tbl;
186
+ klass.$k = meta;
161
187
  meta.$c = klass.$c;
162
- singleton_class_attached(meta, klass);
188
+ rb_singleton_class_attached(meta, klass);
163
189
  // console.log("meta id: " + klass.__classid__);
164
190
  return meta;
165
191
  }
166
192
  } else {
167
193
  // if we want metaclass of an object, do this
168
- return make_singleton_class(klass);
194
+ return rb_make_singleton_class(klass);
169
195
  }
170
196
  };
171
197
 
172
- function make_singleton_class(obj) {
173
- var orig_class = obj.$klass;
174
- var klass = class_boot(orig_class);
198
+ function rb_make_singleton_class(obj) {
199
+ var orig_class = obj.$k;
200
+ var klass = rb_class_boot(orig_class);
175
201
 
176
- klass.$flags |= FL_SINGLETON;
202
+ klass.$f |= FL_SINGLETON;
177
203
 
178
- obj.$klass = klass;
179
- obj.$m = klass.$m_tbl;
204
+ obj.$k = klass;
180
205
 
181
206
  // make methods we define here actually point to instance
182
207
  // FIXME: we could just take advantage of $bridge_prototype like we
183
208
  // use for bridged classes?? means we can make more instances...
184
209
  klass.$bridge_prototype = obj;
185
210
 
186
- singleton_class_attached(klass, obj);
211
+ rb_singleton_class_attached(klass, obj);
187
212
 
188
- klass.$klass = class_real(orig_class).$klass;
189
- klass.$m = klass.$klass.$m_tbl;
213
+ klass.$k = rb_class_real(orig_class).$k;
190
214
  klass.__classid__ = "#<Class:#<" + orig_class.__classid__ + ":" + klass.$id + ">>";
191
215
 
192
216
  return klass;
193
217
  };
194
218
 
195
- function singleton_class_attached(klass, obj) {
196
- if (klass.$flags & FL_SINGLETON) {
219
+ function rb_singleton_class_attached(klass, obj) {
220
+ if (klass.$f & FL_SINGLETON) {
197
221
  klass.__attached__ = obj;
198
222
  }
199
223
  };
200
224
 
201
- function make_metametaclass(metaclass) {
225
+ function rb_make_metametaclass(metaclass) {
202
226
  var metametaclass, super_of_metaclass;
203
227
 
204
- if (metaclass.$klass == metaclass) {
205
- metametaclass = class_boot(null);
206
- metametaclass.$klass = metametaclass;
228
+ if (metaclass.$k == metaclass) {
229
+ metametaclass = rb_class_boot(null);
230
+ metametaclass.$k = metametaclass;
207
231
  }
208
232
  else {
209
- metametaclass = class_boot(null);
210
- metametaclass.$klass = metaclass.$klass.$klass == metaclass.$klass
211
- ? make_metametaclass(metaclass.$klass)
212
- : metaclass.$klass.$klass;
233
+ metametaclass = rb_class_boot(null);
234
+ metametaclass.$k = metaclass.$k.$k == metaclass.$k
235
+ ? rb_make_metametaclass(metaclass.$k)
236
+ : metaclass.$k.$k;
213
237
  }
214
238
 
215
- metametaclass.$flags |= FL_SINGLETON;
239
+ metametaclass.$f |= FL_SINGLETON;
216
240
 
217
- singleton_class_attached(metametaclass, metaclass);
218
- metaclass.$klass = metametaclass;
219
- metaclsss.$m = metametaclass.$m_tbl;
220
- super_of_metaclass = metaclass.$super;
241
+ rb_singleton_class_attached(metametaclass, metaclass);
242
+ rb_metaclass.$k = metametaclass;
243
+ metaclass.$m = metametaclass.$m_tbl;
244
+ super_of_metaclass = metaclass.$s;
221
245
 
222
- metametaclass.$super = super_of_metaclass.$klass.__attached__
246
+ metametaclass.$s = super_of_metaclass.$k.__attached__
223
247
  == super_of_metaclass
224
- ? super_of_metaclass.$klass
225
- : make_metametaclass(super_of_metaclass);
248
+ ? super_of_metaclass.$k
249
+ : rb_make_metametaclass(super_of_metaclass);
226
250
 
227
251
  return metametaclass;
228
252
  };
229
253
 
230
- function boot_defmetametaclass(klass, metametaclass) {
231
- klass.$klass.$klass = metametaclass;
254
+ function rb_boot_defmetametaclass(klass, metametaclass) {
255
+ klass.$k.$k = metametaclass;
232
256
  };
233
257
 
234
258
  // Holds an array of all prototypes that are bridged. Any method defined on
235
259
  // Object in ruby will also be added to the bridge classes.
236
- var bridged_classes = [];
260
+ var rb_bridged_classes = [];
237
261
 
238
262
  /**
239
263
  Define toll free bridged class
240
264
  */
241
- function bridge_class(prototype, flags, id, super_class) {
242
- var klass = define_class(id, super_class);
265
+ function rb_bridge_class(prototype, flags, id, super_class) {
266
+ var klass = rb_define_class(id, super_class);
267
+
268
+ klass.$bridge_prototype = prototype;
269
+ rb_bridged_classes.push(prototype);
243
270
 
244
- prototype.$klass = klass;
271
+ prototype.$k = klass;
245
272
  prototype.$m = klass.$m_tbl;
246
- prototype.$flags = flags;
273
+ prototype.$f = flags;
247
274
  prototype.$r = true;
248
275
 
249
- prototype.$hash = function() { return flags + '_' + this; };
276
+ prototype.$h = function() { return flags + '_' + this; };
250
277
 
251
278
  return klass;
252
279
  };
253
280
 
254
- Rt.native_prototype = function(cls, proto) {
255
- proto.$klass = cls;
256
- proto.$m = cls.$m_tbl;
257
- proto.$flags = T_OBJECT;
258
- proto.$r = true;
281
+ // make native prototype from class
282
+ function rb_native_prototype(cls, proto) {
283
+ var sup = cls.$s;
259
284
 
260
- proto.$hash = function() {
261
- return this.$id || (this.$id = yield_hash());
262
- };
285
+ if (sup != rb_cObject) {
286
+ rb_raise(rb_eRuntimeError, "native_error must be used on subclass of Object only");
287
+ }
288
+
289
+ proto.$k = cls;
290
+ proto.$f = T_OBJECT;
291
+
292
+ proto.$h = function() { return this.$id || (this.$id = rb_yield_hash()); };
263
293
 
264
294
  return cls;
265
- };
295
+ }
266
296
 
267
297
  /**
268
298
  Define a new class (normal way), with the given id and superclass. Will be
269
299
  top level.
270
300
  */
271
- function define_class(id, super_klass) {
272
- return define_class_under(cObject, id, super_klass);
301
+ function rb_define_class(id, super_klass) {
302
+ return rb_define_class_under(rb_cObject, id, super_klass);
273
303
  };
274
304
 
275
- function define_class_under(base, id, super_klass) {
305
+ function rb_define_class_under(base, id, super_klass) {
276
306
  var klass;
277
307
 
278
- if (const_defined(base, id)) {
279
- klass = const_get(base, id);
308
+ if (rb_const_defined(base, id)) {
309
+ klass = rb_const_get(base, id);
280
310
 
281
- if (!(klass.$flags & T_CLASS)) {
282
- throw new Error(id + " is not a class!");
311
+ if (!(klass.$f & T_CLASS)) {
312
+ rb_raise(rb_eException, id + " is not a class");
283
313
  }
284
314
 
285
- if (klass.$super != super_klass && super_klass != cObject) {
286
- throw new Error("Wrong superclass given for " + id);
315
+ if (klass.$s != super_klass && super_klass != rb_cObject) {
316
+ rb_raise(rb_eException, "Wrong superclass given for " + id);
287
317
  }
288
318
 
289
319
  return klass;
290
320
  }
291
321
 
292
- klass = define_class_id(id, super_klass);
322
+ klass = rb_define_class_id(id, super_klass);
293
323
 
294
- if (base == cObject) {
295
- name_class(klass, id);
324
+ if (base == rb_cObject) {
325
+ rb_name_class(klass, id);
296
326
  } else {
297
- name_class(klass, base.__classid__ + '::' + id);
327
+ rb_name_class(klass, base.__classid__ + '::' + id);
298
328
  }
299
329
 
300
- const_set(base, id, klass);
330
+ rb_const_set(base, id, klass);
301
331
  klass.$parent = base;
302
332
 
303
333
  // Class#inherited hook - here is a good place to call. We check method
@@ -311,49 +341,46 @@ function define_class_under(base, id, super_klass) {
311
341
  return klass;
312
342
  };
313
343
 
314
- Rt.define_class_under = define_class_under;
315
-
316
344
  /**
317
345
  Actually create class
318
346
  */
319
- function define_class_id(id, super_klass) {
347
+ function rb_define_class_id(id, super_klass) {
320
348
  var klass;
321
349
 
322
350
  if (!super_klass) {
323
- super_klass = cObject;
351
+ super_klass = rb_cObject;
324
352
  }
325
- klass = class_create(super_klass);
326
- name_class(klass, id);
327
- make_metaclass(klass, super_klass.$klass);
353
+ klass = rb_class_create(super_klass);
354
+ rb_name_class(klass, id);
355
+ rb_make_metaclass(klass, super_klass.$k);
328
356
 
329
357
  return klass;
330
358
  };
331
359
 
332
- function class_create(super_klass) {
333
- return class_boot(super_klass);
360
+ function rb_class_create(super_klass) {
361
+ return rb_class_boot(super_klass);
334
362
  };
335
363
 
336
364
  /**
337
365
  Get singleton class of obj
338
366
  */
339
- function singleton_class(obj) {
367
+ function rb_singleton_class(obj) {
340
368
  var klass;
341
369
 
342
- if (obj.$flags & T_OBJECT) {
343
- if ((obj.$flags & T_NUMBER) || (obj.$flags & T_SYMBOL)) {
344
- raise(eTypeError, "can't define singleton");
370
+ if (obj.$f & T_OBJECT) {
371
+ if ((obj.$f & T_NUMBER) || (obj.$f & T_SYMBOL)) {
372
+ rb_raise(rb_eTypeError, "can't define singleton");
345
373
  }
346
374
  }
347
375
 
348
- if ((obj.$klass.$flags & FL_SINGLETON) && obj.$klass.__attached__ == obj) {
349
- klass = obj.$klass;
376
+ if ((obj.$k.$f & FL_SINGLETON) && obj.$k.__attached__ == obj) {
377
+ klass = obj.$k;
350
378
  }
351
379
  else {
352
- var class_id = obj.$klass.__classid__;
353
- klass = make_metaclass(obj, obj.$klass);
380
+ var class_id = obj.$k.__classid__;
381
+ klass = rb_make_metaclass(obj, obj.$k);
354
382
  }
355
383
 
356
384
  return klass;
357
385
  };
358
386
 
359
- Rt.singleton_class = singleton_class;