Skip to content

Commit d529c87

Browse files
committedSep 5, 2014
Merge pull request #583 from opal/dollars-n-cents
Internals, $$ Ed.
2 parents c3157a7 + aeb25c4 commit d529c87

36 files changed

+389
-391
lines changed
 

‎lib/opal/nodes/call.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def default_compile
6666

6767
if blktmp
6868
unshift "(#{blktmp} = "
69-
push ", #{blktmp}._p = ", block, ", #{blktmp})"
69+
push ", #{blktmp}.$$p = ", block, ", #{blktmp})"
7070
end
7171

7272
if splat

‎lib/opal/nodes/class.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def compile
1717

1818
in_scope do
1919
scope.name = name
20-
add_temp "#{scope.proto} = self._proto"
21-
add_temp "$scope = self._scope"
20+
add_temp "#{scope.proto} = self.$$proto"
21+
add_temp "$scope = self.$$scope"
2222

2323
body_code = self.body_code
2424
empty_line

‎lib/opal/nodes/constants.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ConstGetNode < Base
4949
def compile
5050
push "(("
5151
push expr(base)
52-
push ")._scope.get('#{name}'))"
52+
push ").$$scope.get('#{name}'))"
5353
end
5454
end
5555

‎lib/opal/nodes/def.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def compile
7070
scope_name = scope.identity
7171

7272
if scope.uses_block?
73-
add_temp "$iter = #{scope_name}._p"
73+
add_temp "$iter = #{scope_name}.$$p"
7474
add_temp "#{yielder} = $iter || nil"
7575

76-
line "#{scope_name}._p = null;"
76+
line "#{scope_name}.$$p = null;"
7777
end
7878

7979
unshift "\n#{current_indent}", scope.to_vars
@@ -107,9 +107,9 @@ def compile
107107
elsif scope.iter?
108108
wrap "$opal.defn(self, '$#{mid}', ", ')'
109109
elsif scope.type == :sclass
110-
unshift "self._proto#{jsid} = "
110+
unshift "self.$$proto#{jsid} = "
111111
elsif scope.top?
112-
unshift "$opal.Object._proto#{jsid} = "
112+
unshift "$opal.Object.$$proto#{jsid} = "
113113
else
114114
unshift "def#{jsid} = "
115115
end

‎lib/opal/nodes/defined.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ def compile_colon2
7575
# does not raise errors is needed
7676
push "(function(){ try { return (("
7777
push expr(value)
78-
push ") != null ? 'constant' : nil); } catch (err) { if (err._klass"
78+
push ") != null ? 'constant' : nil); } catch (err) { if (err.$$class"
7979
push " === Opal.NameError) { return nil; } else { throw(err); }}; })()"
8080
end
8181

8282
def compile_colon3
83-
push "($opal.Object._scope.#{value[1]} == null ? nil : 'constant')"
83+
push "($opal.Object.$$scope.#{value[1]} == null ? nil : 'constant')"
8484
end
8585

8686
def compile_cvar

‎lib/opal/nodes/definitions.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def compile
4242
scope.methods << "$#{new_name[1]}"
4343
push "$opal.defn(self, '$#{new_name[1]}', #{scope.proto}#{old_mid})"
4444
else
45-
push "self._proto#{new_mid} = self._proto#{old_mid}"
45+
push "self.$$proto#{new_mid} = self.$$proto#{old_mid}"
4646
end
4747
end
4848
end

‎lib/opal/nodes/helpers.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def js_truthy(sexp)
7676
end
7777

7878
with_temp do |tmp|
79-
[fragment("((#{tmp} = "), expr(sexp), fragment(") !== nil && (!#{tmp}._isBoolean || #{tmp} == true))")]
79+
[fragment("((#{tmp} = "), expr(sexp), fragment(") !== nil && (!#{tmp}.$$is_boolean || #{tmp} == true))")]
8080
end
8181
end
8282

@@ -90,7 +90,7 @@ def js_falsy(sexp)
9090
end
9191

9292
with_temp do |tmp|
93-
[fragment("((#{tmp} = "), expr(sexp), fragment(") === nil || (#{tmp}._isBoolean && #{tmp} == false))")]
93+
[fragment("((#{tmp} = "), expr(sexp), fragment(") === nil || (#{tmp}.$$is_boolean && #{tmp} == false))")]
9494
end
9595
end
9696

‎lib/opal/nodes/iter.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def compile
2525

2626
in_scope do
2727
identity = scope.identify!
28-
add_temp "self = #{identity}._s || this"
28+
add_temp "self = #{identity}.$$s || this"
2929

3030
compile_args(args[1..-1], opt_args, params)
3131

@@ -39,7 +39,7 @@ def compile
3939
scope.add_temp block_arg
4040
scope_name = scope.identify!
4141

42-
line "#{block_arg} = #{scope_name}._p || nil, #{scope_name}._p = null;"
42+
line "#{block_arg} = #{scope_name}.$$p || nil, #{scope_name}.$$p = null;"
4343
end
4444

4545
body_code = stmt(body)
@@ -51,7 +51,7 @@ def compile
5151
unshift to_vars
5252

5353
unshift "(#{identity} = function(#{params.join ', '}){"
54-
push "}, #{identity}._s = self, #{identity})"
54+
push "}, #{identity}.$$s = self, #{identity})"
5555
end
5656

5757
def compile_args(args, opt_args, params)

‎lib/opal/nodes/masgn.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def compile
1818
push "#{tmp} = $opal.to_ary(", expr(rhs[1]), ")"
1919
elsif rhs.type == :splat
2020
push "(#{tmp} = ", expr(rhs[1]), ")['$to_a'] ? (#{tmp} = #{tmp}['$to_a']())"
21-
push " : (#{tmp})._isArray ? #{tmp} : (#{tmp} = [#{tmp}])"
21+
push " : (#{tmp}).$$is_array ? #{tmp} : (#{tmp} = [#{tmp}])"
2222
else
2323
raise "unsupported mlhs type"
2424
end

‎lib/opal/nodes/module.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def compile
1616

1717
in_scope do
1818
scope.name = name
19-
add_temp "#{scope.proto} = self._proto"
20-
add_temp '$scope = self._scope'
19+
add_temp "#{scope.proto} = self.$$proto"
20+
add_temp '$scope = self.$$scope'
2121

2222
body_code = stmt(body || s(:nil))
2323
empty_line

‎lib/opal/nodes/singleton_class.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def compile
1111
push "(function(self) {"
1212

1313
in_scope do
14-
add_temp '$scope = self._scope'
15-
add_temp 'def = self._proto'
14+
add_temp '$scope = self.$$scope'
15+
add_temp 'def = self.$$proto'
1616

1717
line scope.to_vars
1818
line stmt(compiler.returns(body))

‎lib/opal/nodes/super.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def compile_dispatcher
1818
if scope.def?
1919
scope.uses_block!
2020
scope_name = scope.identify!
21-
class_name = scope.parent.name ? "$#{scope.parent.name}" : 'self._klass._proto'
21+
class_name = scope.parent.name ? "$#{scope.parent.name}" : 'self.$$class.$$proto'
2222

2323
if scope.defs
2424
push "$opal.find_super_dispatcher(self, '#{scope.mid.to_s}', #{scope_name}, "
@@ -31,7 +31,7 @@ def compile_dispatcher
3131
end
3232
elsif scope.iter?
3333
chain, cur_defn, mid = scope.get_super_chain
34-
trys = chain.map { |c| "#{c}._def" }.join(' || ')
34+
trys = chain.map { |c| "#{c}.$$def" }.join(' || ')
3535

3636
push "$opal.find_iter_super_dispatcher(self, #{mid}, (#{trys} || #{cur_defn}), null)"
3737
else

‎opal/corelib/array.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Array
44
include Enumerable
55

66
# Mark all javascript arrays as being valid ruby arrays
7-
`def._isArray = true`
7+
`def.$$is_array = true`
88

99
def self.[](*objects)
1010
objects
@@ -244,7 +244,7 @@ def ==(other)
244244
var a = self[i],
245245
b = other[i];
246246
247-
if (a._isArray && b._isArray && (a === self)) {
247+
if (a.$$is_array && b.$$is_array && (a === self)) {
248248
continue;
249249
}
250250
@@ -721,7 +721,7 @@ def eql?(other)
721721
var a = self[i],
722722
b = other[i];
723723
724-
if (a._isArray && b._isArray && (a === self)) {
724+
if (a.$$is_array && b.$$is_array && (a === self)) {
725725
continue;
726726
}
727727
@@ -916,7 +916,7 @@ def flatten!(level = undefined)
916916
end
917917

918918
def hash
919-
`self._id || (self._id = Opal.uid())`
919+
`self.$$id || (self.$$id = Opal.uid())`
920920
end
921921

922922
def include?(member)

‎opal/corelib/array/inheritance.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ def self.inherited(klass)
33
replace = Class.new(Array::Wrapper)
44

55
%x{
6-
klass._proto = replace._proto;
7-
klass._proto._klass = klass;
8-
klass._alloc = replace._alloc;
9-
klass.__parent = #{Array::Wrapper};
6+
klass.$$proto = replace.$$proto;
7+
klass.$$proto.$$class = klass;
8+
klass.$$alloc = replace.$$alloc;
9+
klass.$$parent = #{Array::Wrapper};
1010
1111
klass.$allocate = replace.$allocate;
1212
klass.$new = replace.$new;
@@ -79,7 +79,7 @@ def *(other)
7979
%x{
8080
var result = #{@literal * other};
8181
82-
if (result._isArray) {
82+
if (result.$$is_array) {
8383
return #{self.class.allocate(`result`)}
8484
}
8585
else {
@@ -92,7 +92,7 @@ def [](index, length = undefined)
9292
%x{
9393
var result = #{@literal.slice(index, length)};
9494
95-
if (result._isArray && (index._isRange || length !== undefined)) {
95+
if (result.$$is_array && (index.$$is_range || length !== undefined)) {
9696
return #{self.class.allocate(`result`)}
9797
}
9898
else {

‎opal/corelib/basic_object.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def ==(other)
77
end
88

99
def __id__
10-
`self._id || (self._id = Opal.uid())`
10+
`self.$$id || (self.$$id = Opal.uid())`
1111
end
1212

1313
def __send__(symbol, *args, &block)
@@ -16,14 +16,14 @@ def __send__(symbol, *args, &block)
1616
1717
if (func) {
1818
if (block !== nil) {
19-
func._p = block;
19+
func.$$p = block;
2020
}
2121
2222
return func.apply(self, args);
2323
}
2424
2525
if (block !== nil) {
26-
self.$method_missing._p = block;
26+
self.$method_missing.$$p = block;
2727
}
2828
2929
return self.$method_missing.apply(self, [symbol].concat(args));
@@ -41,12 +41,12 @@ def instance_eval(&block)
4141
Kernel.raise ArgumentError, "no block given" unless block
4242

4343
%x{
44-
var old = block._s,
44+
var old = block.$$s,
4545
result;
4646
47-
block._s = null;
47+
block.$$s = null;
4848
result = block.call(self, self);
49-
block._s = old;
49+
block.$$s = old;
5050
5151
return result;
5252
}
@@ -56,12 +56,12 @@ def instance_exec(*args, &block)
5656
Kernel.raise ArgumentError, "no block given" unless block
5757

5858
%x{
59-
var block_self = block._s,
59+
var block_self = block.$$s,
6060
result;
6161
62-
block._s = null;
62+
block.$$s = null;
6363
result = block.apply(self, args);
64-
block._s = block_self;
64+
block.$$s = block_self;
6565
6666
return result;
6767
}

‎opal/corelib/boolean.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Boolean
2-
`def._isBoolean = true`
2+
`def.$$is_boolean = true`
33

44
class << self
55
undef_method :new

‎opal/corelib/class.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
class Class
44
def self.new(sup = Object, &block)
55
%x{
6-
if (!sup._isClass || sup.__mod__) {
6+
if (!sup.$$is_class || sup.$$mod) {
77
#{raise TypeError, "superclass must be a Class"};
88
}
99
1010
function AnonClass(){};
1111
var klass = Opal.boot(sup, AnonClass)
12-
klass._name = nil;
13-
klass.__parent = sup;
12+
klass.$$name = nil;
13+
klass.$$parent = sup;
1414
1515
// inherit scope from parent
16-
$opal.create_scope(sup._scope, klass);
16+
$opal.create_scope(sup.$$scope, klass);
1717
1818
sup.$inherited(klass);
1919
2020
if (block !== nil) {
21-
var block_self = block._s;
22-
block._s = null;
21+
var block_self = block.$$s;
22+
block.$$s = null;
2323
block.call(klass);
24-
block._s = block_self;
24+
block.$$s = block_self;
2525
}
2626
2727
return klass;
@@ -30,8 +30,8 @@ def self.new(sup = Object, &block)
3030

3131
def allocate
3232
%x{
33-
var obj = new self._alloc;
34-
obj._id = Opal.uid();
33+
var obj = new self.$$alloc;
34+
obj.$$id = Opal.uid();
3535
return obj;
3636
}
3737
end
@@ -43,13 +43,13 @@ def new(*args, &block)
4343
%x{
4444
var obj = #{allocate};
4545
46-
obj.$initialize._p = block;
46+
obj.$initialize.$$p = block;
4747
obj.$initialize.apply(obj, args);
4848
return obj;
4949
}
5050
end
5151

5252
def superclass
53-
`self._super || nil`
53+
`self.$$super || nil`
5454
end
5555
end

0 commit comments

Comments
 (0)
Please sign in to comment.