52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/fastruby/object.rb', line 52
def fastruby(argument, *options_hashes)
options_hash = {:validate_lvar_types => true}
options_hash[:no_cache] = true if ENV['FASTRUBY_NO_CACHE'] == "1"
options_hashes.each do |opt|
options_hash.merge!(opt)
end
objs = Array.new
unless options_hash[:no_cache]
snippet_hash = FastRuby.cache.hash_snippet(argument,options_hash[:validate_lvar_types].to_s + "^" + FastRuby::VERSION)
objs = FastRuby.cache.retrieve(snippet_hash)
end
if objs.empty?
tree = nil
require "fastruby/fastruby_sexp"
if argument.instance_of? FastRuby::FastRubySexp
tree = argument
elsif argument.instance_of? String
require "rubygems"
require "ruby_parser"
require "fastruby/sexp_extension"
tree = RubyParser.new.parse(argument).to_fastruby_sexp
else
raise ArgumentError
end
return unless tree
method_name = "_anonymous_" + rand(100000000000).to_s
Object.execute_tree(FastRuby.encapsulate_tree(tree,method_name), {:main => method_name, :self => self, :snippet_hash => snippet_hash}.merge(options_hash))
else
objs.sort{|x,y|
File.new(x).ctime <=> File.new(y).ctime
}.each do |obj|
begin
$last_obj_proc = nil
require obj
if $last_obj_proc
FastRuby.cache.register_proc(obj, $last_obj_proc)
end
FastRuby.cache.execute(obj, self.kind_of?(Class) ? self : Object)
rescue Exception => e
p e
end
end
end
end
|