Skip to content

Instantly share code, notes, and snippets.

@hosiawak
Created June 28, 2011 15:13
Show Gist options
  • Save hosiawak/1051353 to your computer and use it in GitHub Desktop.
Save hosiawak/1051353 to your computer and use it in GitHub Desktop.
it "provides label and goto" do
a = 1
goto :there
a = 2
label :there
a.should == 1
end
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