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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86447e8ed8423243fd4a85d47c6f6193d401456d
|
4
|
+
data.tar.gz: ead0343c4c707bb0ea133943085e6e5ca24f3372
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9cbfc562bb7529053e755e07763a431b57d802535fa2b5deed201828a07a326bc1ecce7597898d333f1dd9c7a14bbb1eed5bcbf052524f0c6a2bfc8e376fc79
|
7
|
+
data.tar.gz: 4c66b35a3ec55cc68e9f22fe1a7db78bd3e209491fb774f47d0dbccf4bada876966d164a47901cb03e0cb9763489399f60600b0a992265f6a080a4e91615be85
|
data/lib/ast/builder.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative "nodes"
|
2
|
+
|
3
|
+
module Ikra
|
4
|
+
module AST
|
5
|
+
|
6
|
+
# Builds an Ikra AST from a Parser RubyGem AST
|
7
|
+
module Builder
|
8
|
+
class << self
|
9
|
+
def from_parser_ast(node)
|
10
|
+
RootNode.new(child: translate_node(node))
|
11
|
+
end
|
12
|
+
|
13
|
+
def translate_node(node)
|
14
|
+
if node == nil
|
15
|
+
nil
|
16
|
+
else
|
17
|
+
send("translate_#{node.type.to_s}".to_sym, node)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def translate_const(node)
|
22
|
+
# TODO: what is the meaning of the first child?
|
23
|
+
ConstNode.new(identifier: node.children[1])
|
24
|
+
end
|
25
|
+
|
26
|
+
def translate_int(node)
|
27
|
+
IntNode.new(value: node.children[0])
|
28
|
+
end
|
29
|
+
|
30
|
+
def translate_float(node)
|
31
|
+
FloatNode.new(value: node.children[0])
|
32
|
+
end
|
33
|
+
|
34
|
+
def translate_bool(node)
|
35
|
+
BoolNode.new(value: node.children[0])
|
36
|
+
end
|
37
|
+
|
38
|
+
def translate_lvar(node)
|
39
|
+
LVarReadNode.new(identifier: node.children[0])
|
40
|
+
end
|
41
|
+
|
42
|
+
def translate_lvasgn(node)
|
43
|
+
LVarWriteNode.new(identifier: node.children[0], value: translate_node(node.children[1]))
|
44
|
+
end
|
45
|
+
|
46
|
+
def translate_ivar(node)
|
47
|
+
IVarReadNode.new(identifier: node.children[0])
|
48
|
+
end
|
49
|
+
|
50
|
+
def translate_if(node)
|
51
|
+
IfNode.new(condition: translate_node(node.children[0]),
|
52
|
+
true_body_stmts: translate_node(node.children[1]),
|
53
|
+
false_body_stmts: translate_node(node.children[2]))
|
54
|
+
end
|
55
|
+
|
56
|
+
def extract_begin_single_statement(node, should_return = false)
|
57
|
+
next_node = node
|
58
|
+
while next_node.type == :begin
|
59
|
+
if next_node.children.size != 1
|
60
|
+
raise "Begin node contains more than one statement"
|
61
|
+
end
|
62
|
+
|
63
|
+
next_node = next_node.children[0]
|
64
|
+
end
|
65
|
+
|
66
|
+
next_node
|
67
|
+
end
|
68
|
+
|
69
|
+
def translate_for(node)
|
70
|
+
if node.children[0].type == :lvasgn and extract_begin_single_statement(node.children[1]).type == :irange
|
71
|
+
range = extract_begin_single_statement(node.children[1])
|
72
|
+
|
73
|
+
ForNode.new(iterator_identifier: node.children[0].children[0],
|
74
|
+
range_from: translate_node(range.children[0]),
|
75
|
+
range_to: translate_node(range.children[1]),
|
76
|
+
body_stmts: translate_node(node.children[2]))
|
77
|
+
else
|
78
|
+
raise "Can only handle simple For loops at the moment"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def translate_break(node)
|
83
|
+
BreakNode.new
|
84
|
+
end
|
85
|
+
|
86
|
+
def translate_send(node)
|
87
|
+
SendNode.new(receiver: translate_node(node.children[0]),
|
88
|
+
selector: node.children[1],
|
89
|
+
arguments: node.children[2..-1].map do |arg|
|
90
|
+
translate_node(arg) end)
|
91
|
+
end
|
92
|
+
|
93
|
+
def translate_begin(node)
|
94
|
+
BeginNode.new(body_stmts: node.children.map do |stmt|
|
95
|
+
translate_node(stmt) end)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "set"
|
2
|
+
require_relative "nodes"
|
3
|
+
require_relative "visitor"
|
4
|
+
|
5
|
+
module Ikra
|
6
|
+
module AST
|
7
|
+
|
8
|
+
# Visitor for determining the names all lexical variables that are accessed by a block (or method??)
|
9
|
+
# TODO: does a method have access to lexical variables?
|
10
|
+
class LexicalVariablesEnumerator < Visitor
|
11
|
+
attr_reader :lexical_variables
|
12
|
+
|
13
|
+
def initialize(lexical_var_names)
|
14
|
+
@lexical_var_names = lexical_var_names
|
15
|
+
@lexical_variables = Set.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_lvar_access(identifier)
|
19
|
+
if @lexical_var_names.include?(identifier)
|
20
|
+
@lexical_variables.add(identifier)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def visit_lvar_read_node(node)
|
25
|
+
add_lvar_access(node.identifier)
|
26
|
+
end
|
27
|
+
|
28
|
+
def visit_lvar_write_node(node)
|
29
|
+
add_lvar_access(node.identifier)
|
30
|
+
super(node)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "set"
|
2
|
+
require_relative "../scope"
|
3
|
+
|
4
|
+
module Ikra
|
5
|
+
module AST
|
6
|
+
class MethodDefinition
|
7
|
+
attr_accessor :type # receiver type
|
8
|
+
attr_accessor :selector
|
9
|
+
attr_accessor :ast
|
10
|
+
attr_accessor :return_type
|
11
|
+
attr_accessor :callers # method definitions calling this method
|
12
|
+
attr_accessor :symbol_table
|
13
|
+
attr_accessor :binding # needed for resolving constants
|
14
|
+
attr_accessor :local_variables # local variables defined in the method (name -> type)
|
15
|
+
attr_accessor :lexical_variables # lexical variables (defined outside; name -> type)
|
16
|
+
attr_accessor :accessed_lexical_variables # accessed lexical variables, only these variables are transferred to the GPU. TODO: Do we still need this? This is now determined in symbolic.rb
|
17
|
+
attr_accessor :parameter_variables # parameters of the method/block (name -> type)
|
18
|
+
|
19
|
+
def initialize(type:, selector:, parameter_variables:, return_type:, ast:)
|
20
|
+
@type = type
|
21
|
+
@selector = selector
|
22
|
+
@parameter_variables = parameter_variables
|
23
|
+
@return_type = return_type
|
24
|
+
@ast = ast
|
25
|
+
@callers = Set.new
|
26
|
+
@symbol_table = Scope.new
|
27
|
+
@local_variables = {}
|
28
|
+
@lexical_variables = {} # optional
|
29
|
+
@accessed_lexical_variables = {} # optional
|
30
|
+
end
|
31
|
+
|
32
|
+
def parameter_names
|
33
|
+
type.method_parameters(selector)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/ast/nodes.rb
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
module Ikra
|
2
|
+
module AST
|
3
|
+
class Node
|
4
|
+
attr_accessor :parent
|
5
|
+
|
6
|
+
def is_begin_node?
|
7
|
+
false
|
8
|
+
end
|
9
|
+
|
10
|
+
def replace(another_node)
|
11
|
+
parent.replace_child(self, another_node)
|
12
|
+
end
|
13
|
+
|
14
|
+
def replace_child(node, another_node)
|
15
|
+
instance_variables.each do |inst_var|
|
16
|
+
if instance_variable_get(inst_var) == node
|
17
|
+
instance_variable_set(inst_var, another_node)
|
18
|
+
another_node.parent = self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def class_owner
|
24
|
+
@parent.class_owner
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class RootNode < Node
|
29
|
+
attr_reader :child
|
30
|
+
attr_accessor :class_owner # @return [Class] The class where this method is defined
|
31
|
+
|
32
|
+
def initialize(child:)
|
33
|
+
@child = child
|
34
|
+
child.parent = self
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class ConstNode < Node
|
39
|
+
attr_reader :identifier
|
40
|
+
|
41
|
+
def initialize(identifier:)
|
42
|
+
@identifier = identifier
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class LVarReadNode < Node
|
47
|
+
attr_reader :identifier
|
48
|
+
|
49
|
+
def initialize(identifier:)
|
50
|
+
@identifier = identifier
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class LVarWriteNode < Node
|
55
|
+
attr_reader :identifier
|
56
|
+
attr_reader :value
|
57
|
+
|
58
|
+
def initialize(identifier:, value:)
|
59
|
+
@identifier = identifier
|
60
|
+
@value = value
|
61
|
+
|
62
|
+
value.parent = self
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class IVarReadNode < Node
|
67
|
+
attr_reader :identifier
|
68
|
+
|
69
|
+
def initialize(identifier:)
|
70
|
+
@identifier = identifier
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class IntNode < Node
|
75
|
+
attr_reader :value
|
76
|
+
|
77
|
+
def initialize(value:)
|
78
|
+
@value = value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class FloatNode < Node
|
83
|
+
attr_reader :value
|
84
|
+
|
85
|
+
def initialize(value:)
|
86
|
+
@value = value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class BoolNode < Node
|
91
|
+
attr_reader :value
|
92
|
+
|
93
|
+
def initialize(value:)
|
94
|
+
@value = value
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class ForNode < Node
|
99
|
+
attr_reader :iterator_identifier
|
100
|
+
attr_reader :range_from
|
101
|
+
attr_reader :range_to
|
102
|
+
attr_reader :body_stmts
|
103
|
+
|
104
|
+
def initialize(iterator_identifier:, range_from:, range_to:, body_stmts: BeginNode.new)
|
105
|
+
@iterator_identifier = iterator_identifier
|
106
|
+
@range_from = range_from
|
107
|
+
@range_to = range_to
|
108
|
+
@body_stmts = body_stmts
|
109
|
+
|
110
|
+
range_from.parent = self
|
111
|
+
range_to.parent = self
|
112
|
+
body_stmts.parent = self
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class BreakNode < Node
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
class IfNode < Node
|
121
|
+
attr_reader :condition
|
122
|
+
attr_reader :true_body_stmts
|
123
|
+
attr_reader :false_body_stmts
|
124
|
+
|
125
|
+
def initialize(condition:, true_body_stmts:, false_body_stmts: nil)
|
126
|
+
@condition = condition
|
127
|
+
@true_body_stmts = true_body_stmts
|
128
|
+
@false_body_stmts = false_body_stmts
|
129
|
+
|
130
|
+
condition.parent = self
|
131
|
+
true_body_stmts.parent = self
|
132
|
+
|
133
|
+
if false_body_stmts != nil
|
134
|
+
false_body_stmts.parent = self
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
class BeginNode < Node
|
140
|
+
attr_reader :body_stmts
|
141
|
+
|
142
|
+
def initialize(body_stmts: [])
|
143
|
+
@body_stmts = body_stmts
|
144
|
+
|
145
|
+
body_stmts.each do |stmt|
|
146
|
+
stmt.parent = self
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def replace_child(node, another_node)
|
151
|
+
@body_stmts = @body_stmts.map do |stmt|
|
152
|
+
if node == stmt
|
153
|
+
another_node.parent = self
|
154
|
+
another_node
|
155
|
+
else
|
156
|
+
stmt
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def is_begin_node?
|
162
|
+
true
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
class SendNode < Node
|
167
|
+
attr_reader :receiver
|
168
|
+
attr_reader :selector
|
169
|
+
attr_reader :arguments
|
170
|
+
|
171
|
+
def initialize(receiver:, selector:, arguments: [])
|
172
|
+
@receiver = receiver
|
173
|
+
@selector = selector
|
174
|
+
@arguments = arguments
|
175
|
+
|
176
|
+
receiver.parent = self
|
177
|
+
arguments.each do |arg|
|
178
|
+
arg.parent = self
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def replace_child(node, another_node)
|
183
|
+
if @receiver == node
|
184
|
+
@receiver = another_node
|
185
|
+
end
|
186
|
+
|
187
|
+
@arguments = @arguments.map do |arg|
|
188
|
+
if node == arg
|
189
|
+
another_node.parent = self
|
190
|
+
another_node
|
191
|
+
else
|
192
|
+
arg
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
class ReturnNode < Node
|
199
|
+
attr_reader :value
|
200
|
+
|
201
|
+
def initialize(value:)
|
202
|
+
@value = value
|
203
|
+
|
204
|
+
value.parent = self
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
data/lib/ast/printer.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
module Ikra
|
2
|
+
module AST
|
3
|
+
class Node
|
4
|
+
def to_s
|
5
|
+
"[Node]"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class RootNode
|
10
|
+
def to_s
|
11
|
+
"[RootNode: #{child.to_s}]"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ConstNode
|
16
|
+
def to_s
|
17
|
+
"[ConstNode: #{identifier.to_s}]"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class LVarReadNode
|
22
|
+
def to_s
|
23
|
+
"[LVarReadNode: #{identifier.to_s}]"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class LVarWriteNode
|
28
|
+
def to_s
|
29
|
+
"[LVarWriteNode: #{identifier.to_s} := #{value.to_s}]"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class IntNode
|
34
|
+
def to_s
|
35
|
+
"<#{value.to_s}>"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class FloatNode
|
40
|
+
def to_s
|
41
|
+
"<#{value.to_s}>"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class BoolNode
|
46
|
+
def to_s
|
47
|
+
"<#{value.to_s}>"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class ForNode
|
52
|
+
def to_s
|
53
|
+
"[ForNode: #{iterator_identifier.to_s} := #{range_from.to_s}...#{range_to.to_s}, #{body_stmts.to_s}]"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class BreakNode
|
58
|
+
def to_s
|
59
|
+
"[BreakNode]"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class IfNode
|
64
|
+
def to_s
|
65
|
+
if false_body_stmts != nil
|
66
|
+
"[IfNode: #{condition.to_s}, #{true_body_stmts.to_s}, #{false_body_stmts.to_s}]"
|
67
|
+
else
|
68
|
+
"[IfNode: #{condition.to_s}, #{true_body_stmts.to_s}]"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class BeginNode
|
74
|
+
def to_s
|
75
|
+
stmts = body_stmts.map do |stmt|
|
76
|
+
stmt.to_s
|
77
|
+
end.join(";\n")
|
78
|
+
|
79
|
+
"[BeginNode: {#{stmts}}]"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class SendNode
|
84
|
+
def to_s
|
85
|
+
args = arguments.map do |arg|
|
86
|
+
arg.to_s
|
87
|
+
end.join("; ")
|
88
|
+
|
89
|
+
"[SendNode: #{receiver.to_s}.#{selector.to_s}(#{args})]"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class ReturnNode
|
94
|
+
def to_s
|
95
|
+
"[ReturnNode: #{value.to_s}]"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|