opal 0.3.6 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +69 -97
- data/bin/opal +2 -2
- data/{lib/core → corelib}/array.rb +85 -56
- data/corelib/boolean.rb +20 -0
- data/corelib/class.rb +58 -0
- data/{lib → corelib}/core.rb +2 -50
- data/corelib/dir.rb +22 -0
- data/{lib/core → corelib}/enumerable.rb +0 -0
- data/corelib/error.rb +19 -0
- data/{lib/core → corelib}/file.rb +7 -9
- data/{lib/core → corelib}/hash.rb +104 -144
- data/{lib/core → corelib}/kernel.rb +38 -44
- data/corelib/load_order +21 -0
- data/{lib/core → corelib}/match_data.rb +0 -0
- data/{lib/core → corelib}/module.rb +12 -8
- data/{lib/core → corelib}/nil_class.rb +2 -2
- data/{lib/core → corelib}/numeric.rb +37 -100
- data/corelib/object.rb +37 -0
- data/{lib/core → corelib}/proc.rb +3 -3
- data/corelib/range.rb +27 -0
- data/{lib/core → corelib}/regexp.rb +1 -1
- data/{lib/core → corelib}/string.rb +16 -107
- data/{lib/core → corelib}/top_self.rb +0 -0
- data/lib/opal.rb +7 -0
- data/lib/opal/browserify.rb +34 -0
- data/{opal_lib → lib}/opal/builder.rb +70 -24
- data/lib/opal/command.rb +52 -0
- data/lib/opal/context.rb +197 -0
- data/{opal_lib/opal/ruby/parser.rb → lib/opal/lexer.rb} +20 -4
- data/{opal_lib/opal/ruby → lib/opal}/nodes.rb +238 -127
- data/lib/opal/parser.rb +4894 -0
- data/{opal_lib/opal/ruby/ruby_parser.y → lib/opal/parser.y} +38 -18
- data/lib/rbp.rb +2 -0
- data/lib/rbp/package.rb +49 -0
- data/runtime/class.js +216 -189
- data/runtime/fs.js +2 -2
- data/runtime/init.js +242 -244
- data/runtime/loader.js +78 -99
- data/runtime/module.js +34 -40
- data/runtime/post.js +2 -2
- data/runtime/pre.js +1 -1
- data/runtime/runtime.js +129 -135
- data/{lib → stdlib}/dev.rb +10 -10
- data/{lib → stdlib}/racc/parser.rb +0 -6
- data/{lib → stdlib}/strscan.rb +4 -4
- metadata +57 -105
- data/lib/core/basic_object.rb +0 -51
- data/lib/core/class.rb +0 -38
- data/lib/core/dir.rb +0 -26
- data/lib/core/error.rb +0 -75
- data/lib/core/false_class.rb +0 -81
- data/lib/core/object.rb +0 -6
- data/lib/core/range.rb +0 -27
- data/lib/core/symbol.rb +0 -42
- data/lib/core/true_class.rb +0 -41
- data/lib/ospec.rb +0 -7
- data/lib/ospec/autorun.rb +0 -8
- data/lib/ospec/dsl.rb +0 -15
- data/lib/ospec/example.rb +0 -11
- data/lib/ospec/example/before_and_after_hooks.rb +0 -56
- data/lib/ospec/example/errors.rb +0 -17
- data/lib/ospec/example/example_group.rb +0 -12
- data/lib/ospec/example/example_group_factory.rb +0 -18
- data/lib/ospec/example/example_group_hierarchy.rb +0 -21
- data/lib/ospec/example/example_group_methods.rb +0 -100
- data/lib/ospec/example/example_group_proxy.rb +0 -15
- data/lib/ospec/example/example_methods.rb +0 -46
- data/lib/ospec/example/example_proxy.rb +0 -18
- data/lib/ospec/expectations.rb +0 -19
- data/lib/ospec/expectations/errors.rb +0 -8
- data/lib/ospec/expectations/fail_with.rb +0 -9
- data/lib/ospec/expectations/handler.rb +0 -33
- data/lib/ospec/helpers/scratch.rb +0 -18
- data/lib/ospec/matchers.rb +0 -24
- data/lib/ospec/matchers/be.rb +0 -1
- data/lib/ospec/matchers/generated_descriptions.rb +0 -20
- data/lib/ospec/matchers/operator_matcher.rb +0 -54
- data/lib/ospec/matchers/raise_error.rb +0 -38
- data/lib/ospec/runner.rb +0 -90
- data/lib/ospec/runner/example_group_runner.rb +0 -41
- data/lib/ospec/runner/formatter/html_formatter.rb +0 -139
- data/lib/ospec/runner/formatter/terminal_formatter.rb +0 -48
- data/lib/ospec/runner/options.rb +0 -34
- data/lib/ospec/runner/reporter.rb +0 -82
- data/opal_lib/opal.rb +0 -16
- data/opal_lib/opal/build_methods.rb +0 -51
- data/opal_lib/opal/bundle.rb +0 -70
- data/opal_lib/opal/command.rb +0 -68
- data/opal_lib/opal/context.rb +0 -81
- data/opal_lib/opal/context/console.rb +0 -10
- data/opal_lib/opal/context/file_system.rb +0 -34
- data/opal_lib/opal/context/loader.rb +0 -135
- data/opal_lib/opal/gem.rb +0 -84
- data/opal_lib/opal/rake/builder_task.rb +0 -44
- data/opal_lib/opal/rake/spec_task.rb +0 -32
- data/opal_lib/opal/ruby/ruby_parser.rb +0 -4862
- data/opal_lib/opal/version.rb +0 -4
- data/runtime/debug.js +0 -84
@@ -1,4 +1,4 @@
|
|
1
|
-
class Opal::
|
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 =
|
153
|
+
result = UnaryNode.new({:line => val[0][:line], :value => '!'} , val[1])
|
154
154
|
}
|
155
155
|
| '!' command_call
|
156
156
|
{
|
157
|
-
result =
|
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 =
|
404
|
+
result = UnaryNode.new({:line => val[0][:line], :value => '+'} , val[1])
|
407
405
|
}
|
408
406
|
| '-@' arg
|
409
407
|
{
|
410
|
-
result =
|
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 =
|
428
|
+
result = ComparisonNode.new val[1], val[0], val[2]
|
431
429
|
}
|
432
430
|
| arg '>=' arg
|
433
431
|
{
|
434
|
-
result =
|
432
|
+
result = ComparisonNode.new val[1], val[0], val[2]
|
435
433
|
}
|
436
434
|
| arg '<' arg
|
437
435
|
{
|
438
|
-
result =
|
436
|
+
result = ComparisonNode.new val[1], val[0], val[2]
|
439
437
|
}
|
440
438
|
| arg '<=' arg
|
441
439
|
{
|
442
|
-
result =
|
440
|
+
result = ComparisonNode.new val[1], val[0], val[2]
|
443
441
|
}
|
444
442
|
| arg '==' arg
|
445
443
|
{
|
446
|
-
result =
|
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 =
|
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 =
|
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
|
-
|
752
|
+
cond_push 1
|
755
753
|
}
|
756
754
|
expr_value do
|
757
755
|
{
|
758
|
-
|
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 =
|
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
data/lib/rbp/package.rb
ADDED
@@ -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
|
-
|
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
|
-
|
5
|
-
|
7
|
+
/**
|
8
|
+
Returns the hash value for the receiver. By default on regular
|
9
|
+
objects this is just the objects' id
|
6
10
|
*/
|
7
|
-
|
8
|
-
this.$id
|
9
|
-
|
11
|
+
rb_boot_root.$h = function() {
|
12
|
+
return this.$id;
|
13
|
+
};
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
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
|
-
|
21
|
-
|
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
|
-
|
24
|
-
|
37
|
+
if (superklass) {
|
38
|
+
var ctor = function() {};
|
39
|
+
ctor.prototype = superklass.prototype;
|
40
|
+
cls.prototype = new ctor();
|
25
41
|
}
|
26
42
|
else {
|
27
|
-
|
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
|
-
|
37
|
-
|
46
|
+
cls.prototype.constructor = cls;
|
47
|
+
cls.prototype.$f = T_OBJECT;
|
38
48
|
|
39
|
-
|
40
|
-
|
49
|
+
cls.prototype.$h = function() {
|
50
|
+
return this.$id;
|
51
|
+
};
|
41
52
|
|
42
|
-
|
43
|
-
|
53
|
+
return cls;
|
54
|
+
};
|
44
55
|
|
45
56
|
/**
|
46
|
-
|
47
|
-
*/
|
48
|
-
Rp.$flags = T_CLASS;
|
57
|
+
Make the actual (meta) classes: Object, Class, Module.
|
49
58
|
|
50
|
-
|
51
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
101
|
+
Fixes the class of boot classes to their meta.
|
72
102
|
*/
|
73
|
-
|
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
|
-
|
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
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
109
|
-
|
110
|
-
|
111
|
-
ctor.prototype = superklass.constructor.prototype;
|
119
|
+
var ctor = function() {};
|
120
|
+
ctor.prototype = superklass.$a.prototype;
|
121
|
+
cls.prototype = new ctor();
|
112
122
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
};
|
117
|
-
result.prototype = new ctor();
|
123
|
+
var proto = cls.prototype;
|
124
|
+
proto.constructor = cls;
|
125
|
+
proto.$f = T_OBJECT;
|
118
126
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
130
|
-
|
131
|
-
|
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
|
-
|
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
|
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
|
147
|
-
if (klass.$
|
148
|
-
if ((klass.$
|
149
|
-
return
|
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 =
|
180
|
+
var meta = rb_class_boot(super_class);
|
154
181
|
// remove this??!
|
155
|
-
meta.$
|
156
|
-
meta.$c = meta.$
|
157
|
-
meta.$
|
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.$
|
160
|
-
klass.$m = meta.$m_tbl;
|
186
|
+
klass.$k = meta;
|
161
187
|
meta.$c = klass.$c;
|
162
|
-
|
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
|
194
|
+
return rb_make_singleton_class(klass);
|
169
195
|
}
|
170
196
|
};
|
171
197
|
|
172
|
-
function
|
173
|
-
var orig_class = obj.$
|
174
|
-
var klass =
|
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.$
|
202
|
+
klass.$f |= FL_SINGLETON;
|
177
203
|
|
178
|
-
obj.$
|
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
|
-
|
211
|
+
rb_singleton_class_attached(klass, obj);
|
187
212
|
|
188
|
-
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
|
196
|
-
if (klass.$
|
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
|
225
|
+
function rb_make_metametaclass(metaclass) {
|
202
226
|
var metametaclass, super_of_metaclass;
|
203
227
|
|
204
|
-
if (metaclass.$
|
205
|
-
metametaclass =
|
206
|
-
metametaclass.$
|
228
|
+
if (metaclass.$k == metaclass) {
|
229
|
+
metametaclass = rb_class_boot(null);
|
230
|
+
metametaclass.$k = metametaclass;
|
207
231
|
}
|
208
232
|
else {
|
209
|
-
metametaclass =
|
210
|
-
metametaclass.$
|
211
|
-
?
|
212
|
-
: metaclass.$
|
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.$
|
239
|
+
metametaclass.$f |= FL_SINGLETON;
|
216
240
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
super_of_metaclass = metaclass.$
|
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.$
|
246
|
+
metametaclass.$s = super_of_metaclass.$k.__attached__
|
223
247
|
== super_of_metaclass
|
224
|
-
? super_of_metaclass.$
|
225
|
-
:
|
248
|
+
? super_of_metaclass.$k
|
249
|
+
: rb_make_metametaclass(super_of_metaclass);
|
226
250
|
|
227
251
|
return metametaclass;
|
228
252
|
};
|
229
253
|
|
230
|
-
function
|
231
|
-
klass.$
|
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
|
260
|
+
var rb_bridged_classes = [];
|
237
261
|
|
238
262
|
/**
|
239
263
|
Define toll free bridged class
|
240
264
|
*/
|
241
|
-
function
|
242
|
-
var klass =
|
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.$
|
271
|
+
prototype.$k = klass;
|
245
272
|
prototype.$m = klass.$m_tbl;
|
246
|
-
prototype.$
|
273
|
+
prototype.$f = flags;
|
247
274
|
prototype.$r = true;
|
248
275
|
|
249
|
-
prototype.$
|
276
|
+
prototype.$h = function() { return flags + '_' + this; };
|
250
277
|
|
251
278
|
return klass;
|
252
279
|
};
|
253
280
|
|
254
|
-
|
255
|
-
|
256
|
-
|
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
|
-
|
261
|
-
|
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
|
272
|
-
return
|
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
|
305
|
+
function rb_define_class_under(base, id, super_klass) {
|
276
306
|
var klass;
|
277
307
|
|
278
|
-
if (
|
279
|
-
klass =
|
308
|
+
if (rb_const_defined(base, id)) {
|
309
|
+
klass = rb_const_get(base, id);
|
280
310
|
|
281
|
-
if (!(klass.$
|
282
|
-
|
311
|
+
if (!(klass.$f & T_CLASS)) {
|
312
|
+
rb_raise(rb_eException, id + " is not a class");
|
283
313
|
}
|
284
314
|
|
285
|
-
if (klass.$
|
286
|
-
|
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 =
|
322
|
+
klass = rb_define_class_id(id, super_klass);
|
293
323
|
|
294
|
-
if (base ==
|
295
|
-
|
324
|
+
if (base == rb_cObject) {
|
325
|
+
rb_name_class(klass, id);
|
296
326
|
} else {
|
297
|
-
|
327
|
+
rb_name_class(klass, base.__classid__ + '::' + id);
|
298
328
|
}
|
299
329
|
|
300
|
-
|
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
|
347
|
+
function rb_define_class_id(id, super_klass) {
|
320
348
|
var klass;
|
321
349
|
|
322
350
|
if (!super_klass) {
|
323
|
-
super_klass =
|
351
|
+
super_klass = rb_cObject;
|
324
352
|
}
|
325
|
-
klass =
|
326
|
-
|
327
|
-
|
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
|
333
|
-
return
|
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
|
367
|
+
function rb_singleton_class(obj) {
|
340
368
|
var klass;
|
341
369
|
|
342
|
-
if (obj.$
|
343
|
-
if ((obj.$
|
344
|
-
|
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.$
|
349
|
-
klass = obj.$
|
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.$
|
353
|
-
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;
|