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
105
106
107
108
109
110
|
# File 'lib/red/nodes/call_nodes.rb', line 74
def initialize(function_sexp, *arguments_array_sexp)
options = arguments_array_sexp.pop
function = (METHOD_ESCAPE[function_sexp] || function_sexp).red!
args_array = arguments_array_sexp.last.is_sexp?(:array) ? arguments_array_sexp.last[1..-1].map {|argument_sexp| argument_sexp.red!(:as_argument => true)} : []
args_array += [options[:block_string]] if options[:block_string]
arguments = args_array.join(",")
case function_sexp
when :require
basename = File.basename((arguments_array_sexp.assoc(:array).assoc(:str).last rescue ''))
dirname = File.dirname((arguments_array_sexp.assoc(:array).assoc(:str).last rescue ''))
short_filename = File.join(@@red_filepath, basename)
long_filename = File.join(@@red_filepath, dirname, basename)
unless @@red_required.include?(basename)
@@red_required |= [basename]
file = Dir.glob(short_filename)[0] || Dir.glob('%s.red' % short_filename)[0] || Dir.glob('%s.rb' % short_filename)[0] || Dir.glob(long_filename)[0] || Dir.glob('%s.red' % long_filename)[0] || Dir.glob('%s.rb' % long_filename)[0] || Dir.glob('%s/../../source/redshift/%s' % [File.dirname(__FILE__),basename])[0] || Dir.glob('%s/../../source/redshift/%s.red' % [File.dirname(__FILE__),basename])[0]
stored_filepath = @@red_filepath
@@red_filepath = File.dirname(file)
self << hush_warnings { File.read(file).translate_to_sexp_array }.red!
@@red_filepath = stored_filepath
else
self << "false";
end
when :[]
self << "this.m$%s(%s)" % [function, arguments]
when :block_given?
self << "m$block_given_bool(%s.__block__)" % (@@red_block_arg || 'nil')
else
if Red.debug
error_function = arguments.empty? ? 'n' : 'm'
self << "((this.m$%s&&this.m$%s(%s))||(window.m$%s&&window.m%s(%s))||$%s(this,'%s'))" % [function,function,arguments,function,function,arguments,error_function,function_sexp]
else
arguments = ','+arguments unless arguments.empty?
self << "(this.m$%s||window.m$%s).call(this%s)" % [function, function, arguments]
end
@@red_methods |= [function_sexp] unless @@red_import
end
end
|