rubex 0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -2
  3. data/.travis.yml +9 -1
  4. data/CONTRIBUTING.md +2 -2
  5. data/README.md +4 -1
  6. data/Rakefile +2 -2
  7. data/bin/rubex +4 -5
  8. data/lib/rubex.rb +4 -4
  9. data/lib/rubex/ast.rb +4 -1
  10. data/lib/rubex/ast/expression.rb +22 -1191
  11. data/lib/rubex/ast/expression/actual_arg_list.rb +40 -0
  12. data/lib/rubex/ast/expression/analysed_element_ref.rb +26 -0
  13. data/lib/rubex/ast/expression/analysed_element_ref/c_var_element_ref.rb +30 -0
  14. data/lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb +42 -0
  15. data/lib/rubex/ast/expression/arg_declaration.rb +43 -0
  16. data/lib/rubex/ast/expression/binary.rb +57 -0
  17. data/lib/rubex/ast/expression/binary/binary_boolean.rb +23 -0
  18. data/lib/rubex/ast/expression/binary/binary_boolean_special_op.rb +20 -0
  19. data/lib/rubex/ast/expression/binary/empty_classes.rb +62 -0
  20. data/lib/rubex/ast/expression/block_given.rb +15 -0
  21. data/lib/rubex/ast/expression/coerce_object.rb +15 -0
  22. data/lib/rubex/ast/expression/command_call.rb +74 -0
  23. data/lib/rubex/ast/expression/command_call/struct_or_union_member_call.rb +38 -0
  24. data/lib/rubex/ast/expression/element_ref.rb +64 -0
  25. data/lib/rubex/ast/expression/empty.rb +13 -0
  26. data/lib/rubex/ast/expression/from_ruby_object.rb +20 -0
  27. data/lib/rubex/ast/expression/func_ptr_arg_declaration.rb +21 -0
  28. data/lib/rubex/ast/expression/func_ptr_internal_arg_declaration.rb +13 -0
  29. data/lib/rubex/ast/expression/literal.rb +30 -0
  30. data/lib/rubex/ast/expression/literal/array_lit.rb +51 -0
  31. data/lib/rubex/ast/expression/literal/c_null.rb +15 -0
  32. data/lib/rubex/ast/expression/literal/char.rb +36 -0
  33. data/lib/rubex/ast/expression/literal/double.rb +14 -0
  34. data/lib/rubex/ast/expression/literal/false.rb +33 -0
  35. data/lib/rubex/ast/expression/literal/hash_lit.rb +45 -0
  36. data/lib/rubex/ast/expression/literal/int.rb +14 -0
  37. data/lib/rubex/ast/expression/literal/nil.rb +14 -0
  38. data/lib/rubex/ast/expression/literal/ruby_symbol.rb +22 -0
  39. data/lib/rubex/ast/expression/literal/string_lit.rb +45 -0
  40. data/lib/rubex/ast/expression/literal/true.rb +29 -0
  41. data/lib/rubex/ast/expression/method_call.rb +52 -0
  42. data/lib/rubex/ast/expression/method_call/c_function_call.rb +40 -0
  43. data/lib/rubex/ast/expression/method_call/ruby_method_call.rb +83 -0
  44. data/lib/rubex/ast/expression/name.rb +127 -0
  45. data/lib/rubex/ast/expression/ruby_constant.rb +25 -0
  46. data/lib/rubex/ast/expression/ruby_object_element_ref/ruby_array_element_ref.rb +20 -0
  47. data/lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb +22 -0
  48. data/lib/rubex/ast/expression/self.rb +15 -0
  49. data/lib/rubex/ast/expression/size_of.rb +22 -0
  50. data/lib/rubex/ast/expression/struct_or_union_member_call/element_ref_member_call.rb +23 -0
  51. data/lib/rubex/ast/expression/to_ruby_object.rb +21 -0
  52. data/lib/rubex/ast/expression/typecast.rb +20 -0
  53. data/lib/rubex/ast/expression/typecast_to.rb +10 -0
  54. data/lib/rubex/ast/expression/unary.rb +37 -0
  55. data/lib/rubex/ast/expression/unary_base.rb +24 -0
  56. data/lib/rubex/ast/expression/unary_base/ampersand.rb +16 -0
  57. data/lib/rubex/ast/expression/unary_base/unary_bit_not.rb +18 -0
  58. data/lib/rubex/ast/expression/unary_base/unary_not.rb +18 -0
  59. data/lib/rubex/ast/expression/unary_base/unary_sub.rb +18 -0
  60. data/lib/rubex/ast/node.rb +111 -111
  61. data/lib/rubex/ast/statement.rb +9 -1160
  62. data/lib/rubex/ast/statement/alias.rb +43 -0
  63. data/lib/rubex/ast/statement/argument_list.rb +59 -0
  64. data/lib/rubex/ast/statement/assign.rb +35 -0
  65. data/lib/rubex/ast/statement/begin_block.rb +14 -0
  66. data/lib/rubex/ast/statement/begin_block/begin.rb +202 -0
  67. data/lib/rubex/ast/statement/begin_block/else.rb +21 -0
  68. data/lib/rubex/ast/statement/begin_block/ensure.rb +21 -0
  69. data/lib/rubex/ast/statement/begin_block/rescue.rb +34 -0
  70. data/lib/rubex/ast/statement/break.rb +18 -0
  71. data/lib/rubex/ast/statement/c_array_decl.rb +49 -0
  72. data/lib/rubex/ast/statement/c_base_type.rb +26 -0
  73. data/lib/rubex/ast/statement/c_function_decl.rb +30 -0
  74. data/lib/rubex/ast/statement/c_ptr_decl.rb +52 -0
  75. data/lib/rubex/ast/statement/c_ptr_decl/c_ptr_func_decl.rb +25 -0
  76. data/lib/rubex/ast/statement/c_struct_or_union_def.rb +49 -0
  77. data/lib/rubex/ast/statement/expression.rb +26 -0
  78. data/lib/rubex/ast/statement/for.rb +73 -0
  79. data/lib/rubex/ast/statement/forward_decl.rb +31 -0
  80. data/lib/rubex/ast/statement/if_block.rb +64 -0
  81. data/lib/rubex/ast/statement/if_block/else.rb +30 -0
  82. data/lib/rubex/ast/statement/if_block/elsif.rb +22 -0
  83. data/lib/rubex/ast/statement/if_block/helper.rb +38 -0
  84. data/lib/rubex/ast/statement/print.rb +49 -0
  85. data/lib/rubex/ast/statement/raise.rb +66 -0
  86. data/lib/rubex/ast/statement/return.rb +45 -0
  87. data/lib/rubex/ast/statement/var_decl.rb +49 -0
  88. data/lib/rubex/ast/statement/while.rb +34 -0
  89. data/lib/rubex/ast/statement/yield.rb +41 -0
  90. data/lib/rubex/ast/top_statement.rb +1 -815
  91. data/lib/rubex/ast/top_statement/c_bindings.rb +145 -0
  92. data/lib/rubex/ast/top_statement/klass.rb +125 -0
  93. data/lib/rubex/ast/top_statement/klass/attached_klass.rb +417 -0
  94. data/lib/rubex/ast/top_statement/method_def.rb +110 -0
  95. data/lib/rubex/ast/top_statement/method_def/c_function_def.rb +26 -0
  96. data/lib/rubex/ast/top_statement/method_def/ruby_method_def.rb +33 -0
  97. data/lib/rubex/cli.rb +26 -0
  98. data/lib/rubex/code_writer.rb +1 -1
  99. data/lib/rubex/compiler.rb +49 -28
  100. data/lib/rubex/compiler_config.rb +4 -2
  101. data/lib/rubex/constants.rb +71 -71
  102. data/lib/rubex/data_type.rb +9 -675
  103. data/lib/rubex/data_type/c_array.rb +33 -0
  104. data/lib/rubex/data_type/c_function.rb +23 -0
  105. data/lib/rubex/data_type/c_ptr.rb +71 -0
  106. data/lib/rubex/data_type/c_str.rb +23 -0
  107. data/lib/rubex/data_type/c_struct_or_union.rb +23 -0
  108. data/lib/rubex/data_type/char.rb +30 -0
  109. data/lib/rubex/data_type/f_32.rb +38 -0
  110. data/lib/rubex/data_type/f_64.rb +38 -0
  111. data/lib/rubex/data_type/int.rb +32 -0
  112. data/lib/rubex/data_type/int/c_boolean.rb +13 -0
  113. data/lib/rubex/data_type/int_16.rb +32 -0
  114. data/lib/rubex/data_type/int_32.rb +32 -0
  115. data/lib/rubex/data_type/int_64.rb +36 -0
  116. data/lib/rubex/data_type/int_8.rb +33 -0
  117. data/lib/rubex/data_type/l_int.rb +38 -0
  118. data/lib/rubex/data_type/l_l_int.rb +26 -0
  119. data/lib/rubex/data_type/ruby_method.rb +22 -0
  120. data/lib/rubex/data_type/ruby_object.rb +19 -0
  121. data/lib/rubex/data_type/ruby_object/boolean.rb +11 -0
  122. data/lib/rubex/data_type/ruby_object/boolean/false_type.rb +5 -0
  123. data/lib/rubex/data_type/ruby_object/boolean/true_type.rb +5 -0
  124. data/lib/rubex/data_type/ruby_object/nil_type.rb +9 -0
  125. data/lib/rubex/data_type/ruby_object/ruby_array.rb +10 -0
  126. data/lib/rubex/data_type/ruby_object/ruby_constant.rb +18 -0
  127. data/lib/rubex/data_type/ruby_object/ruby_constant/ruby_class.rb +18 -0
  128. data/lib/rubex/data_type/ruby_object/ruby_hash.rb +9 -0
  129. data/lib/rubex/data_type/ruby_object/ruby_string.rb +10 -0
  130. data/lib/rubex/data_type/ruby_object/ruby_symbol.rb +10 -0
  131. data/lib/rubex/data_type/type_def.rb +34 -0
  132. data/lib/rubex/data_type/u_char.rb +27 -0
  133. data/lib/rubex/data_type/u_int.rb +32 -0
  134. data/lib/rubex/data_type/u_int_16.rb +22 -0
  135. data/lib/rubex/data_type/u_int_32.rb +22 -0
  136. data/lib/rubex/data_type/u_int_64.rb +26 -0
  137. data/lib/rubex/data_type/u_int_8.rb +22 -0
  138. data/lib/rubex/data_type/u_l_int.rb +36 -0
  139. data/lib/rubex/data_type/u_l_int/size_t.rb +10 -0
  140. data/lib/rubex/data_type/u_l_l_int.rb +26 -0
  141. data/lib/rubex/data_type/void.rb +15 -0
  142. data/lib/rubex/data_type_helpers/float_helpers.rb +8 -0
  143. data/lib/rubex/data_type_helpers/helpers.rb +48 -0
  144. data/lib/rubex/data_type_helpers/int_helpers.rb +10 -0
  145. data/lib/rubex/data_type_helpers/u_int_helpers.rb +11 -0
  146. data/lib/rubex/helpers.rb +35 -118
  147. data/lib/rubex/helpers/node_type_methods.rb +9 -0
  148. data/lib/rubex/helpers/writers.rb +79 -0
  149. data/lib/rubex/parser.racc +83 -34
  150. data/lib/rubex/parser.racc.rb +233 -184
  151. data/lib/rubex/version.rb +2 -2
  152. data/rubex.gemspec +2 -0
  153. data/spec/basic_ruby_method_spec.rb +1 -1
  154. data/spec/binding_ptr_args_spec.rb +2 -2
  155. data/spec/bitwise_operators_spec.rb +1 -1
  156. data/spec/blocks_spec.rb +2 -2
  157. data/spec/c_bindings_spec.rb +1 -1
  158. data/spec/c_constants_spec.rb +1 -1
  159. data/spec/c_function_ptrs_spec.rb +1 -1
  160. data/spec/c_functions_spec.rb +2 -2
  161. data/spec/c_struct_interface_spec.rb +1 -1
  162. data/spec/call_by_reference_spec.rb +2 -2
  163. data/spec/class_methods_spec.rb +2 -2
  164. data/spec/class_spec.rb +4 -4
  165. data/spec/cli_spec.rb +43 -0
  166. data/spec/comments_spec.rb +2 -2
  167. data/spec/default_args_spec.rb +21 -23
  168. data/spec/error_handling_spec.rb +1 -1
  169. data/spec/examples_spec.rb +4 -4
  170. data/spec/expressions_spec.rb +1 -1
  171. data/spec/fixtures/cli/cli.rubex +3 -0
  172. data/spec/fixtures/examples/array_to_hash.rubex +1 -1
  173. data/spec/fixtures/examples/rcsv.rubex +10 -6
  174. data/spec/fixtures/loops/loops.rubex +1 -1
  175. data/spec/fixtures/ruby_strings/string_blank_bm.rb +7 -5
  176. data/spec/fixtures/struct/struct.rubex +7 -2
  177. data/spec/fixtures/temp_allocation/temp_allocation.rubex +8 -0
  178. data/spec/if_else_spec.rb +3 -7
  179. data/spec/implicit_lib_include_spec.rb +1 -1
  180. data/spec/init_ruby_objects_with_literal_syntax_spec.rb +1 -1
  181. data/spec/loops_spec.rb +1 -1
  182. data/spec/recursion_spec.rb +18 -21
  183. data/spec/ruby_constant_method_calls_spec.rb +4 -4
  184. data/spec/ruby_operators_spec.rb +1 -1
  185. data/spec/ruby_raise_spec.rb +1 -1
  186. data/spec/ruby_strings_spec.rb +3 -3
  187. data/spec/ruby_symbols_spec.rb +1 -1
  188. data/spec/ruby_types_spec.rb +2 -2
  189. data/spec/spec_helper.rb +42 -10
  190. data/spec/statement_expression_spec.rb +3 -3
  191. data/spec/static_array_spec.rb +3 -3
  192. data/spec/string_literals_spec.rb +2 -2
  193. data/spec/struct_spec.rb +4 -4
  194. data/spec/temp_allocation_spec.rb +35 -0
  195. data/spec/typecasting_spec.rb +2 -2
  196. data/spec/var_declarions_spec.rb +2 -2
  197. metadata +168 -3
@@ -0,0 +1,40 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class ActualArgList < Base
5
+ include Enumerable
6
+ extend Forwardable
7
+
8
+ def_delegators :@args, :empty?, :[], :size, :<<
9
+
10
+ def each(&block)
11
+ @args.each(&block)
12
+ end
13
+
14
+ def map!(&block)
15
+ @args.map!(&block)
16
+ end
17
+
18
+ def initialize args
19
+ @args = args
20
+ @subexprs = []
21
+ end
22
+
23
+ def analyse_types(local_scope)
24
+ @args.each do |arg|
25
+ arg.analyse_types local_scope
26
+ @subexprs << arg
27
+ end
28
+ end
29
+
30
+ def generate_evaluation_code(code, local_scope)
31
+ @args.each { |a| a.generate_evaluation_code(code, local_scope) }
32
+ end
33
+
34
+ def generate_disposal_code(code)
35
+ @args.each { |a| a.generate_disposal_code(code) }
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class AnalysedElementRef < Base
5
+ def initialize(element_ref)
6
+ @element_ref = element_ref
7
+ @pos = @element_ref.pos
8
+ @entry = @element_ref.entry
9
+ @name = @element_ref.name
10
+ @subexprs = @element_ref.subexprs
11
+ @type = @element_ref.type
12
+ end
13
+
14
+ def analyse_types(local_scope)
15
+ @pos.analyse_types local_scope
16
+ end
17
+
18
+ def c_code(local_scope)
19
+ code = super
20
+ code << @c_code
21
+ code
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class CVarElementRef < AnalysedElementRef
5
+ def analyse_types(local_scope)
6
+ @pos.analyse_types local_scope
7
+ @subexprs << @pos
8
+ end
9
+
10
+ def generate_evaluation_code(code, local_scope)
11
+ generate_and_dispose_subexprs(code, local_scope) do
12
+ @c_code = "#{@entry.c_name}[#{@pos.c_code(local_scope)}]"
13
+ end
14
+ end
15
+
16
+ def generate_element_ref_code(_expr, code, local_scope)
17
+ generate_evaluation_code code, local_scope
18
+ end
19
+
20
+ def generate_assignment_code(rhs, code, local_scope)
21
+ generate_and_dispose_subexprs(code, local_scope) do
22
+ code << "#{@entry.c_name}[#{@pos.c_code(local_scope)}] = "
23
+ code << "#{rhs.c_code(local_scope)};"
24
+ code.nl
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class RubyObjectElementRef < AnalysedElementRef
5
+ def analyse_types(local_scope)
6
+ super
7
+ @has_temp = true
8
+ @pos = @pos.to_ruby_object
9
+ @pos.allocate_temps local_scope
10
+ @pos.release_temps local_scope
11
+ @subexprs << @pos
12
+ end
13
+
14
+ def generate_evaluation_code(code, local_scope)
15
+ generate_and_dispose_subexprs(code, local_scope) do
16
+ code << "#{@c_code} = rb_funcall(#{@entry.c_name}, rb_intern(\"[]\"), 1, "
17
+ code << "#{@pos.c_code(local_scope)});"
18
+ code.nl
19
+ end
20
+ end
21
+
22
+ def generate_element_ref_code(expr, code, local_scope)
23
+ generate_and_dispose_subexprs(code, local_scope) do
24
+ str = "#{@c_code} = rb_funcall(#{expr.c_code(local_scope)}."
25
+ str << "#{@entry.c_name}, rb_intern(\"[]\"), 1, "
26
+ str << "#{@pos.c_code(local_scope)});"
27
+ code << str
28
+ code.nl
29
+ end
30
+ end
31
+
32
+ def generate_assignment_code(rhs, code, local_scope)
33
+ generate_and_dispose_subexprs(code, local_scope) do
34
+ code << "rb_funcall(#{@entry.c_name}, rb_intern(\"[]=\"), 2,"
35
+ code << "#{@pos.c_code(local_scope)}, #{rhs.c_code(local_scope)});"
36
+ code.nl
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class ArgDeclaration < Base
5
+ # Keep data_hash attr_reader because this node is coerced into
6
+ # specialized ArgDecl nodes in the parser.
7
+ attr_reader :data_hash
8
+ def initialize(data_hash)
9
+ @data_hash = data_hash
10
+ end
11
+
12
+ # TODO: Support array of function pointers and array in arguments.
13
+ def analyse_types(local_scope, extern: false)
14
+ var, dtype, ident, ptr_level, value = fetch_data
15
+ name = ident
16
+ c_name = Rubex::ARG_PREFIX + ident
17
+ @type = Helpers.determine_dtype(dtype, ptr_level)
18
+ value&.analyse_types(local_scope)
19
+ add_arg_to_symbol_table name, c_name, value, extern, local_scope
20
+ @has_temp = true if @type.object?
21
+ end
22
+
23
+ private
24
+
25
+ def add_arg_to_symbol_table(name, c_name, value, extern, local_scope)
26
+ unless extern
27
+ @entry = local_scope.add_arg(name: name, c_name: c_name, type: @type, value: value)
28
+ end
29
+ end
30
+
31
+ def fetch_data
32
+ var = @data_hash[:variables][0]
33
+ dtype = @data_hash[:dtype]
34
+ ident = var[:ident]
35
+ ptr_level = var[:ptr_level]
36
+ value = var[:value]
37
+
38
+ [var, dtype, ident, ptr_level, value]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,57 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ # Binary expression Base class.
5
+ class Binary < Base
6
+ include Rubex::Helpers::NodeTypeMethods
7
+ def initialize left, operator, right
8
+ @left, @operator, @right = left, operator, right
9
+ @subexprs = []
10
+ end
11
+
12
+ def analyse_types local_scope
13
+ @left.analyse_types local_scope
14
+ @right.analyse_types local_scope
15
+ if type_of(@left).object? || type_of(@right).object?
16
+ @left = @left.to_ruby_object
17
+ @right = @right.to_ruby_object
18
+ @has_temp = true
19
+ end
20
+ @type = Rubex::Helpers.result_type_for(type_of(@left), type_of(@right))
21
+ @subexprs << @left
22
+ @subexprs << @right
23
+ end
24
+
25
+ def generate_evaluation_code code, local_scope
26
+ generate_and_dispose_subexprs(code, local_scope) do
27
+ if @has_temp
28
+ code << "#{@c_code} = rb_funcall(#{@left.c_code(local_scope)}," +
29
+ "rb_intern(\"#{@operator}\")," +
30
+ "1, #{@right.c_code(local_scope)});"
31
+ code.nl
32
+ else
33
+ @c_code = "( #{@left.c_code(local_scope)} #{@operator} #{@right.c_code(local_scope)} )"
34
+ end
35
+ end
36
+ end
37
+
38
+ def c_code local_scope
39
+ super + @c_code
40
+ end
41
+
42
+ def == other
43
+ self.class == other.class && @type == other.type &&
44
+ @left == other.left && @right == other.right &&
45
+ @operator == other.operator
46
+ end
47
+
48
+ private
49
+
50
+ def type_of expr
51
+ t = expr.type
52
+ return (t.c_function? ? t.type : t)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class BinaryBoolean < Binary
5
+ def analyse_types(local_scope)
6
+ @left.analyse_types local_scope
7
+ @right.analyse_types local_scope
8
+ if type_of(@left).object? || type_of(@right).object?
9
+
10
+ @left = @left.to_ruby_object
11
+ @right = @right.to_ruby_object
12
+ @type = Rubex::DataType::Boolean.new
13
+ @has_temp = true
14
+ else
15
+ @type = Rubex::DataType::CBoolean.new
16
+ end
17
+ @subexprs << @left
18
+ @subexprs << @right
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class BinaryBooleanSpecialOp < BinaryBoolean
5
+ def generate_evaluation_code(code, local_scope)
6
+ generate_and_dispose_subexprs(code, local_scope) do
7
+ if @has_temp
8
+ code << "#{@c_code} = " + Rubex::C_MACRO_INT2BOOL +
9
+ "(RTEST(#{@left.c_code(local_scope)}) #{@operator} " \
10
+ "RTEST(#{@right.c_code(local_scope)}));"
11
+ code.nl
12
+ else
13
+ @c_code = "#{@left.c_code(local_scope)} #{@operator} #{@right.c_code(local_scope)}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class BinaryAdd < Binary
5
+ end
6
+
7
+ class BinaryMinus < Binary
8
+ end
9
+
10
+ class BinaryMultiply < Binary
11
+ end
12
+
13
+ class BinaryDivide < Binary
14
+ end
15
+
16
+ class BinaryExpo < Binary
17
+ end
18
+
19
+ class BinaryMod < Binary
20
+ end
21
+
22
+ class BinaryAnd < Binary
23
+ end
24
+
25
+ class BinaryOr < Binary
26
+ end
27
+
28
+ class BinaryXor < Binary
29
+ end
30
+
31
+ class BinaryLShift < Binary
32
+ end
33
+
34
+ class BinaryRShift < Binary
35
+ end
36
+
37
+ class BinaryBoolEq < BinaryBoolean
38
+ end
39
+
40
+ class BinaryBoolNEq < BinaryBoolean
41
+ end
42
+
43
+ class BinaryBoolLt < BinaryBoolean
44
+ end
45
+
46
+ class BinaryBoolLtEq < BinaryBoolean
47
+ end
48
+
49
+ class BinaryBoolGt < BinaryBoolean
50
+ end
51
+
52
+ class BinaryBoolGtEq < BinaryBoolean
53
+ end
54
+
55
+ class BinaryBoolAnd < BinaryBooleanSpecialOp
56
+ end
57
+
58
+ class BinaryBoolOr < BinaryBooleanSpecialOp
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,15 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class BlockGiven < Base
5
+ def analyse_types(_local_scope)
6
+ @type = DataType::CBoolean.new
7
+ end
8
+
9
+ def c_code(_local_scope)
10
+ 'rb_block_given_p()'
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class CoerceObject < Base
5
+ attr_reader :expr
6
+
7
+ extend Forwardable
8
+
9
+ def_delegators :@expr, :generate_evaluation_code, :generate_disposal_code,
10
+ :generate_assignment_code, :allocate_temp, :allocate_temps,
11
+ :release_temp, :release_temps, :type
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,74 @@
1
+ module Rubex
2
+ module AST
3
+ module Expression
4
+ class CommandCall < Base
5
+ def initialize(expr, command, arg_list)
6
+ @expr = expr
7
+ @command = command
8
+ @arg_list = arg_list
9
+ end
10
+
11
+ def analyse_types(local_scope)
12
+ @entry = local_scope.find(@command)
13
+ if @expr.nil? # Case for implicit 'self' when a method in the class itself is being called.
14
+ @expr = (@entry && !@entry.extern) ? Expression::Self.new : Expression::Empty.new
15
+ end
16
+ @expr.analyse_types(local_scope)
17
+ analyse_command_type local_scope
18
+ @subexprs = [@expr, @command]
19
+ super
20
+ end
21
+
22
+ def generate_evaluation_code(code, local_scope)
23
+ @expr.generate_evaluation_code(code, local_scope)
24
+ @command.generate_evaluation_code code, local_scope
25
+ @c_code = @command.c_code(local_scope)
26
+ end
27
+
28
+ def generate_disposal_code(code)
29
+ @expr.generate_disposal_code code
30
+ @command.generate_disposal_code code
31
+ end
32
+
33
+ def generate_assignment_code(rhs, code, local_scope)
34
+ generate_evaluation_code code, local_scope
35
+ code << "#{c_code(local_scope)} = #{rhs.c_code(local_scope)};"
36
+ code.nl
37
+ end
38
+
39
+ def c_code(local_scope)
40
+ code = super
41
+ code << @c_code
42
+ code
43
+ end
44
+
45
+ private
46
+
47
+ def struct_member_call?
48
+ ((@expr.type.cptr? && @expr.type.type.struct_or_union?) ||
49
+ @expr.type.struct_or_union?)
50
+ end
51
+
52
+ def ruby_method_call?
53
+ @entry.type.ruby_method?
54
+ end
55
+
56
+ def c_function_call?
57
+ @entry && @entry.type.base_type.c_function?
58
+ end
59
+
60
+ def analyse_command_type(local_scope)
61
+ if struct_member_call?
62
+ @command = Expression::StructOrUnionMemberCall.new @expr, @command, @arg_list
63
+ elsif c_function_call?
64
+ @command = Expression::CFunctionCall.new @expr, @command, @arg_list
65
+ else
66
+ @command = Expression::RubyMethodCall.new @expr, @command, @arg_list
67
+ end
68
+ @command.analyse_types local_scope
69
+ @type = @command.type
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end