Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e2f8d377b97a
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dc8f5fa5545c
Choose a head ref
  • 5 commits
  • 31 files changed
  • 1 contributor

Commits on Oct 25, 2014

  1. Various runtime cleanups

    Remove usage of $opal in favor of Opal.
    
    Rename Opal.$return to Opal.ret.
    
    Rename Opal.$yield1 to Opal.yield1.
    
    Rename Opal.$yieldX to Opal.yieldX.
    meh committed Oct 25, 2014
    Copy the full SHA
    97ba4ba View commit details
  2. 1
    Copy the full SHA
    f408847 View commit details

Commits on Oct 26, 2014

  1. Copy the full SHA
    fcc978d View commit details
  2. Copy the full SHA
    22edc27 View commit details
  3. Cleanup Opal.rescue

    meh committed Oct 26, 2014
    Copy the full SHA
    dc8f5fa View commit details
2 changes: 1 addition & 1 deletion lib/opal/nodes/call.rb
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ def compile_irb_var
with_temp do |tmp|
lvar = variable(meth)
call = s(:call, s(:self), meth.intern, s(:arglist))
push "((#{tmp} = $opal.irb_vars.#{lvar}) == null ? ", expr(call), " : #{tmp})"
push "((#{tmp} = Opal.irb_vars.#{lvar}) == null ? ", expr(call), " : #{tmp})"
end
end

6 changes: 3 additions & 3 deletions lib/opal/nodes/constants.rb
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ class ConstDeclarationNode < Base

def compile
push expr(base)
wrap "$opal.cdecl($scope, '#{name}', ", ")"
wrap "Opal.cdecl($scope, '#{name}', ", ")"
end
end

@@ -33,7 +33,7 @@ class ConstAssignNode < Base
children :base, :name, :value

def compile
push "$opal.casgn("
push "Opal.casgn("
push expr(base)
push ", '#{name}', "
push expr(value)
@@ -69,7 +69,7 @@ class TopConstAssignNode < Base
children :name, :value

def compile
push "$opal.casgn($opal.Object, '#{name}', "
push "Opal.casgn(Opal.Object, '#{name}', "
push expr(value)
push ")"
end
14 changes: 7 additions & 7 deletions lib/opal/nodes/def.rb
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ def compile

if scope.catch_return
unshift "try {\n"
line "} catch ($returner) { if ($returner === $opal.returner) { return $returner.$v }"
line "} catch ($returner) { if ($returner === Opal.returner) { return $returner.$v }"
push " throw $returner; }"
end
end
@@ -97,19 +97,19 @@ def compile
line "}"

if recvr
unshift '$opal.defs(', recv(recvr), ", '$#{mid}', "
unshift 'Opal.defs(', recv(recvr), ", '$#{mid}', "
push ')'
elsif scope.class? and %w(Object BasicObject).include?(scope.name)
wrap "$opal.defn(self, '$#{mid}', ", ')'
wrap "Opal.defn(self, '$#{mid}', ", ')'
elsif scope.class_scope?
scope.methods << "$#{mid}"
unshift "#{scope.proto}#{jsid} = "
elsif scope.iter?
wrap "$opal.defn(self, '$#{mid}', ", ')'
wrap "Opal.defn(self, '$#{mid}', ", ')'
elsif scope.type == :sclass
unshift "self.$$proto#{jsid} = "
elsif scope.top?
unshift "$opal.Object.$$proto#{jsid} = "
unshift "Opal.Object.$$proto#{jsid} = "
else
unshift "def#{jsid} = "
end
@@ -130,9 +130,9 @@ def arity_check(args, opt, splat, block_name, mid)
aritycode = "var $arity = arguments.length;"

if arity < 0 # splat or opt args
aritycode + "if ($arity < #{-(arity + 1)}) { $opal.ac($arity, #{arity}, this, #{meth}); }"
aritycode + "if ($arity < #{-(arity + 1)}) { Opal.ac($arity, #{arity}, this, #{meth}); }"
else
aritycode + "if ($arity !== #{arity}) { $opal.ac($arity, #{arity}, this, #{meth}); }"
aritycode + "if ($arity !== #{arity}) { Opal.ac($arity, #{arity}, this, #{meth}); }"
end
end
end
4 changes: 2 additions & 2 deletions lib/opal/nodes/defined.rb
Original file line number Diff line number Diff line change
@@ -80,11 +80,11 @@ def compile_colon2
end

def compile_colon3
push "($opal.Object.$$scope.#{value[1]} == null ? nil : 'constant')"
push "(Opal.Object.$$scope.#{value[1]} == null ? nil : 'constant')"
end

def compile_cvar
push "($opal.cvars['#{value[1]}'] != null ? 'class variable' : nil)"
push "(Opal.cvars['#{value[1]}'] != null ? 'class variable' : nil)"
end

def compile_gvar
2 changes: 1 addition & 1 deletion lib/opal/nodes/definitions.rb
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ def old_mid
def compile
if scope.class? or scope.module?
scope.methods << "$#{new_name[1]}"
push "$opal.defn(self, '$#{new_name[1]}', #{scope.proto}#{old_mid})"
push "Opal.defn(self, '$#{new_name[1]}', #{scope.proto}#{old_mid})"
else
push "self.$$proto#{new_mid} = self.$$proto#{old_mid}"
end
2 changes: 1 addition & 1 deletion lib/opal/nodes/logic.rb
Original file line number Diff line number Diff line change
@@ -174,7 +174,7 @@ def scope_to_catch_return
def compile
if def_scope = scope_to_catch_return
def_scope.catch_return = true
push '$opal.$return(', return_val, ')'
push 'Opal.ret(', return_val, ')'
elsif stmt?
push 'return ', return_val
else
2 changes: 1 addition & 1 deletion lib/opal/nodes/masgn.rb
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ def compile
len = rhs.size - 1
push "#{tmp} = ", expr(rhs)
elsif rhs.type == :to_ary
push "#{tmp} = $opal.to_ary(", expr(rhs[1]), ")"
push "#{tmp} = Opal.to_ary(", expr(rhs[1]), ")"
elsif rhs.type == :splat
push "(#{tmp} = ", expr(rhs[1]), ")['$to_a'] && !#{tmp}['$to_a'].$$stub ? (#{tmp} = #{tmp}['$to_a']())"
push " : (#{tmp}).$$is_array ? #{tmp} : (#{tmp} = [#{tmp}])"
2 changes: 1 addition & 1 deletion lib/opal/nodes/module.rb
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ def name_and_base
elsif cid.type == :colon2
[cid[2].to_s, expr(cid[1])]
elsif cid.type == :colon3
[cid[1].to_s, '$opal.Object']
[cid[1].to_s, 'Opal.Object']
else
raise "Bad receiver in module"
end
2 changes: 1 addition & 1 deletion lib/opal/nodes/rescue.rb
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ def compile
# if no expressions are given, then catch all errors
push "true"
else
push "$opal.$rescue($err, ["
push "Opal.rescue($err, ["
rescue_exprs.each_with_index do |rexpr, idx|
push ', ' unless idx == 0
push expr(rexpr)
2 changes: 1 addition & 1 deletion lib/opal/nodes/scope.rb
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ def to_vars
# Generates code for this module to donate methods
def to_donate_methods
if should_donate? and !@methods.empty?
fragment("%s;$opal.donate(self, [%s]);" % [@compiler.parser_indent, @methods.map(&:inspect).join(', ')])
fragment("%s;Opal.donate(self, [%s]);" % [@compiler.parser_indent, @methods.map(&:inspect).join(', ')])
else
fragment("")
end
6 changes: 3 additions & 3 deletions lib/opal/nodes/super.rb
Original file line number Diff line number Diff line change
@@ -21,19 +21,19 @@ def compile_dispatcher
class_name = scope.parent.name ? "$#{scope.parent.name}" : 'self.$$class.$$proto'

if scope.defs
push "$opal.find_super_dispatcher(self, '#{scope.mid.to_s}', #{scope_name}, "
push "Opal.find_super_dispatcher(self, '#{scope.mid.to_s}', #{scope_name}, "
push iter
push ", #{class_name})"
else
push "$opal.find_super_dispatcher(self, '#{scope.mid.to_s}', #{scope_name}, "
push "Opal.find_super_dispatcher(self, '#{scope.mid.to_s}', #{scope_name}, "
push iter
push ")"
end
elsif scope.iter?
chain, cur_defn, mid = scope.get_super_chain
trys = chain.map { |c| "#{c}.$$def" }.join(' || ')

push "$opal.find_iter_super_dispatcher(self, #{mid}, (#{trys} || #{cur_defn}), null)"
push "Opal.find_iter_super_dispatcher(self, #{mid}, (#{trys} || #{cur_defn}), null)"
else
raise "Cannot call super() from outside a method block"
end
18 changes: 9 additions & 9 deletions lib/opal/nodes/top.rb
Original file line number Diff line number Diff line change
@@ -14,13 +14,13 @@ def compile

opening
in_scope do
line "$opal.dynamic_require_severity = #{compiler.dynamic_require_severity.to_s.inspect};"
line "Opal.dynamic_require_severity = #{compiler.dynamic_require_severity.to_s.inspect};"
body_code = stmt(stmts)
body_code = [body_code] unless body_code.is_a?(Array)

add_temp 'self = $opal.top'
add_temp '$scope = $opal'
add_temp 'nil = $opal.nil'
add_temp 'self = Opal.top'
add_temp '$scope = Opal'
add_temp 'nil = Opal.nil'

add_used_helpers
add_used_operators
@@ -39,9 +39,9 @@ def compile
def opening
if compiler.requirable?
path = Pathname(compiler.file).cleanpath.to_s
line "Opal.modules[#{path.inspect}] = function($opal) {"
line "Opal.modules[#{path.inspect}] = function(Opal) {"
else
line "(function($opal) {"
line "(function(Opal) {"
end
end

@@ -59,13 +59,13 @@ def stmts

def compile_irb_vars
if compiler.irb?
line "if (!$opal.irb_vars) { $opal.irb_vars = {}; }"
line "if (!Opal.irb_vars) { Opal.irb_vars = {}; }"
end
end

def add_used_helpers
helpers = compiler.helpers.to_a
helpers.to_a.each { |h| add_temp "$#{h} = $opal.#{h}" }
helpers.to_a.each { |h| add_temp "$#{h} = Opal.#{h}" }
end

def add_used_operators
@@ -82,7 +82,7 @@ def compile_method_stubs
if compiler.method_missing?
calls = compiler.method_calls
stubs = calls.to_a.map { |k| "'$#{k}'" }.join(', ')
line "$opal.add_stubs([#{stubs}]);"
line "Opal.add_stubs([#{stubs}]);" unless stubs.empty?
end
end

10 changes: 5 additions & 5 deletions lib/opal/nodes/variables.rb
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ def compile

with_temp do |tmp|
push property(var_name.to_s)
wrap "((#{tmp} = $opal.irb_vars", ") == null ? nil : #{tmp})"
wrap "((#{tmp} = Opal.irb_vars", ") == null ? nil : #{tmp})"
end
end
end
@@ -32,7 +32,7 @@ def using_irb?

def compile
if using_irb?
push "$opal.irb_vars#{property var_name.to_s} = "
push "Opal.irb_vars#{property var_name.to_s} = "
push expr(value)
else
add_local variable(var_name.to_s)
@@ -126,7 +126,7 @@ class ClassVariableNode < Base

def compile
with_temp do |tmp|
push "((#{tmp} = $opal.cvars['#{name}']) == null ? nil : #{tmp})"
push "((#{tmp} = Opal.cvars['#{name}']) == null ? nil : #{tmp})"
end
end
end
@@ -137,7 +137,7 @@ class ClassVarAssignNode < Base
children :name, :value

def compile
push "($opal.cvars['#{name}'] = "
push "(Opal.cvars['#{name}'] = "
push expr(value)
push ")"
end
@@ -149,7 +149,7 @@ class ClassVarDeclNode < Base
children :name, :value

def compile
push "($opal.cvars['#{name}'] = "
push "(Opal.cvars['#{name}'] = "
push expr(value)
push ")"
end
6 changes: 3 additions & 3 deletions lib/opal/nodes/yield.rb
Original file line number Diff line number Diff line change
@@ -11,14 +11,14 @@ def compile_call(children, level)

if yields_single_arg?(children)
push expr(children.first)
wrap "$opal.$yield1(#{block_name}, ", ')'
wrap "Opal.yield1(#{block_name}, ", ')'
else
push expr(s(:arglist, *children))

if uses_splat?(children)
wrap "$opal.$yieldX(#{block_name}, ", ')'
wrap "Opal.yieldX(#{block_name}, ", ')'
else
wrap "$opal.$yieldX(#{block_name}, [", '])'
wrap "Opal.yieldX(#{block_name}, [", '])'
end
end
end
14 changes: 7 additions & 7 deletions opal/corelib/array.rb
Original file line number Diff line number Diff line change
@@ -462,7 +462,7 @@ def cycle(n = nil, &block)
%x{
while (true) {
for (var i = 0, length = self.length; i < length; i++) {
var value = $opal.$yield1(block, self[i]);
var value = Opal.yield1(block, self[i]);
if (value === $breaker) {
return $breaker.$v;
@@ -480,7 +480,7 @@ def cycle(n = nil, &block)
while (n > 0) {
for (var i = 0, length = self.length; i < length; i++) {
var value = $opal.$yield1(block, self[i]);
var value = Opal.yield1(block, self[i]);
if (value === $breaker) {
return $breaker.$v;
@@ -524,7 +524,7 @@ def collect(&block)
var result = [];
for (var i = 0, length = self.length; i < length; i++) {
var value = Opal.$yield1(block, self[i]);
var value = Opal.yield1(block, self[i]);
if (value === $breaker) {
return $breaker.$v;
@@ -542,7 +542,7 @@ def collect!(&block)

%x{
for (var i = 0, length = self.length; i < length; i++) {
var value = Opal.$yield1(block, self[i]);
var value = Opal.yield1(block, self[i]);
if (value === $breaker) {
return $breaker.$v;
@@ -677,7 +677,7 @@ def each(&block)

%x{
for (var i = 0, length = self.length; i < length; i++) {
var value = $opal.$yield1(block, self[i]);
var value = Opal.yield1(block, self[i]);
if (value == $breaker) {
return $breaker.$v;
@@ -693,7 +693,7 @@ def each_index(&block)

%x{
for (var i = 0, length = self.length; i < length; i++) {
var value = $opal.$yield1(block, i);
var value = Opal.yield1(block, i);
if (value === $breaker) {
return $breaker.$v;
@@ -1265,7 +1265,7 @@ def select(&block)
for (var i = 0, length = self.length, item, value; i < length; i++) {
item = self[i];
if ((value = $opal.$yield1(block, item)) === $breaker) {
if ((value = Opal.yield1(block, item)) === $breaker) {
return $breaker.$v;
}
6 changes: 3 additions & 3 deletions opal/corelib/array/inheritance.rb
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ def self.inherited(klass)
replace = Class.new(Array::Wrapper)

%x{
klass.$$proto = replace.$$proto;
klass.$$proto = replace.$$proto;
klass.$$proto.$$class = klass;
klass.$$alloc = replace.$$alloc;
klass.$$parent = #{Array::Wrapper};
klass.$$alloc = replace.$$alloc;
klass.$$parent = #{Array::Wrapper};
klass.$allocate = replace.$allocate;
klass.$new = replace.$new;
4 changes: 2 additions & 2 deletions opal/corelib/basic_object.rb
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ def instance_exec(*args, &block)

def method_missing(symbol, *args, &block)
Kernel.raise NoMethodError, `self.$inspect && !self.$inspect.$$stub` ?
"undefined method `#{symbol}' for #{inspect}:#{`self.$$class`.name}" :
"undefined method `#{symbol}' for #{`self.$$class`.name}"
"undefined method `#{symbol}' for #{inspect}:#{`self.$$class`}" :
"undefined method `#{symbol}' for #{`self.$$class`}"
end
end
2 changes: 1 addition & 1 deletion opal/corelib/class.rb
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ def self.new(sup = Object, &block)
klass.$$parent = sup;
// inherit scope from parent
$opal.create_scope(sup.$$scope, klass);
Opal.create_scope(sup.$$scope, klass);
sup.$inherited(klass);
Loading