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: 1765c8c815e1
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ead874906df1
Choose a head ref
  • 4 commits
  • 12 files changed
  • 1 contributor

Commits on Nov 13, 2013

  1. Copy the full SHA
    54747ee View commit details
  2. Copy the full SHA
    0590aff View commit details
  3. Copy the full SHA
    e566caa View commit details
  4. Copy the full SHA
    ead8749 View commit details
3 changes: 1 addition & 2 deletions lib/opal/nodes/class.rb
Original file line number Diff line number Diff line change
@@ -35,8 +35,7 @@ def super_code
end

def body_code
body[1] = s(:nil) unless body[1]
stmt(compiler.returns(body))
stmt(compiler.returns(body || s(:nil)))
end
end
end
2 changes: 1 addition & 1 deletion lib/opal/nodes/def.rb
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ def compile
scope.block_name = yielder

params = process(args)
stmt_code = stmt(stmts)
stmt_code = stmt(compiler.returns(stmts))

add_temp 'self = this'

14 changes: 0 additions & 14 deletions lib/opal/nodes/definitions.rb
Original file line number Diff line number Diff line change
@@ -13,20 +13,6 @@ def compile
end
end

# :scope nodes are actually inside scopes (e.g. :module, :class).
# These are not actually the scopes themselves.
class ScopeNode < Base
handle :scope

children :body

def compile
body = self.body || s(:nil)
body = compiler.returns(body) unless scope.class_scope?
push stmt(body)
end
end

class UndefNode < Base
handle :undef

2 changes: 1 addition & 1 deletion lib/opal/nodes/module.rb
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ def compile
add_temp "#{scope.proto} = self._proto"
add_temp '$scope = self._scope'

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

line scope.to_vars
2 changes: 1 addition & 1 deletion lib/opal/nodes/singleton_class.rb
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ def compile
add_temp 'def = self._proto'

line scope.to_vars
line stmt(body)
line stmt(compiler.returns(body))
end

line "})(", recv(object), ".$singleton_class())"
5 changes: 1 addition & 4 deletions lib/opal/nodes/top.rb
Original file line number Diff line number Diff line change
@@ -30,10 +30,7 @@ def compile
end

def stmts
sexp = @sexp || s(:nil)
scope = s(:scope, sexp)
scope.line = sexp.line
scope
compiler.returns(@sexp || s(:nil))
end

def compile_irb_vars
22 changes: 4 additions & 18 deletions lib/opal/parser.rb
Original file line number Diff line number Diff line change
@@ -83,38 +83,24 @@ def new_body(compstmt, res, els, ens)

def new_def(line, recv, name, args, body)
body = s(:block, body) if body.type != :block
scope = s(:scope, body)
body << s(:nil) if body.size == 1
scope.line = body.line
args.line = line
s = s(:def, recv, name.to_sym, args, scope)
s = s(:def, recv, name.to_sym, args, body)
s.line = line
s.end_line = @lexer.line
s
end

def new_class(path, sup, body)
scope = s(:scope)
scope << body unless body.size == 1
scope.line = body.line
s = s(:class, path, sup, scope)
s
s(:class, path, sup, body)
end

def new_sclass(expr, body)
scope = s(:scope)
scope << body #unless body.size == 1
scope.line = body.line
s = s(:sclass, expr, scope)
s
s(:sclass, expr, body)
end

def new_module(path, body)
scope = s(:scope)
scope << body unless body.size == 1
scope.line = body.line
s = s(:module, path, scope)
s
s(:module, path, body)
end

def new_iter(args, body)
8 changes: 4 additions & 4 deletions spec/opal/parser/class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'spec_helper'

describe "The class keyword" do
it "returns a plain s(:scope) when given an empty body" do
opal_parse('class A; end').should == [:class, :A, nil, [:scope]]
it "returns an empty s(:block) when given an empty body" do
opal_parse('class A; end').should == [:class, :A, nil, [:block]]
end

it "does not place single expressions into a s(:block)" do
opal_parse('class A; 1; end').should == [:class, :A, nil, [:scope, [:int, 1]]]
opal_parse('class A; 1; end').should == [:class, :A, nil, [:int, 1]]
end

it "adds multiple body expressions into a s(:block)" do
opal_parse('class A; 1; 2; end').should == [:class, :A, nil, [:scope, [:block, [:int, 1], [:int, 2]]]]
opal_parse('class A; 1; 2; end').should == [:class, :A, nil, [:block, [:int, 1], [:int, 2]]]
end

it "uses nil as a placeholder when no superclass is given" do
8 changes: 4 additions & 4 deletions spec/opal/parser/def_spec.rb
Original file line number Diff line number Diff line change
@@ -3,21 +3,21 @@
describe "The def keyword" do
describe "for normal definitions" do
it "should return s(:def)" do
opal_parse("def a; end").should == [:def, nil, :a, [:args], [:scope, [:block, [:nil]]]]
opal_parse("def a; end").should == [:def, nil, :a, [:args], [:block, [:nil]]]
end

it "adds s(:nil) on an empty body" do
opal_parse("def foo; end").last.should == [:scope, [:block, [:nil]]]
opal_parse("def foo; end").last.should == [:block, [:nil]]
end
end

describe "for singleton definitions" do
it "should return s(:def)" do
opal_parse("def self.a; end").should == [:def, [:self], :a, [:args], [:scope, [:block, [:nil]]]]
opal_parse("def self.a; end").should == [:def, [:self], :a, [:args], [:block, [:nil]]]
end

it "adds s(:nil) on an empty body" do
opal_parse("def self.foo; end").last.should == [:scope, [:block, [:nil]]]
opal_parse("def self.foo; end").last.should == [:block, [:nil]]
end
end

12 changes: 6 additions & 6 deletions spec/opal/parser/lvar_spec.rb
Original file line number Diff line number Diff line change
@@ -15,24 +15,24 @@

describe "inside a def" do
it "should created by a norm arg" do
opal_parse("def a(b); b; end").should == [:def, nil, :a, [:args, :b], [:scope, [:block, [:lvar, :b]]]]
opal_parse("def a(b, c); c; end").should == [:def, nil, :a, [:args, :b, :c], [:scope, [:block, [:lvar, :c]]]]
opal_parse("def a(b); b; end").should == [:def, nil, :a, [:args, :b], [:block, [:lvar, :b]]]
opal_parse("def a(b, c); c; end").should == [:def, nil, :a, [:args, :b, :c], [:block, [:lvar, :c]]]
end

it "should be created by an opt arg" do
opal_parse("def a(b=10); b; end").should == [:def, nil, :a, [:args, :b, [:block, [:lasgn, :b, [:int, 10]]]], [:scope, [:block, [:lvar, :b]]]]
opal_parse("def a(b=10); b; end").should == [:def, nil, :a, [:args, :b, [:block, [:lasgn, :b, [:int, 10]]]], [:block, [:lvar, :b]]]
end

it "should be created by a rest arg" do
opal_parse("def a(*b); b; end").should == [:def, nil, :a, [:args, :"*b"], [:scope, [:block, [:lvar, :b]]]]
opal_parse("def a(*b); b; end").should == [:def, nil, :a, [:args, :"*b"], [:block, [:lvar, :b]]]
end

it "should be created by a block arg" do
opal_parse("def a(&b); b; end").should == [:def, nil, :a, [:args, :"&b"], [:scope, [:block, [:lvar, :b]]]]
opal_parse("def a(&b); b; end").should == [:def, nil, :a, [:args, :"&b"], [:block, [:lvar, :b]]]
end

it "should not be created from locals outside the def" do
opal_parse("a = 10; def b; a; end").should == [:block, [:lasgn, :a, [:int, 10]], [:def, nil, :b, [:args], [:scope, [:block, [:call, nil, :a, [:arglist]]]]]]
opal_parse("a = 10; def b; a; end").should == [:block, [:lasgn, :a, [:int, 10]], [:def, nil, :b, [:args], [:block, [:call, nil, :a, [:arglist]]]]]
end
end
end
8 changes: 4 additions & 4 deletions spec/opal/parser/module_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'spec_helper'

describe "The module keyword" do
it "returns a plain s(:scope) when given an empty body" do
opal_parse('module A; end').should == [:module, :A, [:scope]]
it "returns an empty s(:block) when given an empty body" do
opal_parse('module A; end').should == [:module, :A, [:block]]
end

it "does not place single expressions into a s(:block)" do
opal_parse('module A; 1; end').should == [:module, :A, [:scope, [:int, 1]]]
opal_parse('module A; 1; end').should == [:module, :A, [:int, 1]]
end

it "adds multiple body expressions into a s(:block)" do
opal_parse('module A; 1; 2; end').should == [:module, :A, [:scope, [:block, [:int, 1], [:int, 2]]]]
opal_parse('module A; 1; 2; end').should == [:module, :A, [:block, [:int, 1], [:int, 2]]]
end

it "should accept just a constant for the module name" do
4 changes: 2 additions & 2 deletions spec/opal/parser/sclass_spec.rb
Original file line number Diff line number Diff line change
@@ -6,11 +6,11 @@
end

it "does not place single expressions into an s(:block)" do
opal_parse('class << A; 1; end')[2].should == [:scope, [:int, 1]]
opal_parse('class << A; 1; end')[2].should == [:int, 1]
end

it "adds multiple body expressions into a s(:block)" do
opal_parse('class << A; 1; 2; end')[2].should == [:scope, [:block, [:int, 1], [:int, 2]]]
opal_parse('class << A; 1; 2; end')[2].should == [:block, [:int, 1], [:int, 2]]
end

it "should accept any expressions for singleton part" do