ikra 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ast/builder.rb +100 -0
- data/lib/ast/lexical_variables_enumerator.rb +34 -0
- data/lib/ast/method_definition.rb +37 -0
- data/lib/ast/nodes.rb +208 -0
- data/lib/ast/printer.rb +99 -0
- data/lib/ast/translator.rb +264 -0
- data/lib/ast/visitor.rb +173 -0
- data/lib/config/configuration.rb +18 -0
- data/lib/config/os_configuration.rb +56 -0
- data/lib/entity.rb +11 -0
- data/lib/ikra.rb +7 -0
- data/lib/parsing.rb +32 -0
- data/lib/resources/cuda/block_function_head.cpp +1 -0
- data/lib/resources/cuda/env_builder_copy_array.cpp +4 -0
- data/lib/resources/cuda/header.cpp +46 -0
- data/lib/resources/cuda/kernel.cpp +8 -0
- data/lib/resources/cuda/kernel_launcher.cpp +28 -0
- data/lib/resources/cuda/soa_header.cpp +4 -0
- data/lib/scope.rb +166 -0
- data/lib/sourcify/Gemfile +10 -0
- data/lib/sourcify/HISTORY.txt +88 -0
- data/lib/sourcify/LICENSE +20 -0
- data/lib/sourcify/README.rdoc +352 -0
- data/lib/sourcify/Rakefile +111 -0
- data/lib/sourcify/lib/sourcify.rb +44 -0
- data/lib/sourcify/lib/sourcify/common/parser/converter.rb +29 -0
- data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/comment.rb +23 -0
- data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb +43 -0
- data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/dstring.rb +58 -0
- data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/extensions.rb +140 -0
- data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/heredoc.rb +26 -0
- data/lib/sourcify/lib/sourcify/common/parser/source_code.rb +45 -0
- data/lib/sourcify/lib/sourcify/common/ragel/common.rl +5 -0
- data/lib/sourcify/lib/sourcify/common/ragel/expressions.rl +38 -0
- data/lib/sourcify/lib/sourcify/common/ragel/machines.rl +317 -0
- data/lib/sourcify/lib/sourcify/errors.rb +4 -0
- data/lib/sourcify/lib/sourcify/method.rb +138 -0
- data/lib/sourcify/lib/sourcify/method/methods.rb +3 -0
- data/lib/sourcify/lib/sourcify/method/methods/to_raw_source.rb +30 -0
- data/lib/sourcify/lib/sourcify/method/methods/to_sexp.rb +30 -0
- data/lib/sourcify/lib/sourcify/method/methods/to_source.rb +30 -0
- data/lib/sourcify/lib/sourcify/method/parser.rb +110 -0
- data/lib/sourcify/lib/sourcify/method/parser/converter.rb +8 -0
- data/lib/sourcify/lib/sourcify/method/parser/raw_scanner.rb +2494 -0
- data/lib/sourcify/lib/sourcify/method/parser/raw_scanner.rl +144 -0
- data/lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb +68 -0
- data/lib/sourcify/lib/sourcify/method/parser/scanner.rb +52 -0
- data/lib/sourcify/lib/sourcify/method/parser/source_code.rb +8 -0
- data/lib/sourcify/lib/sourcify/patches.rb +63 -0
- data/lib/sourcify/lib/sourcify/proc.rb +183 -0
- data/lib/sourcify/lib/sourcify/proc/methods.rb +3 -0
- data/lib/sourcify/lib/sourcify/proc/methods/source_location.rb +61 -0
- data/lib/sourcify/lib/sourcify/proc/methods/to_raw_source.rb +20 -0
- data/lib/sourcify/lib/sourcify/proc/methods/to_sexp.rb +40 -0
- data/lib/sourcify/lib/sourcify/proc/methods/to_source.rb +48 -0
- data/lib/sourcify/lib/sourcify/proc/parser.rb +51 -0
- data/lib/sourcify/lib/sourcify/proc/parser/converter.rb +8 -0
- data/lib/sourcify/lib/sourcify/proc/parser/normalizer.rb +43 -0
- data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner.rb +2498 -0
- data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner.rl +149 -0
- data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb +74 -0
- data/lib/sourcify/lib/sourcify/proc/parser/scanner.rb +49 -0
- data/lib/sourcify/lib/sourcify/proc/parser/source_code.rb +8 -0
- data/lib/sourcify/lib/sourcify/version.rb +3 -0
- data/lib/sourcify/sourcify.gemspec +31 -0
- data/lib/sourcify/spec/dump_object_space_procs.rb +84 -0
- data/lib/sourcify/spec/method/encoding_from_def_end_block_spec.rb +33 -0
- data/lib/sourcify/spec/method/encoding_from_define_method_spec.rb +37 -0
- data/lib/sourcify/spec/method/others_from_def_end_block_spec.rb +49 -0
- data/lib/sourcify/spec/method/others_from_define_method_spec.rb +63 -0
- data/lib/sourcify/spec/method/raw_scanner/block_comment_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/double_colons_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/heredoc_w_indent_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
- data/lib/sourcify/spec/method/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
- data/lib/sourcify/spec/method/raw_scanner/per_line_comment_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/single_quote_str_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/slash_operator_spec.rb +8 -0
- data/lib/sourcify/spec/method/raw_scanner/spec_helper.rb +80 -0
- data/lib/sourcify/spec/method/spec_helper.rb +1 -0
- data/lib/sourcify/spec/method/to_raw_source_spec.rb +31 -0
- data/lib/sourcify/spec/method/to_raw_source_w_specified_strip_enclosure_spec.rb +148 -0
- data/lib/sourcify/spec/method/to_sexp_from_def_end_block_w_variables_spec.rb +46 -0
- data/lib/sourcify/spec/method/to_sexp_from_def_end_block_within_irb_spec.rb +38 -0
- data/lib/sourcify/spec/method/to_sexp_from_def_end_block_within_pry_spec.rb +38 -0
- data/lib/sourcify/spec/method/to_sexp_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +56 -0
- data/lib/sourcify/spec/method/to_sexp_from_define_method_w_variables_spec.rb +52 -0
- data/lib/sourcify/spec/method/to_sexp_from_define_method_within_irb_spec.rb +42 -0
- data/lib/sourcify/spec/method/to_sexp_from_define_method_within_pry_spec.rb +42 -0
- data/lib/sourcify/spec/method/to_sexp_w_specified_strip_enclosure_spec.rb +74 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_19_extras_spec.rb +23 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_begin_spec.rb +35 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_case_spec.rb +35 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_class_spec.rb +51 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_do_end_block_spec.rb +33 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb +126 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_if_spec.rb +83 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb +141 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_method_spec.rb +33 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_module_spec.rb +59 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_unless_spec.rb +83 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_until_spec.rb +179 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_while_spec.rb +179 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_w_singleton_method_spec.rb +19 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_within_irb_spec.rb +30 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_block_within_pry_spec.rb +45 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_w_multi_blocks_and_many_matches_spec.rb +30 -0
- data/lib/sourcify/spec/method/to_source_from_def_end_w_multi_blocks_and_single_match_spec.rb +36 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_braced_block_spec.rb +113 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_do_end_block_spec.rb +145 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_many_matches_spec.rb +56 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_single_match_spec.rb +73 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_many_matches_spec.rb +36 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_no_match_spec.rb +36 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_single_match_spec.rb +28 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +103 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_many_matches_spec.rb +36 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_no_match_spec.rb +36 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_single_match_spec.rb +28 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_ignore_nested_spec.rb +36 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_within_irb_spec.rb +32 -0
- data/lib/sourcify/spec/method/to_source_from_define_method_within_pry_spec.rb +49 -0
- data/lib/sourcify/spec/method/to_source_magic_file_var_spec.rb +176 -0
- data/lib/sourcify/spec/method/to_source_magic_line_var_spec.rb +298 -0
- data/lib/sourcify/spec/method/to_source_w_specified_strip_enclosure_spec.rb +39 -0
- data/lib/sourcify/spec/no_method/unsupported_platform_spec.rb +26 -0
- data/lib/sourcify/spec/proc/19x_extras.rb +27 -0
- data/lib/sourcify/spec/proc/created_on_the_fly_proc_spec.rb +80 -0
- data/lib/sourcify/spec/proc/encoding_spec.rb +36 -0
- data/lib/sourcify/spec/proc/others_spec.rb +40 -0
- data/lib/sourcify/spec/proc/raw_scanner/block_comment_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/double_colons_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/heredoc_w_indent_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
- data/lib/sourcify/spec/proc/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
- data/lib/sourcify/spec/proc/raw_scanner/per_line_comment_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/single_quote_str_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/slash_operator_spec.rb +8 -0
- data/lib/sourcify/spec/proc/raw_scanner/spec_helper.rb +63 -0
- data/lib/sourcify/spec/proc/readme +5 -0
- data/lib/sourcify/spec/proc/spec_helper.rb +1 -0
- data/lib/sourcify/spec/proc/to_raw_source_spec.rb +33 -0
- data/lib/sourcify/spec/proc/to_raw_source_w_specified_strip_enclosure_spec.rb +69 -0
- data/lib/sourcify/spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb +46 -0
- data/lib/sourcify/spec/proc/to_sexp_variables_spec.rb +146 -0
- data/lib/sourcify/spec/proc/to_sexp_w_specified_strip_enclosure_spec.rb +60 -0
- data/lib/sourcify/spec/proc/to_sexp_within_irb_spec.rb +146 -0
- data/lib/sourcify/spec/proc/to_sexp_within_pry_spec.rb +149 -0
- data/lib/sourcify/spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb +33 -0
- data/lib/sourcify/spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb +82 -0
- data/lib/sourcify/spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb +46 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb +35 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb +35 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb +89 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb +33 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_for_spec.rb +132 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb +87 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb +103 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb +33 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb +49 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb +87 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb +189 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_while_spec.rb +189 -0
- data/lib/sourcify/spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb +46 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb +43 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb +20 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rb +45 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb +45 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rb +22 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb +84 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb +45 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb +45 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rb +22 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb +43 -0
- data/lib/sourcify/spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb +31 -0
- data/lib/sourcify/spec/proc/to_source_magic_file_var_spec.rb +127 -0
- data/lib/sourcify/spec/proc/to_source_magic_line_var_spec.rb +127 -0
- data/lib/sourcify/spec/proc/to_source_variables_spec.rb +29 -0
- data/lib/sourcify/spec/proc/to_source_w_specified_strip_enclosure_spec.rb +33 -0
- data/lib/sourcify/spec/proc/to_source_within_irb_spec.rb +38 -0
- data/lib/sourcify/spec/proc/to_source_within_pry_spec.rb +61 -0
- data/lib/sourcify/spec/raw_scanner/block_comment_shared_spec.rb +57 -0
- data/lib/sourcify/spec/raw_scanner/double_colons_shared_spec.rb +11 -0
- data/lib/sourcify/spec/raw_scanner/double_quote_str_w_interpolation_shared_spec.rb +60 -0
- data/lib/sourcify/spec/raw_scanner/double_quote_str_wo_interpolation_shared_spec.rb +86 -0
- data/lib/sourcify/spec/raw_scanner/heredoc_w_indent_shared_spec.rb +69 -0
- data/lib/sourcify/spec/raw_scanner/heredoc_wo_indent_shared_spec.rb +70 -0
- data/lib/sourcify/spec/raw_scanner/kw_block_start_alias1_shared_spec.rb +73 -0
- data/lib/sourcify/spec/raw_scanner/kw_block_start_alias2_shared_spec.rb +73 -0
- data/lib/sourcify/spec/raw_scanner/per_line_comment_shared_spec.rb +32 -0
- data/lib/sourcify/spec/raw_scanner/shared_specs.rb +3 -0
- data/lib/sourcify/spec/raw_scanner/single_quote_str_shared_spec.rb +79 -0
- data/lib/sourcify/spec/raw_scanner/slash_operator_shared_spec.rb +71 -0
- data/lib/sourcify/spec/run_build.sh +25 -0
- data/lib/sourcify/spec/spec_helper.rb +130 -0
- data/lib/symbolic/symbolic.rb +248 -0
- data/lib/symbolic/visitor.rb +51 -0
- data/lib/translator/block_translator.rb +123 -0
- data/lib/translator/command_translator.rb +421 -0
- data/lib/translator/last_returns_visitor.rb +57 -0
- data/lib/translator/local_variables_enumerator.rb +35 -0
- data/lib/translator/method_translator.rb +24 -0
- data/lib/translator/translator.rb +49 -0
- data/lib/type_aware_array.rb +71 -0
- data/lib/types/array_type.rb +51 -0
- data/lib/types/class_type.rb +128 -0
- data/lib/types/object_tracer.rb +162 -0
- data/lib/types/primitive_type.rb +73 -0
- data/lib/types/ruby_extension.rb +67 -0
- data/lib/types/ruby_type.rb +45 -0
- data/lib/types/type_inference.rb +382 -0
- data/lib/types/union_type.rb +155 -0
- metadata +321 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
if [ -z "$TRAVIS" ]; then
|
3
|
+
echo ''
|
4
|
+
echo `gem env | grep 'INSTALLATION DIRECTORY' | sed 's/.*\/\(.*\)/\1:/'`
|
5
|
+
rm -rf ~/.ruby_inline/*ParseTree*
|
6
|
+
fi
|
7
|
+
|
8
|
+
SUPPORTS_METHOD_TO_SOURCE=`ruby -e '
|
9
|
+
begin
|
10
|
+
[:source_location, :parameters].each{|meth| 1.method(:to_s).send(meth) }
|
11
|
+
raise RuntimeError if RUBY_PLATFORM =~ /java/i
|
12
|
+
puts :true
|
13
|
+
rescue NoMethodError, RuntimeError
|
14
|
+
puts :false
|
15
|
+
end
|
16
|
+
'`
|
17
|
+
|
18
|
+
if [ "$SUPPORTS_METHOD_TO_SOURCE" == "true" ]; then
|
19
|
+
bundle exec bacon spec/{proc,method}/*/*_spec.rb spec/{proc,method}/*_spec.rb
|
20
|
+
else
|
21
|
+
echo "NOTE: This ruby doesn't support Method#to_source (& friends) !!"
|
22
|
+
bundle exec bacon spec/proc/*/*_spec.rb spec/{proc,no_method}/*_spec.rb
|
23
|
+
fi
|
24
|
+
|
25
|
+
# __END__
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby_parser'
|
3
|
+
require 'ruby2ruby'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
require 'sourcify'
|
8
|
+
|
9
|
+
# ///////////////////////////////////////////////////////////
|
10
|
+
# Bacon
|
11
|
+
# ///////////////////////////////////////////////////////////
|
12
|
+
|
13
|
+
require 'bacon'
|
14
|
+
Bacon.extend(Bacon::TestUnitOutput)
|
15
|
+
Bacon.summary_on_exit
|
16
|
+
|
17
|
+
# Removing the extra noises in output, making bacon even less verbose !!
|
18
|
+
if ENV['MUTE_BACON'] == 'true'
|
19
|
+
Bacon.extend(Module.new {
|
20
|
+
|
21
|
+
def handle_requirement(description)
|
22
|
+
unless (error = yield).empty?
|
23
|
+
print error[0..0]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def handle_summary
|
28
|
+
puts "", " %d tests, %d assertions, %d failures, %d errors" %
|
29
|
+
Bacon::Counter.values_at(:specifications, :requirements, :failed, :errors)
|
30
|
+
end
|
31
|
+
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
# ///////////////////////////////////////////////////////////
|
36
|
+
# Spec helpers & matchers
|
37
|
+
# ///////////////////////////////////////////////////////////
|
38
|
+
|
39
|
+
def has_parsetree?
|
40
|
+
Object.const_defined?(:ParseTree)
|
41
|
+
end
|
42
|
+
|
43
|
+
def watever(*args, &block)
|
44
|
+
Proc.new(&block)
|
45
|
+
end
|
46
|
+
|
47
|
+
def code_to_sexp(code)
|
48
|
+
if has_parsetree?
|
49
|
+
require 'parse_tree'
|
50
|
+
Unifier.new.process(ParseTree.translate(code))
|
51
|
+
else
|
52
|
+
require 'ruby_parser'
|
53
|
+
RubyParser.new.parse(code)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def normalize_code(code)
|
58
|
+
Ruby2Ruby.new.process(code_to_sexp(code))
|
59
|
+
end
|
60
|
+
|
61
|
+
def having_source(expected, opts={}, &matcher)
|
62
|
+
lambda do |thing|
|
63
|
+
#normalize_code(expected) # added for bug fixing
|
64
|
+
normalize_code(block_given? ? thing.to_source(&matcher) : thing.to_source(opts)) \
|
65
|
+
== normalize_code(expected)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def having_raw_source(expected, opts={}, &matcher)
|
70
|
+
lambda do |thing|
|
71
|
+
found = block_given? ? thing.to_raw_source(&matcher) : thing.to_raw_source(opts)
|
72
|
+
found == expected.strip
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def having_sexp(expected, opts={}, &matcher)
|
77
|
+
lambda do |thing|
|
78
|
+
expected = eval(expected) if expected.is_a?(String)
|
79
|
+
if block_given?
|
80
|
+
thing.to_sexp(&matcher).inspect == expected.inspect
|
81
|
+
else
|
82
|
+
thing.to_sexp(opts).inspect == expected.inspect
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def capture(stdin_str = '')
|
88
|
+
begin
|
89
|
+
require 'stringio'
|
90
|
+
$o_stdin, $o_stdout, $o_stderr = $stdin, $stdout, $stderr
|
91
|
+
$stdin, $stdout, $stderr = StringIO.new(stdin_str), StringIO.new, StringIO.new
|
92
|
+
yield
|
93
|
+
{:stdout => $stdout.string, :stderr => $stderr.string}
|
94
|
+
ensure
|
95
|
+
$stdin, $stdout, $stderr = $o_stdin, $o_stdout, $o_stderr
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def irb_exec(stdin_str)
|
100
|
+
# See http://tyenglog.heroku.com/2010/9/how-to-test-irb-specific-support &
|
101
|
+
# http://tyenglog.heroku.com/2010/9/how-to-test-irb-specific-support-2-
|
102
|
+
sourcify_rb = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'sourcify.rb')
|
103
|
+
irb_feedback = /^ ?=> /
|
104
|
+
irb_opts = '--simple-prompt'
|
105
|
+
values = %x(echo "#{stdin_str}" | irb #{irb_opts} -r #{sourcify_rb}).split("\n").
|
106
|
+
grep(irb_feedback).map{|s| eval(s.sub(irb_feedback,'').strip) }
|
107
|
+
|
108
|
+
# IRB behaves slightly differently in 1.9.2 for appending newline
|
109
|
+
(values[-1].nil? && RUBY_VERSION =~ /1.9.(2|3)/) ? values[0 .. -2] : values
|
110
|
+
end
|
111
|
+
|
112
|
+
def pry_exec(stdin_str)
|
113
|
+
sourcify_rb = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'sourcify.rb')
|
114
|
+
pry_opts = '--simple-prompt --no-color'
|
115
|
+
results = []
|
116
|
+
|
117
|
+
%x(echo "#{stdin_str}" | pry #{pry_opts} -r #{sourcify_rb}).
|
118
|
+
split("\n").each do |line|
|
119
|
+
case line
|
120
|
+
when /^((?:>> |)=> )/
|
121
|
+
results << [line.sub($1,'')]
|
122
|
+
when /^( )/
|
123
|
+
results[-1] << line
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
results = results.map{|lines| eval(lines.join) }
|
128
|
+
results[-1].nil? ? results[0..-2] : results
|
129
|
+
end
|
130
|
+
|
@@ -0,0 +1,248 @@
|
|
1
|
+
require "set"
|
2
|
+
require_relative "../translator/command_translator"
|
3
|
+
require_relative "../types/primitive_type"
|
4
|
+
require_relative "../types/class_type"
|
5
|
+
require_relative "../types/union_type"
|
6
|
+
require_relative "../types/array_type"
|
7
|
+
require_relative "../type_aware_array"
|
8
|
+
require_relative "../parsing"
|
9
|
+
require_relative "../ast/nodes"
|
10
|
+
require_relative "../ast/lexical_variables_enumerator"
|
11
|
+
require_relative "../config/os_configuration"
|
12
|
+
|
13
|
+
Ikra::Configuration.check_software_configuration
|
14
|
+
|
15
|
+
module Ikra
|
16
|
+
module Symbolic
|
17
|
+
class BlockParameter
|
18
|
+
Normal = 0
|
19
|
+
Index = 1
|
20
|
+
PreviousFusion = 2
|
21
|
+
|
22
|
+
attr_accessor :name
|
23
|
+
attr_accessor :type
|
24
|
+
attr_accessor :source_type
|
25
|
+
|
26
|
+
def initialize(name:, type:, source_type: Normal)
|
27
|
+
@name = name
|
28
|
+
@type = type
|
29
|
+
@source_type = source_type
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module ArrayCommand
|
34
|
+
|
35
|
+
attr_reader :unique_id # [Fixnum] Returns a unique ID for this command. It is used during name mangling in the code generator to determine the name of array identifiers (and do other stuff?).
|
36
|
+
|
37
|
+
@@unique_id = 1
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
super
|
41
|
+
|
42
|
+
# Generate unique ID
|
43
|
+
@unique_id = @@unique_id
|
44
|
+
@@unique_id += 1
|
45
|
+
end
|
46
|
+
|
47
|
+
def [](index)
|
48
|
+
if @result == nil
|
49
|
+
execute
|
50
|
+
end
|
51
|
+
|
52
|
+
@result[index]
|
53
|
+
end
|
54
|
+
|
55
|
+
def execute
|
56
|
+
@result = Translator.translate_command(self).execute
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_command
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
def pmap(&block)
|
64
|
+
ArrayMapCommand.new(self, block)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns a collection of the names of all block parameters.
|
68
|
+
# @return [Array(Symbol)] list of block parameters
|
69
|
+
def block_parameter_names
|
70
|
+
block.parameters.map do |param|
|
71
|
+
param[1]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Returns the size (number of elements) of the result, after executing the parallel section.
|
76
|
+
# @return [Fixnum] size
|
77
|
+
def size
|
78
|
+
raise NotImplementedError
|
79
|
+
end
|
80
|
+
|
81
|
+
def target
|
82
|
+
raise NotImplementedError
|
83
|
+
end
|
84
|
+
|
85
|
+
# Returns the abstract syntax tree for a parallel section.
|
86
|
+
def ast
|
87
|
+
# TODO: add caching for AST here
|
88
|
+
# TODO: maybe set dummy class_owner here?
|
89
|
+
parser_local_vars = block.binding.local_variables + block_parameter_names
|
90
|
+
source = Parsing.parse_block(block, parser_local_vars)
|
91
|
+
AST::Builder.from_parser_ast(source)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns a collection of lexical variables that are accessed within a parallel section.
|
95
|
+
# @return [Hash{Symbol => Object}]
|
96
|
+
def lexical_externals
|
97
|
+
all_lexical_vars = block.binding.local_variables
|
98
|
+
lexical_vars_enumerator = AST::LexicalVariablesEnumerator.new(all_lexical_vars)
|
99
|
+
ast.accept(lexical_vars_enumerator)
|
100
|
+
accessed_variables = lexical_vars_enumerator.lexical_variables
|
101
|
+
|
102
|
+
result = Hash.new
|
103
|
+
for var_name in accessed_variables
|
104
|
+
result[var_name] = block.binding.local_variable_get(var_name)
|
105
|
+
end
|
106
|
+
|
107
|
+
result
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns a collection of external objects that are accessed within a parallel section.
|
111
|
+
def externals
|
112
|
+
lexical_externals.keys
|
113
|
+
end
|
114
|
+
|
115
|
+
protected
|
116
|
+
|
117
|
+
# Returns the block of the parallel section.
|
118
|
+
# @return [Proc] block
|
119
|
+
def block
|
120
|
+
raise NotImplementedError
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class ArrayNewCommand
|
125
|
+
include ArrayCommand
|
126
|
+
|
127
|
+
def initialize(size, block)
|
128
|
+
super()
|
129
|
+
|
130
|
+
@size = size
|
131
|
+
@block = block
|
132
|
+
end
|
133
|
+
|
134
|
+
def size
|
135
|
+
@size
|
136
|
+
end
|
137
|
+
|
138
|
+
protected
|
139
|
+
|
140
|
+
attr_reader :block
|
141
|
+
end
|
142
|
+
|
143
|
+
class ArrayMapCommand
|
144
|
+
include ArrayCommand
|
145
|
+
|
146
|
+
attr_reader :target
|
147
|
+
|
148
|
+
def initialize(target, block)
|
149
|
+
super()
|
150
|
+
|
151
|
+
@target = target
|
152
|
+
@block = block
|
153
|
+
end
|
154
|
+
|
155
|
+
def size
|
156
|
+
@target.size
|
157
|
+
end
|
158
|
+
|
159
|
+
protected
|
160
|
+
|
161
|
+
attr_reader :block
|
162
|
+
end
|
163
|
+
|
164
|
+
class ArraySelectCommand
|
165
|
+
include ArrayCommand
|
166
|
+
|
167
|
+
attr_reader :target
|
168
|
+
|
169
|
+
def initialize(target, block)
|
170
|
+
super
|
171
|
+
|
172
|
+
@target = target
|
173
|
+
@block = block
|
174
|
+
end
|
175
|
+
|
176
|
+
# how to implement SELECT?
|
177
|
+
# idea: two return values (actual value and boolean indicator as struct type)
|
178
|
+
end
|
179
|
+
|
180
|
+
class ArrayIdentityCommand
|
181
|
+
include ArrayCommand
|
182
|
+
|
183
|
+
attr_reader :target
|
184
|
+
|
185
|
+
Block = Proc.new do |element|
|
186
|
+
element
|
187
|
+
end
|
188
|
+
|
189
|
+
@@unique_id = 1
|
190
|
+
|
191
|
+
def initialize(target)
|
192
|
+
super()
|
193
|
+
|
194
|
+
@target = target
|
195
|
+
|
196
|
+
# Ensure that base array cannot be modified
|
197
|
+
target.freeze
|
198
|
+
end
|
199
|
+
|
200
|
+
def execute
|
201
|
+
@target
|
202
|
+
end
|
203
|
+
|
204
|
+
def size
|
205
|
+
@target.size
|
206
|
+
end
|
207
|
+
|
208
|
+
# Returns a collection of external objects that are accessed within a parallel section. This includes all elements of the base array.
|
209
|
+
def externals
|
210
|
+
lexical_externals.keys + @target
|
211
|
+
end
|
212
|
+
|
213
|
+
def base_type
|
214
|
+
# TODO: add caching (@target is frozen)
|
215
|
+
type = Types::UnionType.new
|
216
|
+
|
217
|
+
@target.each do |element|
|
218
|
+
type.expand_with_singleton_type(element.class.to_ikra_type)
|
219
|
+
end
|
220
|
+
|
221
|
+
type
|
222
|
+
end
|
223
|
+
|
224
|
+
protected
|
225
|
+
|
226
|
+
def block
|
227
|
+
Block
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
class Array
|
234
|
+
class << self
|
235
|
+
def pnew(size, &block)
|
236
|
+
Ikra::Symbolic::ArrayNewCommand.new(size, block)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def pmap(&block)
|
241
|
+
Ikra::Symbolic::ArrayMapCommand.new(to_command, block)
|
242
|
+
end
|
243
|
+
|
244
|
+
def to_command
|
245
|
+
Ikra::Symbolic::ArrayIdentityCommand.new(self)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Ikra
|
2
|
+
module Symbolic
|
3
|
+
class ArrayNewCommand
|
4
|
+
def accept(visitor)
|
5
|
+
visitor.visit_array_new_command(self)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ArrayMapCommand
|
10
|
+
def accept(visitor)
|
11
|
+
visitor.visit_array_map_command(self)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ArraySelectCommand
|
16
|
+
def accept(visitor)
|
17
|
+
visitor.visit_array_select_command(self)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ArrayIdentityCommand
|
22
|
+
def accept(visitor)
|
23
|
+
visitor.visit_array_identity_command(self)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Visitor
|
28
|
+
def visit_array_command(command)
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def visit_array_new_command(command)
|
33
|
+
visit_array_command(command)
|
34
|
+
end
|
35
|
+
|
36
|
+
def visit_array_map_command(command)
|
37
|
+
visit_array_command(command)
|
38
|
+
command.target.accept(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def visit_array_select_command(command)
|
42
|
+
visit_array_command(command)
|
43
|
+
command.target.accept(self)
|
44
|
+
end
|
45
|
+
|
46
|
+
def visit_array_identity_command(command)
|
47
|
+
visit_array_command(command)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|