Class: Object

Inherits:
BasicObject
Defined in:
lib/fastruby.rb,
lib/fastruby/object.rb,
lib/fastruby/sexp_extension.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decode64(value) ⇒ Object



29
30
31
# File 'lib/fastruby.rb', line 29

def self.decode64(value)
  Base64.decode64(value)
end

.execute_tree(tree, *options_hashes) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fastruby/object.rb', line 106

def self.execute_tree(tree,*options_hashes)
  options_hash = {:validate_lvar_types => true}
  options_hashes.each do |opt|
    options_hash.merge!(opt)
  end

  require "fastruby/fastruby_sexp"
  method_name = tree[1]

  self_ = options_hash[:self]
  self_ = self unless self_.instance_of? Class

  FastRuby.set_tree(self_, method_name, tree, options_hash[:snippet_hash], options_hash)

  class << self
    $metaclass = self
  end

  self_.build([$class_self],method_name,true)
end

Instance Method Details

#fastruby(argument, *options_hashes) ⇒ Object



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

#gc_register_objectObject



127
128
129
130
# File 'lib/fastruby/object.rb', line 127

def gc_register_object
  $refered_from_code_array = Array.new unless $refered_from_code_array
  $refered_from_code_array << self
end

#to_fastruby_sexpObject



27
28
29
# File 'lib/fastruby/sexp_extension.rb', line 27

def to_fastruby_sexp
  self
end