Created
June 28, 2011 15:13
-
-
Save hosiawak/1051353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "provides label and goto" do | |
a = 1 | |
goto :there | |
a = 2 | |
label :there | |
a.should == 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rubinius | |
module AST | |
class Goto < Node | |
def initialize(line, label) | |
@line = line | |
@label = label | |
end | |
def bytecode(g) | |
g.goto Label.get(@label, g) | |
end | |
end | |
class Label < Node | |
def initialize(line, label) | |
@line = line | |
@label = label | |
end | |
def self.get(label, g) | |
prefix = g.state.name | |
key = "#{prefix}#{label}".to_sym | |
@labels ||= { } | |
if l = @labels[key] | |
return l | |
else | |
@labels[key] = Rubinius::Generator::Label.new(g) | |
end | |
end | |
def bytecode(g) | |
self.class.get(@label, g).set! | |
end | |
end | |
end | |
end | |
module Macros | |
module Goto | |
def process_fcall(line, name, arguments) | |
label = arguments.body.first.value | |
case name | |
when :goto | |
Rubinius::AST::Goto.new(line, label) | |
when :label | |
Rubinius::AST::Label.new(line, label) | |
else | |
super | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment