ikra 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ast/builder.rb +100 -0
  3. data/lib/ast/lexical_variables_enumerator.rb +34 -0
  4. data/lib/ast/method_definition.rb +37 -0
  5. data/lib/ast/nodes.rb +208 -0
  6. data/lib/ast/printer.rb +99 -0
  7. data/lib/ast/translator.rb +264 -0
  8. data/lib/ast/visitor.rb +173 -0
  9. data/lib/config/configuration.rb +18 -0
  10. data/lib/config/os_configuration.rb +56 -0
  11. data/lib/entity.rb +11 -0
  12. data/lib/ikra.rb +7 -0
  13. data/lib/parsing.rb +32 -0
  14. data/lib/resources/cuda/block_function_head.cpp +1 -0
  15. data/lib/resources/cuda/env_builder_copy_array.cpp +4 -0
  16. data/lib/resources/cuda/header.cpp +46 -0
  17. data/lib/resources/cuda/kernel.cpp +8 -0
  18. data/lib/resources/cuda/kernel_launcher.cpp +28 -0
  19. data/lib/resources/cuda/soa_header.cpp +4 -0
  20. data/lib/scope.rb +166 -0
  21. data/lib/sourcify/Gemfile +10 -0
  22. data/lib/sourcify/HISTORY.txt +88 -0
  23. data/lib/sourcify/LICENSE +20 -0
  24. data/lib/sourcify/README.rdoc +352 -0
  25. data/lib/sourcify/Rakefile +111 -0
  26. data/lib/sourcify/lib/sourcify.rb +44 -0
  27. data/lib/sourcify/lib/sourcify/common/parser/converter.rb +29 -0
  28. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/comment.rb +23 -0
  29. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/counter.rb +43 -0
  30. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/dstring.rb +58 -0
  31. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/extensions.rb +140 -0
  32. data/lib/sourcify/lib/sourcify/common/parser/raw_scanner/heredoc.rb +26 -0
  33. data/lib/sourcify/lib/sourcify/common/parser/source_code.rb +45 -0
  34. data/lib/sourcify/lib/sourcify/common/ragel/common.rl +5 -0
  35. data/lib/sourcify/lib/sourcify/common/ragel/expressions.rl +38 -0
  36. data/lib/sourcify/lib/sourcify/common/ragel/machines.rl +317 -0
  37. data/lib/sourcify/lib/sourcify/errors.rb +4 -0
  38. data/lib/sourcify/lib/sourcify/method.rb +138 -0
  39. data/lib/sourcify/lib/sourcify/method/methods.rb +3 -0
  40. data/lib/sourcify/lib/sourcify/method/methods/to_raw_source.rb +30 -0
  41. data/lib/sourcify/lib/sourcify/method/methods/to_sexp.rb +30 -0
  42. data/lib/sourcify/lib/sourcify/method/methods/to_source.rb +30 -0
  43. data/lib/sourcify/lib/sourcify/method/parser.rb +110 -0
  44. data/lib/sourcify/lib/sourcify/method/parser/converter.rb +8 -0
  45. data/lib/sourcify/lib/sourcify/method/parser/raw_scanner.rb +2494 -0
  46. data/lib/sourcify/lib/sourcify/method/parser/raw_scanner.rl +144 -0
  47. data/lib/sourcify/lib/sourcify/method/parser/raw_scanner_extensions.rb +68 -0
  48. data/lib/sourcify/lib/sourcify/method/parser/scanner.rb +52 -0
  49. data/lib/sourcify/lib/sourcify/method/parser/source_code.rb +8 -0
  50. data/lib/sourcify/lib/sourcify/patches.rb +63 -0
  51. data/lib/sourcify/lib/sourcify/proc.rb +183 -0
  52. data/lib/sourcify/lib/sourcify/proc/methods.rb +3 -0
  53. data/lib/sourcify/lib/sourcify/proc/methods/source_location.rb +61 -0
  54. data/lib/sourcify/lib/sourcify/proc/methods/to_raw_source.rb +20 -0
  55. data/lib/sourcify/lib/sourcify/proc/methods/to_sexp.rb +40 -0
  56. data/lib/sourcify/lib/sourcify/proc/methods/to_source.rb +48 -0
  57. data/lib/sourcify/lib/sourcify/proc/parser.rb +51 -0
  58. data/lib/sourcify/lib/sourcify/proc/parser/converter.rb +8 -0
  59. data/lib/sourcify/lib/sourcify/proc/parser/normalizer.rb +43 -0
  60. data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner.rb +2498 -0
  61. data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner.rl +149 -0
  62. data/lib/sourcify/lib/sourcify/proc/parser/raw_scanner_extensions.rb +74 -0
  63. data/lib/sourcify/lib/sourcify/proc/parser/scanner.rb +49 -0
  64. data/lib/sourcify/lib/sourcify/proc/parser/source_code.rb +8 -0
  65. data/lib/sourcify/lib/sourcify/version.rb +3 -0
  66. data/lib/sourcify/sourcify.gemspec +31 -0
  67. data/lib/sourcify/spec/dump_object_space_procs.rb +84 -0
  68. data/lib/sourcify/spec/method/encoding_from_def_end_block_spec.rb +33 -0
  69. data/lib/sourcify/spec/method/encoding_from_define_method_spec.rb +37 -0
  70. data/lib/sourcify/spec/method/others_from_def_end_block_spec.rb +49 -0
  71. data/lib/sourcify/spec/method/others_from_define_method_spec.rb +63 -0
  72. data/lib/sourcify/spec/method/raw_scanner/block_comment_spec.rb +8 -0
  73. data/lib/sourcify/spec/method/raw_scanner/double_colons_spec.rb +8 -0
  74. data/lib/sourcify/spec/method/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
  75. data/lib/sourcify/spec/method/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
  76. data/lib/sourcify/spec/method/raw_scanner/heredoc_w_indent_spec.rb +8 -0
  77. data/lib/sourcify/spec/method/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
  78. data/lib/sourcify/spec/method/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
  79. data/lib/sourcify/spec/method/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
  80. data/lib/sourcify/spec/method/raw_scanner/per_line_comment_spec.rb +8 -0
  81. data/lib/sourcify/spec/method/raw_scanner/single_quote_str_spec.rb +8 -0
  82. data/lib/sourcify/spec/method/raw_scanner/slash_operator_spec.rb +8 -0
  83. data/lib/sourcify/spec/method/raw_scanner/spec_helper.rb +80 -0
  84. data/lib/sourcify/spec/method/spec_helper.rb +1 -0
  85. data/lib/sourcify/spec/method/to_raw_source_spec.rb +31 -0
  86. data/lib/sourcify/spec/method/to_raw_source_w_specified_strip_enclosure_spec.rb +148 -0
  87. data/lib/sourcify/spec/method/to_sexp_from_def_end_block_w_variables_spec.rb +46 -0
  88. data/lib/sourcify/spec/method/to_sexp_from_def_end_block_within_irb_spec.rb +38 -0
  89. data/lib/sourcify/spec/method/to_sexp_from_def_end_block_within_pry_spec.rb +38 -0
  90. data/lib/sourcify/spec/method/to_sexp_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +56 -0
  91. data/lib/sourcify/spec/method/to_sexp_from_define_method_w_variables_spec.rb +52 -0
  92. data/lib/sourcify/spec/method/to_sexp_from_define_method_within_irb_spec.rb +42 -0
  93. data/lib/sourcify/spec/method/to_sexp_from_define_method_within_pry_spec.rb +42 -0
  94. data/lib/sourcify/spec/method/to_sexp_w_specified_strip_enclosure_spec.rb +74 -0
  95. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_19_extras_spec.rb +23 -0
  96. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_begin_spec.rb +35 -0
  97. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_case_spec.rb +35 -0
  98. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_class_spec.rb +51 -0
  99. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_do_end_block_spec.rb +33 -0
  100. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb +126 -0
  101. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_if_spec.rb +83 -0
  102. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb +141 -0
  103. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_method_spec.rb +33 -0
  104. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_module_spec.rb +59 -0
  105. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_unless_spec.rb +83 -0
  106. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_until_spec.rb +179 -0
  107. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_nested_while_spec.rb +179 -0
  108. data/lib/sourcify/spec/method/to_source_from_def_end_block_w_singleton_method_spec.rb +19 -0
  109. data/lib/sourcify/spec/method/to_source_from_def_end_block_within_irb_spec.rb +30 -0
  110. data/lib/sourcify/spec/method/to_source_from_def_end_block_within_pry_spec.rb +45 -0
  111. data/lib/sourcify/spec/method/to_source_from_def_end_w_multi_blocks_and_many_matches_spec.rb +30 -0
  112. data/lib/sourcify/spec/method/to_source_from_def_end_w_multi_blocks_and_single_match_spec.rb +36 -0
  113. data/lib/sourcify/spec/method/to_source_from_define_method_w_braced_block_spec.rb +113 -0
  114. data/lib/sourcify/spec/method/to_source_from_define_method_w_do_end_block_spec.rb +145 -0
  115. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_many_matches_spec.rb +56 -0
  116. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_single_match_spec.rb +73 -0
  117. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_many_matches_spec.rb +36 -0
  118. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_no_match_spec.rb +36 -0
  119. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_single_match_spec.rb +28 -0
  120. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +103 -0
  121. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_many_matches_spec.rb +36 -0
  122. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_no_match_spec.rb +36 -0
  123. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_single_match_spec.rb +28 -0
  124. data/lib/sourcify/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_ignore_nested_spec.rb +36 -0
  125. data/lib/sourcify/spec/method/to_source_from_define_method_within_irb_spec.rb +32 -0
  126. data/lib/sourcify/spec/method/to_source_from_define_method_within_pry_spec.rb +49 -0
  127. data/lib/sourcify/spec/method/to_source_magic_file_var_spec.rb +176 -0
  128. data/lib/sourcify/spec/method/to_source_magic_line_var_spec.rb +298 -0
  129. data/lib/sourcify/spec/method/to_source_w_specified_strip_enclosure_spec.rb +39 -0
  130. data/lib/sourcify/spec/no_method/unsupported_platform_spec.rb +26 -0
  131. data/lib/sourcify/spec/proc/19x_extras.rb +27 -0
  132. data/lib/sourcify/spec/proc/created_on_the_fly_proc_spec.rb +80 -0
  133. data/lib/sourcify/spec/proc/encoding_spec.rb +36 -0
  134. data/lib/sourcify/spec/proc/others_spec.rb +40 -0
  135. data/lib/sourcify/spec/proc/raw_scanner/block_comment_spec.rb +8 -0
  136. data/lib/sourcify/spec/proc/raw_scanner/double_colons_spec.rb +8 -0
  137. data/lib/sourcify/spec/proc/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
  138. data/lib/sourcify/spec/proc/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
  139. data/lib/sourcify/spec/proc/raw_scanner/heredoc_w_indent_spec.rb +8 -0
  140. data/lib/sourcify/spec/proc/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
  141. data/lib/sourcify/spec/proc/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
  142. data/lib/sourcify/spec/proc/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
  143. data/lib/sourcify/spec/proc/raw_scanner/per_line_comment_spec.rb +8 -0
  144. data/lib/sourcify/spec/proc/raw_scanner/single_quote_str_spec.rb +8 -0
  145. data/lib/sourcify/spec/proc/raw_scanner/slash_operator_spec.rb +8 -0
  146. data/lib/sourcify/spec/proc/raw_scanner/spec_helper.rb +63 -0
  147. data/lib/sourcify/spec/proc/readme +5 -0
  148. data/lib/sourcify/spec/proc/spec_helper.rb +1 -0
  149. data/lib/sourcify/spec/proc/to_raw_source_spec.rb +33 -0
  150. data/lib/sourcify/spec/proc/to_raw_source_w_specified_strip_enclosure_spec.rb +69 -0
  151. data/lib/sourcify/spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb +46 -0
  152. data/lib/sourcify/spec/proc/to_sexp_variables_spec.rb +146 -0
  153. data/lib/sourcify/spec/proc/to_sexp_w_specified_strip_enclosure_spec.rb +60 -0
  154. data/lib/sourcify/spec/proc/to_sexp_within_irb_spec.rb +146 -0
  155. data/lib/sourcify/spec/proc/to_sexp_within_pry_spec.rb +149 -0
  156. data/lib/sourcify/spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb +33 -0
  157. data/lib/sourcify/spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb +82 -0
  158. data/lib/sourcify/spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb +46 -0
  159. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb +35 -0
  160. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb +35 -0
  161. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb +89 -0
  162. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb +33 -0
  163. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_for_spec.rb +132 -0
  164. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb +87 -0
  165. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb +103 -0
  166. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb +33 -0
  167. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb +49 -0
  168. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb +87 -0
  169. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb +189 -0
  170. data/lib/sourcify/spec/proc/to_source_from_do_end_block_w_nested_while_spec.rb +189 -0
  171. data/lib/sourcify/spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb +46 -0
  172. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb +43 -0
  173. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb +20 -0
  174. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rb +45 -0
  175. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb +45 -0
  176. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rb +22 -0
  177. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb +84 -0
  178. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb +45 -0
  179. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb +45 -0
  180. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rb +22 -0
  181. data/lib/sourcify/spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb +43 -0
  182. data/lib/sourcify/spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb +31 -0
  183. data/lib/sourcify/spec/proc/to_source_magic_file_var_spec.rb +127 -0
  184. data/lib/sourcify/spec/proc/to_source_magic_line_var_spec.rb +127 -0
  185. data/lib/sourcify/spec/proc/to_source_variables_spec.rb +29 -0
  186. data/lib/sourcify/spec/proc/to_source_w_specified_strip_enclosure_spec.rb +33 -0
  187. data/lib/sourcify/spec/proc/to_source_within_irb_spec.rb +38 -0
  188. data/lib/sourcify/spec/proc/to_source_within_pry_spec.rb +61 -0
  189. data/lib/sourcify/spec/raw_scanner/block_comment_shared_spec.rb +57 -0
  190. data/lib/sourcify/spec/raw_scanner/double_colons_shared_spec.rb +11 -0
  191. data/lib/sourcify/spec/raw_scanner/double_quote_str_w_interpolation_shared_spec.rb +60 -0
  192. data/lib/sourcify/spec/raw_scanner/double_quote_str_wo_interpolation_shared_spec.rb +86 -0
  193. data/lib/sourcify/spec/raw_scanner/heredoc_w_indent_shared_spec.rb +69 -0
  194. data/lib/sourcify/spec/raw_scanner/heredoc_wo_indent_shared_spec.rb +70 -0
  195. data/lib/sourcify/spec/raw_scanner/kw_block_start_alias1_shared_spec.rb +73 -0
  196. data/lib/sourcify/spec/raw_scanner/kw_block_start_alias2_shared_spec.rb +73 -0
  197. data/lib/sourcify/spec/raw_scanner/per_line_comment_shared_spec.rb +32 -0
  198. data/lib/sourcify/spec/raw_scanner/shared_specs.rb +3 -0
  199. data/lib/sourcify/spec/raw_scanner/single_quote_str_shared_spec.rb +79 -0
  200. data/lib/sourcify/spec/raw_scanner/slash_operator_shared_spec.rb +71 -0
  201. data/lib/sourcify/spec/run_build.sh +25 -0
  202. data/lib/sourcify/spec/spec_helper.rb +130 -0
  203. data/lib/symbolic/symbolic.rb +248 -0
  204. data/lib/symbolic/visitor.rb +51 -0
  205. data/lib/translator/block_translator.rb +123 -0
  206. data/lib/translator/command_translator.rb +421 -0
  207. data/lib/translator/last_returns_visitor.rb +57 -0
  208. data/lib/translator/local_variables_enumerator.rb +35 -0
  209. data/lib/translator/method_translator.rb +24 -0
  210. data/lib/translator/translator.rb +49 -0
  211. data/lib/type_aware_array.rb +71 -0
  212. data/lib/types/array_type.rb +51 -0
  213. data/lib/types/class_type.rb +128 -0
  214. data/lib/types/object_tracer.rb +162 -0
  215. data/lib/types/primitive_type.rb +73 -0
  216. data/lib/types/ruby_extension.rb +67 -0
  217. data/lib/types/ruby_type.rb +45 -0
  218. data/lib/types/type_inference.rb +382 -0
  219. data/lib/types/union_type.rb +155 -0
  220. metadata +321 -0
@@ -0,0 +1,56 @@
1
+ require "rbconfig"
2
+
3
+ module Ikra
4
+ module Configuration
5
+ class << self
6
+ SUPPORTED_OS = [:linux, :macosx]
7
+ CUDA_NVCC = "/Developer/NVIDIA/CUDA-7.5/bin/nvcc"
8
+
9
+ def check_software_configuration
10
+ if !SUPPORTED_OS.include?(operating_system)
11
+ raise "Operating system not supported: #{operating_system}"
12
+ end
13
+
14
+ # Check if nvcc is installed
15
+ %x(#{CUDA_NVCC})
16
+ if $?.exitstatus != 1
17
+ raise "nvcc not installed"
18
+ end
19
+ end
20
+
21
+ def nvcc_invocation_string(in_file, out_file)
22
+ "#{CUDA_NVCC} -o #{out_file} -I/usr/local/cuda/samples/common/inc --shared -Xcompiler -fPIC #{in_file}"
23
+ end
24
+
25
+ def so_suffix
26
+ if operating_system == :linux
27
+ "so"
28
+ elsif operating_system == :macosx
29
+ "so"
30
+ elsif operating_system == :windows
31
+ "dll"
32
+ else
33
+ raise "Operating system not supported"
34
+ end
35
+ end
36
+
37
+ def operating_system
38
+ # copied from: http://stackoverflow.com/questions/11784109/detecting-operating-systems-in-ruby
39
+
40
+ host_os = RbConfig::CONFIG['host_os']
41
+ case host_os
42
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
43
+ :windows
44
+ when /darwin|mac os/
45
+ :macosx
46
+ when /linux/
47
+ :linux
48
+ when /solaris|bsd/
49
+ :unix
50
+ else
51
+ raise "Unknown operating system"
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ module Ikra
2
+
3
+ # Marker mixin for object tracer
4
+ module Entity
5
+
6
+ end
7
+ end
8
+
9
+ class Array
10
+ include Ikra::Entity
11
+ end
@@ -0,0 +1,7 @@
1
+ require "logger"
2
+ require_relative "symbolic/symbolic"
3
+ require_relative "entity"
4
+
5
+ module Ikra
6
+ Log = Logger.new(STDOUT)
7
+ end
@@ -0,0 +1,32 @@
1
+ require "parser/current"
2
+ require_relative "sourcify/lib/sourcify"
3
+ require "method_source"
4
+
5
+ module Parsing
6
+ class << self
7
+ def parse_block(block, local_variables = [])
8
+ parser = Parser::CurrentRuby.default_parser
9
+ local_variables.each do |var|
10
+ parser.static_env.declare(var)
11
+ end
12
+
13
+ parser_source = Parser::Source::Buffer.new('(string)', 1)
14
+ parser_source.source = block.to_source(strip_enclosure: true)
15
+
16
+ return parser.parse(parser_source)
17
+ end
18
+
19
+ def parse_method(method)
20
+ parser = Parser::CurrentRuby.default_parser
21
+ method.parameters.each do |param|
22
+ parser.static_env.declare(param[1])
23
+ end
24
+
25
+ parser_source = Parser::Source::Buffer.new('(string)', 1)
26
+ # TODO: dirty hack necessary because Parser is broken
27
+ parser_source.source = method.source.lines[1..-2].join
28
+
29
+ return parser.parse(parser_source)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1 @@
1
+ __device__ /*{return_type}*/ /*{name}*/(/*{parameters}*/)
@@ -0,0 +1,4 @@
1
+
2
+ void * temp_ptr_/*{field}*/ = /*{host_env}*/->/*{field}*/;
3
+ checkCudaErrors(cudaMalloc((void **) &/*{host_env}*/->/*{field}*/, /*{size_bytes}*/));
4
+ checkCudaErrors(cudaMemcpy(/*{host_env}*/->/*{field}*/, temp_ptr_/*{field}*/, /*{size_bytes}*/, cudaMemcpyHostToDevice));
@@ -0,0 +1,46 @@
1
+ #include <stdio.h>
2
+
3
+ #include <helper_cuda.h>
4
+ #include <helper_cuda_gl.h>
5
+
6
+ using namespace std;
7
+
8
+
9
+ /* ----- BEGIN Shared Library Export ----- */
10
+ // taken from http://stackoverflow.com/questions/2164827/explicitly-exporting-shared-library-functions-in-linux
11
+
12
+ #if defined(_MSC_VER)
13
+ // Microsoft
14
+ #define EXPORT __declspec(dllexport)
15
+ #define IMPORT __declspec(dllimport)
16
+ #elif defined(_GCC)
17
+ // GCC
18
+ #define EXPORT __attribute__((visibility("default")))
19
+ #define IMPORT
20
+ #else
21
+ // do nothing and hope for the best?
22
+ #define EXPORT
23
+ #define IMPORT
24
+ #pragma warning Unknown dynamic link import/export semantics.
25
+ #endif
26
+ /* ----- END Shared Library Export ----- */
27
+
28
+ /* ----- BEGIN Class Type ----- */
29
+ typedef int obj_id_t;
30
+ typedef int class_id_t;
31
+ /* ----- END Class Type ----- */
32
+
33
+ /* ----- BEGIN Union Type ----- */
34
+ typedef struct union_type_struct
35
+ {
36
+ class_id_t class_id;
37
+ obj_id_t object_id;
38
+ } union_t;
39
+ /* ----- END Union Type ----- */
40
+
41
+
42
+ /* ----- BEGIN Environment (lexical variables) ----- */
43
+ // environment_struct must be defined later
44
+ typedef struct environment_struct environment_t;
45
+ /* ----- END Environment (lexical variables) ----- */
46
+
@@ -0,0 +1,8 @@
1
+
2
+
3
+ __global__ void kernel(environment_t */*{env_identifier}*/, /*{result_type}*/ *_result_)
4
+ {
5
+ _result_[threadIdx.x + blockIdx.x * blockDim.x] = /*{block_invocation}*/;
6
+ }
7
+
8
+
@@ -0,0 +1,28 @@
1
+ extern "C" EXPORT /*{result_type}*/ *launch_kernel(environment_t */*{host_env}*/)
2
+ {
3
+ printf("kernel launched\n");
4
+
5
+ /* Modify host environment to contain device pointers addresses */
6
+ /*{copy_env}*/
7
+
8
+ /* Allocate device environment and copy over struct */
9
+ environment_t */*{dev_env}*/;
10
+ checkCudaErrors(cudaMalloc(&/*{dev_env}*/, sizeof(environment_t)));
11
+ checkCudaErrors(cudaMemcpy(/*{dev_env}*/, /*{host_env}*/, sizeof(environment_t), cudaMemcpyHostToDevice));
12
+
13
+ /*{result_type}*/ *host_result = (/*{result_type}*/ *) malloc(sizeof(/*{result_type}*/) * /*{result_size}*/);
14
+ /*{result_type}*/ *device_result;
15
+ checkCudaErrors(cudaMalloc(&device_result, sizeof(/*{result_type}*/) * /*{result_size}*/));
16
+
17
+ dim3 dim_grid(/*{grid_dim[0]}*/, /*{grid_dim[1]}*/, /*{grid_dim[2]}*/);
18
+ dim3 dim_block(/*{block_dim[0]}*/, /*{block_dim[1]}*/, /*{block_dim[2]}*/);
19
+
20
+ kernel<<<dim_grid, dim_block>>>(/*{dev_env}*/, device_result);
21
+
22
+ checkCudaErrors(cudaThreadSynchronize());
23
+
24
+ checkCudaErrors(cudaMemcpy(host_result, device_result, sizeof(/*{result_type}*/) * /*{result_size}*/, cudaMemcpyDeviceToHost));
25
+ checkCudaErrors(cudaFree(/*{dev_env}*/));
26
+
27
+ return host_result;
28
+ }
@@ -0,0 +1,4 @@
1
+ /* ----- BEGIN Structure of Arrays (SoA) definitions ----- */
2
+ /*{definitions}*/
3
+ /* ----- END Structure of Arrays (SoA) definitions ----- */
4
+
@@ -0,0 +1,166 @@
1
+ require "set"
2
+ require_relative "types/union_type"
3
+
4
+ class Frame < Hash
5
+ def function_frame!
6
+ @is_function_frame = true
7
+ end
8
+
9
+ def is_function_frame?
10
+ @is_function_frame ||= false
11
+ @is_function_frame
12
+ end
13
+
14
+ def add_return_type(type)
15
+ if not is_function_frame?
16
+ raise "Return type allowed only for function frames"
17
+ end
18
+
19
+ if not type.is_union_type?
20
+ raise "Expected union type"
21
+ end
22
+
23
+ @return_type ||= Ikra::Types::UnionType.new
24
+ @return_type.expand(type)
25
+ end
26
+
27
+ def return_type
28
+ if not is_function_frame?
29
+ raise "Return type allowed only for function frames"
30
+ end
31
+
32
+ @return_type ||= Ikra::Types::UnionType.new
33
+ @return_type
34
+ end
35
+
36
+ def variable_names
37
+ keys
38
+ end
39
+ end
40
+
41
+ class Scope < Array
42
+ class Variable
43
+ attr_reader :type
44
+ attr_accessor :read
45
+ attr_accessor :written
46
+
47
+ def initialize(type = Ikra::Types::UnionType.new)
48
+ @type = type
49
+ @read = false
50
+ @written = false
51
+ end
52
+ end
53
+
54
+ def top_frame
55
+ last
56
+ end
57
+
58
+ def previous_frame
59
+ self[-2]
60
+ end
61
+
62
+ def push_frame
63
+ frame = Frame.new
64
+ frame.default_proc = Proc.new do |hash, key|
65
+ hash[key] = Variable.new
66
+ end
67
+ push(frame)
68
+ end
69
+
70
+ def push_function_frame
71
+ push_frame
72
+ top_frame.function_frame!
73
+ end
74
+
75
+ def pop_frame
76
+ pop
77
+ end
78
+
79
+ # TODO: maybe remove?
80
+ def define_shadowed(name, type)
81
+ if top_frame.has_key?(name)
82
+ raise "#{name} already defined"
83
+ end
84
+
85
+ top_frame[name] = Variable.new(type)
86
+ end
87
+
88
+ def is_defined?(name)
89
+ any? do |frame|
90
+ frame.has_key?(name)
91
+ end
92
+ end
93
+
94
+ def get_type(name)
95
+ reverse_each do |frame|
96
+ if frame.has_key?(name)
97
+ return frame[name].type
98
+ end
99
+ end
100
+
101
+ raise "#{name} not found in symbol table"
102
+ end
103
+
104
+ def declare_expand_type(name, type)
105
+ if not type.is_union_type?
106
+ raise "Expected union type"
107
+ end
108
+
109
+ top_frame[name].type.expand(type)
110
+ end
111
+
112
+ def add_return_type(type)
113
+ reverse_each.detect do |fr|
114
+ fr.add_return_type(type)
115
+ return self
116
+ end
117
+
118
+ raise "Function frame not found"
119
+ end
120
+
121
+ def read!(name)
122
+ frame = reverse_each.detect do |fr|
123
+ fr.has_key?(name)
124
+ end
125
+
126
+ frame[name].read = true
127
+ end
128
+
129
+ def written!(name)
130
+ frame = reverse_each.detect do |fr|
131
+ fr.has_key?(name)
132
+ end
133
+
134
+ frame[name].written = true
135
+ end
136
+
137
+ def read_variables(frame_position)
138
+ frame = self[frame_position]
139
+ frame.select do |name, var|
140
+ var.read
141
+ end.keys
142
+ end
143
+
144
+ def written_variables(frame_position)
145
+ frame = self[frame_position]
146
+ frame.select do |name, var|
147
+ var.written
148
+ end.keys
149
+ end
150
+
151
+ def read_and_written_variables(frame_position = -1)
152
+ read_variables(frame_position) + written_variables(frame_position)
153
+ end
154
+
155
+ def new_frame(&block)
156
+ push_frame
157
+ yield
158
+ pop_frame
159
+ end
160
+
161
+ def new_function_frame(&block)
162
+ push_function_frame
163
+ yield
164
+ pop_frame
165
+ end
166
+ end
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sourcify.gemspec
4
+ gemspec
5
+
6
+ # As required by travis, see
7
+ # http://about.travis-ci.org/docs/user/languages/ruby
8
+ group :test do
9
+ gem 'rake'
10
+ end
@@ -0,0 +1,88 @@
1
+ === Current (pre 0.6.0)
2
+
3
+ * adds Method#to_source, Method#to_sexp & Method#to_raw_source to MRI-1.9.2 (issue#3)
4
+ * extensive refactoring to existing proc support to support the above
5
+ * fixes incorrect encoding for scanner result (issue#19) [@tomykaira]
6
+ * ensures compatibility with pry (issue#22) [@ty, @scooter-dangle]
7
+ * fixes "already initialized const X" in ruby_parser" [@jmettraux]
8
+
9
+ === 0.5.0 (May 2, 2011)
10
+
11
+ * adds Proc#to_raw_source that supports extracting of raw code, as it is written in
12
+ the source code (see issue#9), it supports all options that are already supported
13
+ by Proc#to_source.
14
+ * MRI-1.8.6 now supports both ParseTree & static-scanner mode
15
+ * out with infinity_test (due to unresolvable & unexpected consistent failure in
16
+ running specs for jruby-1.6.1 & always running ParseTree mode specs in static-scanner
17
+ mode), use homebaked rake tasks (spec:parsetree, spec:static & spec:all) to acheive
18
+ testing of different rubies in different modes
19
+ * removd dependency on jeweler, & use bundler instead to handle dependency & also have
20
+ our own handcrafted gemspec file
21
+
22
+ === 0.4.2 (Feb 06, 2011)
23
+
24
+ * fixes Sourcify::NoMatchingProcError when inline proc contains hashes (issue#7) [#ngty]
25
+ * uses RubyParser#parse to eval correctness of code instead of Kernel#eval [#ngty]
26
+
27
+ === 0.4.1 (Jan 29, 2011)
28
+
29
+ * fixes Sourcify::NoMatchingProcError when if/unless/until/while modifier follows
30
+ a trailing backslash (see issue#5) [#ngty]
31
+
32
+ === 0.4.0 (Oct 15, 2010)
33
+
34
+ * adds Proc#to_source(:strip_enclosure => ...) (& the Proc#to_sexp equivalent) to ease
35
+ stripping of enclosing 'proc {|params| ... }', returning only the inner code body
36
+ '...' [#ngty]
37
+ * adds Proc#to_source(:attached_to => ..., :ignore_nested => ..., &body_matcher) (& the
38
+ Proc#to_sexp equivalent) to narrow down code scanning, avoiding unnecessary
39
+ Sourcify::MultipleMatchingProcsPerLineError, useful for libs that can anticipate
40
+ how the proc should look like [#ngty]
41
+ * adds support for running in MRI-1.9.2 [#ngty]
42
+ * fixes '/' operator always treated as start of regexp [#ngty & #seamusabshere]
43
+
44
+ === 0.3.0 (Sep 23, 2010)
45
+
46
+ * Proc#to_source & friends now work in IRB as well [#ngty]
47
+
48
+ === 0.2.3 (Sep 15, 2010)
49
+
50
+ * since (static) code scanner doesn't run in 1.8.6, we enforce ParseTree mode
51
+ for 1.8.6 [#ngty]
52
+
53
+ === 0.2.2 (Sep 15, 2010)
54
+
55
+ * fixed failure to run on MRI-1.8.6 [#ngty]
56
+
57
+ === 0.2.1 (Sep 14, 2010)
58
+
59
+ * introduced hack to ensure procs generated by Symbol#to_proc & Method#to_proc
60
+ behaves exactly the same way under 1.8.*, 1.9.* & JRuby ~> always throwing
61
+ CannotHandleCreatedOnTheFlyProcError [#ngty]
62
+ * minor cleaning up of ragel scanner [#ngty]
63
+
64
+ === 0.2.0 (Sep 10, 2010)
65
+
66
+ * use home-baked ragel-based scanner for scanning for proc code [#ngty]
67
+ * renamed Sourcify::LexerInternalError to Sourcify::ParserInternalError since
68
+ we are not using any lexer anymore [#ngty]
69
+ * introduces CannotParseEvalCodeError, CannotParseIrbCodeError &
70
+ CannotHandleCreatedOnTheFlyProcError to handle procs that there is no way
71
+ to extract code from [#ngty]
72
+ * tested against well known projects (eg. spree & redmine) to show that it is
73
+ indeed working [#ngty]
74
+
75
+ === 0.1.2 (Aug 30, 2010)
76
+
77
+ * introduced throwing of Sourcify::LexerInternalError when parser cannot handle
78
+ incorrectly lexed code fragments [#ngty]
79
+ * fixed bug in lexing keyword literals (represented as Symbol) [#ngty]
80
+
81
+ === 0.1.1 (Aug 30, 2010)
82
+
83
+ * fixed empty return for Proc#to_sexp after calling of Proc#to_source [#ngty]
84
+
85
+ === 0.1.0 (Aug 28, 2010)
86
+
87
+ * 1st gem release !! [#ngty]
88
+