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
class Rubinius::Compiler::Parser | |
def self.processor | |
Macros::Processor | |
end | |
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 Macros | |
module Andand | |
ANDAND = :andand | |
def process_call(line, receiver, name, arguments) | |
if receiver.kind_of?(Rubinius::AST::Send) && receiver.name == ANDAND | |
local_var = gensym | |
assgn = Rubinius::AST::LocalVariableAssignment.new(line, local_var, receiver.receiver) | |
left = Rubinius::AST::LocalVariableAccess.new(line, local_var) | |
if arguments |
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
# * +convert_options+: When creating thumbnails, use this free-form options | |
# field to pass in various convert command options. Typical options are "-strip" to | |
# remove all Exif data from the image (save space for thumbnails and avatars) or | |
# "-depth 8" to specify the bit depth of the resulting conversion. See ImageMagick | |
# convert documentation for more options: (http://www.imagemagick.org/script/convert.php) | |
# Note that this option takes a hash of options, each of which correspond to the style | |
# of thumbnail being generated. You can also specify :all as a key, which will apply | |
# to all of the thumbnails being generated. If you specify options for the :original, | |
# it would be best if you did not specify destructive options, as the intent of keeping | |
# the original around is to regenerate all the thumbnails when requirements change. |
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
def before(method_sym, &block) | |
old_method = self.instance_method(method_sym) | |
if old_method.arity == 0 | |
define_method(method_sym) do | |
block.call | |
old_method.bind(self).call | |
end | |
else | |
define_method(method_sym) do |*params| | |
old_method.bind(self).call(*block.call(*params)) |
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
karol@mint ~/projects/personal/rubinius_macros $ rbx compile -B -e "if :hello then 'hello' else 'else'; end" | |
============= :__script__ ============== | |
Arguments: 0 required, 0 total | |
Locals: 0 | |
Stack size: 1 | |
Lines to IP: 1: 0..11, 0: 12..14 | |
0000: push_literal :hello | |
0002: goto_if_false 9 |
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
def fib(i, c = 0, n = 1) | |
if i == 0 | |
c | |
else | |
recur(i - 1, n, c + n) | |
end | |
end | |
puts fib(50000) |
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
# The goal is to not use the regular Symbol#to_proc | |
# (which is to_proc method in the Symbol class) | |
# but rather use an Abstract Syntax Tree transformation to | |
# transform map(&:to_s) into map {|x| x.to_s} | |
# This can be achieved by using the flexible compiler architecture | |
# in Rubinius and is presented below. | |
# | |
# First we undefine the regular Symbol#to_proc | |
class Symbol |
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
From 04c96cf7f4aefec5cfb4837bf5c13495d21d64ff Mon Sep 17 00:00:00 2001 | |
From: Karol Hosiawa <hosiawak@gmail.com> | |
Date: Tue, 7 Jun 2011 23:25:38 +0200 | |
Subject: [PATCH] updated Date constants and julian specs | |
--- | |
spec/ruby/library/date/constants_spec.rb | 69 +++++++++++++++++++++++++++ | |
spec/ruby/library/date/julian_spec.rb | 75 ++++++++++++++++++++++++++---- | |
2 files changed, 134 insertions(+), 10 deletions(-) |
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
class Blah | |
def blah | |
puts "blah!" | |
end | |
end | |
Blah.new.blah |