rubex 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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,8 @@
1
+ def test_temp(s)
2
+ if s.nil?
3
+ return "nil"
4
+ elsif !s.nil?
5
+ return "small" if s.size == 0
6
+ end
7
+ return "large"
8
+ end
@@ -14,24 +14,20 @@ describe Rubex do
14
14
  end
15
15
  end
16
16
 
17
- context ".compile", focus: true do
17
+ context ".compile" do
18
18
  it "compiles to valid C file" do
19
19
  t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
20
20
  end
21
21
  end
22
22
 
23
- context "Black Box testing", focus: true do
23
+ context "Black Box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(adder_if_else(2, 3, 4)).to eq(4)
29
29
  expect(multi_if_elsif).to eq(true)
30
30
  expect(IfElseTest.new.ruby_obj_in_condition).to eq(20)
31
-
32
- # pending("Multi line if statement conditions.") do
33
- # expect(multi_line_if).to eq(true)
34
- # end
35
31
  end
36
32
  end
37
33
  end
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black Box testing", focus: true do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(test_method).to eq(9)
29
29
  end
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black Box testing", focus: true do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
  array = [1,2,3,4,5,6]
28
28
  string = "Hello world! Lets have a picnic!"
29
29
  h = {
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black Box testing", focus: true do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(looper(5)).to eq(10)
29
29
  expect(break_stmt).to eq(3)
@@ -1,33 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rubex do
4
- pending("implement recursion") do
5
- test_case = "recursion"
4
+ test_case = 'recursion'
6
5
 
7
- context "Case: #{test_case}" do
8
- before do
9
- @path = path_str test_case
10
- end
6
+ context "Case: #{test_case}" do
7
+ before do
8
+ @path = path_str test_case
9
+ end
11
10
 
12
- context ".ast" do
13
- it "generates a valid AST" do
14
- t = Rubex::Compiler.ast(@path + '.rubex')
15
- end
11
+ context '.ast' do
12
+ skip 'generates a valid AST' do
13
+ t = Rubex::Compiler.ast(@path + '.rubex')
16
14
  end
15
+ end
17
16
 
18
- context ".compile" do
19
- it "compiles to valid C code" do
20
- t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
21
- end
17
+ context '.compile' do
18
+ skip 'compiles to valid C code' do
19
+ t, c, e = Rubex::Compiler.compile(@path + '.rubex', test: true)
22
20
  end
21
+ end
23
22
 
24
- context "Black Box testing" do
25
- it "compiles and checks for valid output" do
26
- setup_and_teardown_compiled_files(test_case) do |dir|
27
- require_relative "#{dir}/#{test_case}.so"
28
-
29
- expect(Fibonnaci.new.compute(5)).to eq(5)
30
- end
23
+ context 'Black Box testing' do
24
+ skip 'compiles and checks for valid output' do
25
+ setup_and_teardown_compiled_files(test_case) do |dir|
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
+ expect(Fibonnaci.new.compute(5)).to eq(5)
31
28
  end
32
29
  end
33
30
  end
@@ -14,16 +14,16 @@ describe Rubex do
14
14
  end
15
15
  end
16
16
 
17
- context ".compile", focus: true do
17
+ context ".compile" do
18
18
  it "compiles to valid C file" do
19
19
  t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
20
20
  end
21
21
  end
22
22
 
23
- context "Black Box testing", focus: true do
23
+ context "Black Box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(InitRubyClass.new.init_classes).to eq(
29
29
  [3,3, "Hello! This is a test", "converted."]
@@ -32,4 +32,4 @@ describe Rubex do
32
32
  end
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(StringCaller.new.call_now("foo!")).to eq("f")
29
29
 
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black box testing", focus: true do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  cls = RaiseTester.new
29
29
  expect { cls.test_raise(true) }.to raise_error(ArgumentError)
@@ -14,16 +14,16 @@ describe Rubex do
14
14
  end
15
15
  end
16
16
 
17
- context ".compile", focus: true do
17
+ context ".compile" do
18
18
  it "compiles to valid C file" do
19
19
  t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
20
20
  end
21
21
  end
22
22
 
23
- context "Black box testing", focus: true do
23
+ context "Black box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(blank?(" ")).to eq(true)
29
29
  end
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black box testing", focus: true do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
  answer = {
28
28
  first: "a",
29
29
  second: :f,
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black Box testing", focus: true do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(RubyTypes.new.these_types("", [], {})).to eq(
29
29
  {"fff" => 565}
@@ -32,4 +32,4 @@ describe Rubex do
32
32
  end
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -1,3 +1,7 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ end
1
5
  require 'rspec'
2
6
  require 'awesome_print'
3
7
  require 'pp'
@@ -12,8 +16,12 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
12
16
 
13
17
  require 'rubex'
14
18
 
15
- def dir_str test_case
16
- "#{Dir.pwd}/spec/fixtures/#{test_case}"
19
+ def dir_str test_case, example=nil
20
+ if example
21
+ "#{Dir.pwd}/spec/fixtures/#{test_case}/#{example}"
22
+ else
23
+ "#{Dir.pwd}/spec/fixtures/#{test_case}"
24
+ end
17
25
  end
18
26
 
19
27
  def path_str test_case, example=nil
@@ -23,7 +31,7 @@ end
23
31
 
24
32
  def generate_shared_object test_case, example=nil
25
33
  path = path_str test_case, example
26
- dir = dir_str test_case
34
+ dir = dir_str test_case, example
27
35
 
28
36
  Rubex::Compiler.compile(path + '.rubex', directory: dir)
29
37
  Dir.chdir(dir) do
@@ -33,15 +41,10 @@ def generate_shared_object test_case, example=nil
33
41
  end
34
42
 
35
43
  def delete_generated_files test_case, example=nil
36
- dir = dir_str test_case
44
+ dir = dir_str test_case, example
37
45
  test_case = example if example
38
46
  Dir.chdir(dir) do
39
- [
40
- "#{test_case}.c", "#{test_case}.so", "Makefile",
41
- "extconf.rb" , "#{test_case}.o"
42
- ].each do |f|
43
- FileUtils.rm f
44
- end
47
+ FileUtils.rm(Dir.glob("#{test_case}.{c,so,o,bundle,dll}") + ["Makefile", "extconf.rb"], force: true)
45
48
  end
46
49
  end
47
50
 
@@ -58,3 +61,32 @@ end
58
61
  def expect_compiled_code code, path
59
62
  expect(code.to_s).to eq(File.read(path))
60
63
  end
64
+
65
+
66
+ def detect_os
67
+ @os ||= (
68
+ host_os = RbConfig::CONFIG['host_os']
69
+ case host_os
70
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
71
+ :windows
72
+ when /darwin|mac os/
73
+ :macosx
74
+ when /linux/
75
+ :linux
76
+ when /solaris|bsd/
77
+ :unix
78
+ else
79
+ raise StandardError, "unknown os: #{host_os.inspect}"
80
+ end
81
+ )
82
+ end
83
+
84
+ def os_extension
85
+ @extension_hash ||= {
86
+ windows: 'dll',
87
+ macosx: 'bundle',
88
+ linux: 'so',
89
+ unix: 'so'
90
+ }
91
+ @extension_hash[detect_os]
92
+ end
@@ -14,17 +14,17 @@ describe Rubex do
14
14
  end
15
15
  end
16
16
 
17
- context ".compile", focus: true do
17
+ context ".compile" do
18
18
  it "compiles to valid C file" do
19
19
  t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
20
20
  end
21
21
  end
22
22
 
23
- context "Black box testing", focus: true do
23
+ context "Black box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
26
  def foo; end
27
- require_relative "#{dir}/#{test_case}.so"
27
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
28
28
 
29
29
  expect(expr_stat).to eq("success.")
30
30
  end
@@ -14,16 +14,16 @@ describe Rubex do
14
14
  end
15
15
  end
16
16
 
17
- context ".compile", focus: true do
17
+ context ".compile" do
18
18
  it "compiles to valid C file" do
19
19
  t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
20
20
  end
21
21
  end
22
22
 
23
- context "Black box testing", focus: true do
23
+ context "Black box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(static_array).to eq(123)
29
29
  end
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black Box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(strings).to eq("Ted says \"Oh my God thats a big sandwich!\"")
29
29
  expect(string_ret).to eq("This is a returned string.")
@@ -31,4 +31,4 @@ describe Rubex do
31
31
  end
32
32
  end
33
33
  end
34
- end
34
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Rubex do
3
+ describe Rubex do
4
4
  test_case = "struct"
5
5
 
6
6
  context "Case: #{test_case}" do
@@ -20,15 +20,15 @@ describe Rubex do
20
20
  end
21
21
  end
22
22
 
23
- context "Black Box testing", this: true do
23
+ context "Black Box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(structure("aa",2,3)).to eq(666)
29
29
  expect(struct_index).to eq(4)
30
30
  expect(access_struct_obj).to eq(1)
31
- expect(struct_ptr).to eq(7)
31
+ expect(struct_ptr).to eq(9)
32
32
  end
33
33
  end
34
34
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubex do
4
+ test_case = 'temp_allocation'
5
+
6
+ context "Case: #{test_case}" do
7
+ before do
8
+ @path = path_str test_case
9
+ end
10
+
11
+ context ".ast" do
12
+ it "generates the AST" do
13
+ t = Rubex::Compiler.ast(@path + '.rubex')
14
+ end
15
+ end
16
+
17
+ context ".compile" do
18
+ it "compiles to valid C file" do
19
+ t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
20
+ end
21
+ end
22
+
23
+ context "Black Box testing" do
24
+ it "compiles and checks for valid output" do
25
+ setup_and_teardown_compiled_files(test_case) do |dir|
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
+
28
+ expect(test_temp("")).to eq("small")
29
+ expect(test_temp(nil)).to eq("nil")
30
+ expect(test_temp("aa")).to eq("large")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -25,8 +25,8 @@ describe Rubex do
25
25
  it "compiles and checks for valid output" do
26
26
  setup_and_teardown_compiled_files(test_case) do
27
27
  dir = dir_str test_case
28
- require_relative "#{dir}/#{test_case}.so"
29
-
28
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
29
+
30
30
  t = TestTypeCasts.new
31
31
 
32
32
  expect(t.test_this).to eq(10)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Rubex do
3
+ describe Rubex do
4
4
  test_case = "var_declarations"
5
5
 
6
6
  context "Case: #{test_case}" do
@@ -23,7 +23,7 @@ describe Rubex do
23
23
  context "Black Box testing" do
24
24
  it "compiles and checks for valid output" do
25
25
  setup_and_teardown_compiled_files(test_case) do |dir|
26
- require_relative "#{dir}/#{test_case}.so"
26
+ require_relative "#{dir}/#{test_case}.#{os_extension}"
27
27
 
28
28
  expect(additive(1,5,2)).to be_within(0.001).of(6.6)
29
29
  expect(declare_in_the_middle).to eq(7)
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubex
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sameer Deshmukh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-17 00:00:00.000000000 Z
11
+ date: 2018-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.20'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: racc
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  description: |
154
182
  A Ruby-like language for writing Ruby C extensions.
155
183
 
@@ -197,16 +225,145 @@ files:
197
225
  - lib/rubex.rb
198
226
  - lib/rubex/ast.rb
199
227
  - lib/rubex/ast/expression.rb
228
+ - lib/rubex/ast/expression/actual_arg_list.rb
229
+ - lib/rubex/ast/expression/analysed_element_ref.rb
230
+ - lib/rubex/ast/expression/analysed_element_ref/c_var_element_ref.rb
231
+ - lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb
232
+ - lib/rubex/ast/expression/arg_declaration.rb
233
+ - lib/rubex/ast/expression/binary.rb
234
+ - lib/rubex/ast/expression/binary/binary_boolean.rb
235
+ - lib/rubex/ast/expression/binary/binary_boolean_special_op.rb
236
+ - lib/rubex/ast/expression/binary/empty_classes.rb
237
+ - lib/rubex/ast/expression/block_given.rb
238
+ - lib/rubex/ast/expression/coerce_object.rb
239
+ - lib/rubex/ast/expression/command_call.rb
240
+ - lib/rubex/ast/expression/command_call/struct_or_union_member_call.rb
241
+ - lib/rubex/ast/expression/element_ref.rb
242
+ - lib/rubex/ast/expression/empty.rb
243
+ - lib/rubex/ast/expression/from_ruby_object.rb
244
+ - lib/rubex/ast/expression/func_ptr_arg_declaration.rb
245
+ - lib/rubex/ast/expression/func_ptr_internal_arg_declaration.rb
246
+ - lib/rubex/ast/expression/literal.rb
247
+ - lib/rubex/ast/expression/literal/array_lit.rb
248
+ - lib/rubex/ast/expression/literal/c_null.rb
249
+ - lib/rubex/ast/expression/literal/char.rb
250
+ - lib/rubex/ast/expression/literal/double.rb
251
+ - lib/rubex/ast/expression/literal/false.rb
252
+ - lib/rubex/ast/expression/literal/hash_lit.rb
253
+ - lib/rubex/ast/expression/literal/int.rb
254
+ - lib/rubex/ast/expression/literal/nil.rb
255
+ - lib/rubex/ast/expression/literal/ruby_symbol.rb
256
+ - lib/rubex/ast/expression/literal/string_lit.rb
257
+ - lib/rubex/ast/expression/literal/true.rb
258
+ - lib/rubex/ast/expression/method_call.rb
259
+ - lib/rubex/ast/expression/method_call/c_function_call.rb
260
+ - lib/rubex/ast/expression/method_call/ruby_method_call.rb
261
+ - lib/rubex/ast/expression/name.rb
262
+ - lib/rubex/ast/expression/ruby_constant.rb
263
+ - lib/rubex/ast/expression/ruby_object_element_ref/ruby_array_element_ref.rb
264
+ - lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb
265
+ - lib/rubex/ast/expression/self.rb
266
+ - lib/rubex/ast/expression/size_of.rb
267
+ - lib/rubex/ast/expression/struct_or_union_member_call/element_ref_member_call.rb
268
+ - lib/rubex/ast/expression/to_ruby_object.rb
269
+ - lib/rubex/ast/expression/typecast.rb
270
+ - lib/rubex/ast/expression/typecast_to.rb
271
+ - lib/rubex/ast/expression/unary.rb
272
+ - lib/rubex/ast/expression/unary_base.rb
273
+ - lib/rubex/ast/expression/unary_base/ampersand.rb
274
+ - lib/rubex/ast/expression/unary_base/unary_bit_not.rb
275
+ - lib/rubex/ast/expression/unary_base/unary_not.rb
276
+ - lib/rubex/ast/expression/unary_base/unary_sub.rb
200
277
  - lib/rubex/ast/node.rb
201
278
  - lib/rubex/ast/statement.rb
279
+ - lib/rubex/ast/statement/alias.rb
280
+ - lib/rubex/ast/statement/argument_list.rb
281
+ - lib/rubex/ast/statement/assign.rb
282
+ - lib/rubex/ast/statement/begin_block.rb
283
+ - lib/rubex/ast/statement/begin_block/begin.rb
284
+ - lib/rubex/ast/statement/begin_block/else.rb
285
+ - lib/rubex/ast/statement/begin_block/ensure.rb
286
+ - lib/rubex/ast/statement/begin_block/rescue.rb
287
+ - lib/rubex/ast/statement/break.rb
288
+ - lib/rubex/ast/statement/c_array_decl.rb
289
+ - lib/rubex/ast/statement/c_base_type.rb
290
+ - lib/rubex/ast/statement/c_function_decl.rb
291
+ - lib/rubex/ast/statement/c_ptr_decl.rb
292
+ - lib/rubex/ast/statement/c_ptr_decl/c_ptr_func_decl.rb
293
+ - lib/rubex/ast/statement/c_struct_or_union_def.rb
294
+ - lib/rubex/ast/statement/expression.rb
295
+ - lib/rubex/ast/statement/for.rb
296
+ - lib/rubex/ast/statement/forward_decl.rb
297
+ - lib/rubex/ast/statement/if_block.rb
298
+ - lib/rubex/ast/statement/if_block/else.rb
299
+ - lib/rubex/ast/statement/if_block/elsif.rb
300
+ - lib/rubex/ast/statement/if_block/helper.rb
301
+ - lib/rubex/ast/statement/print.rb
302
+ - lib/rubex/ast/statement/raise.rb
303
+ - lib/rubex/ast/statement/return.rb
304
+ - lib/rubex/ast/statement/var_decl.rb
305
+ - lib/rubex/ast/statement/while.rb
306
+ - lib/rubex/ast/statement/yield.rb
202
307
  - lib/rubex/ast/top_statement.rb
308
+ - lib/rubex/ast/top_statement/c_bindings.rb
309
+ - lib/rubex/ast/top_statement/klass.rb
310
+ - lib/rubex/ast/top_statement/klass/attached_klass.rb
311
+ - lib/rubex/ast/top_statement/method_def.rb
312
+ - lib/rubex/ast/top_statement/method_def/c_function_def.rb
313
+ - lib/rubex/ast/top_statement/method_def/ruby_method_def.rb
314
+ - lib/rubex/cli.rb
203
315
  - lib/rubex/code_writer.rb
204
316
  - lib/rubex/compiler.rb
205
317
  - lib/rubex/compiler_config.rb
206
318
  - lib/rubex/constants.rb
207
319
  - lib/rubex/data_type.rb
320
+ - lib/rubex/data_type/c_array.rb
321
+ - lib/rubex/data_type/c_function.rb
322
+ - lib/rubex/data_type/c_ptr.rb
323
+ - lib/rubex/data_type/c_str.rb
324
+ - lib/rubex/data_type/c_struct_or_union.rb
325
+ - lib/rubex/data_type/char.rb
326
+ - lib/rubex/data_type/f_32.rb
327
+ - lib/rubex/data_type/f_64.rb
328
+ - lib/rubex/data_type/int.rb
329
+ - lib/rubex/data_type/int/c_boolean.rb
330
+ - lib/rubex/data_type/int_16.rb
331
+ - lib/rubex/data_type/int_32.rb
332
+ - lib/rubex/data_type/int_64.rb
333
+ - lib/rubex/data_type/int_8.rb
334
+ - lib/rubex/data_type/l_int.rb
335
+ - lib/rubex/data_type/l_l_int.rb
336
+ - lib/rubex/data_type/ruby_method.rb
337
+ - lib/rubex/data_type/ruby_object.rb
338
+ - lib/rubex/data_type/ruby_object/boolean.rb
339
+ - lib/rubex/data_type/ruby_object/boolean/false_type.rb
340
+ - lib/rubex/data_type/ruby_object/boolean/true_type.rb
341
+ - lib/rubex/data_type/ruby_object/nil_type.rb
342
+ - lib/rubex/data_type/ruby_object/ruby_array.rb
343
+ - lib/rubex/data_type/ruby_object/ruby_constant.rb
344
+ - lib/rubex/data_type/ruby_object/ruby_constant/ruby_class.rb
345
+ - lib/rubex/data_type/ruby_object/ruby_hash.rb
346
+ - lib/rubex/data_type/ruby_object/ruby_string.rb
347
+ - lib/rubex/data_type/ruby_object/ruby_symbol.rb
348
+ - lib/rubex/data_type/type_def.rb
349
+ - lib/rubex/data_type/u_char.rb
350
+ - lib/rubex/data_type/u_int.rb
351
+ - lib/rubex/data_type/u_int_16.rb
352
+ - lib/rubex/data_type/u_int_32.rb
353
+ - lib/rubex/data_type/u_int_64.rb
354
+ - lib/rubex/data_type/u_int_8.rb
355
+ - lib/rubex/data_type/u_l_int.rb
356
+ - lib/rubex/data_type/u_l_int/size_t.rb
357
+ - lib/rubex/data_type/u_l_l_int.rb
358
+ - lib/rubex/data_type/void.rb
359
+ - lib/rubex/data_type_helpers/float_helpers.rb
360
+ - lib/rubex/data_type_helpers/helpers.rb
361
+ - lib/rubex/data_type_helpers/int_helpers.rb
362
+ - lib/rubex/data_type_helpers/u_int_helpers.rb
208
363
  - lib/rubex/error.rb
209
364
  - lib/rubex/helpers.rb
365
+ - lib/rubex/helpers/node_type_methods.rb
366
+ - lib/rubex/helpers/writers.rb
210
367
  - lib/rubex/lexer.rex
211
368
  - lib/rubex/lexer.rex.rb
212
369
  - lib/rubex/parser.racc
@@ -229,6 +386,7 @@ files:
229
386
  - spec/call_by_reference_spec.rb
230
387
  - spec/class_methods_spec.rb
231
388
  - spec/class_spec.rb
389
+ - spec/cli_spec.rb
232
390
  - spec/comments_spec.rb
233
391
  - spec/default_args_spec.rb
234
392
  - spec/error_handling_spec.rb
@@ -246,6 +404,7 @@ files:
246
404
  - spec/fixtures/call_by_reference/call_by_reference.rubex
247
405
  - spec/fixtures/class/class.rubex
248
406
  - spec/fixtures/class_methods/class_methods.rubex
407
+ - spec/fixtures/cli/cli.rubex
249
408
  - spec/fixtures/comments/comments.rubex
250
409
  - spec/fixtures/default_args/default_args.rubex
251
410
  - spec/fixtures/error_handling/error_handling.rubex
@@ -269,6 +428,7 @@ files:
269
428
  - spec/fixtures/static_array/static_array.rubex
270
429
  - spec/fixtures/string_literals/string_literals.rubex
271
430
  - spec/fixtures/struct/struct.rubex
431
+ - spec/fixtures/temp_allocation/temp_allocation.rubex
272
432
  - spec/fixtures/typecasting/typecasting.rubex
273
433
  - spec/fixtures/var_declarations/var_declarations.rubex
274
434
  - spec/if_else_spec.rb
@@ -287,6 +447,7 @@ files:
287
447
  - spec/static_array_spec.rb
288
448
  - spec/string_literals_spec.rb
289
449
  - spec/struct_spec.rb
450
+ - spec/temp_allocation_spec.rb
290
451
  - spec/typecasting_spec.rb
291
452
  - spec/var_declarions_spec.rb
292
453
  homepage: http://github.com/sciruby/rubex
@@ -309,7 +470,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
309
470
  version: '0'
310
471
  requirements: []
311
472
  rubyforge_project:
312
- rubygems_version: 2.6.8
473
+ rubygems_version: 2.7.4
313
474
  signing_key:
314
475
  specification_version: 4
315
476
  summary: A Ruby-like language for writing Ruby C extensions. Rubex keeps you happy
@@ -327,6 +488,7 @@ test_files:
327
488
  - spec/call_by_reference_spec.rb
328
489
  - spec/class_methods_spec.rb
329
490
  - spec/class_spec.rb
491
+ - spec/cli_spec.rb
330
492
  - spec/comments_spec.rb
331
493
  - spec/default_args_spec.rb
332
494
  - spec/error_handling_spec.rb
@@ -344,6 +506,7 @@ test_files:
344
506
  - spec/fixtures/call_by_reference/call_by_reference.rubex
345
507
  - spec/fixtures/class/class.rubex
346
508
  - spec/fixtures/class_methods/class_methods.rubex
509
+ - spec/fixtures/cli/cli.rubex
347
510
  - spec/fixtures/comments/comments.rubex
348
511
  - spec/fixtures/default_args/default_args.rubex
349
512
  - spec/fixtures/error_handling/error_handling.rubex
@@ -367,6 +530,7 @@ test_files:
367
530
  - spec/fixtures/static_array/static_array.rubex
368
531
  - spec/fixtures/string_literals/string_literals.rubex
369
532
  - spec/fixtures/struct/struct.rubex
533
+ - spec/fixtures/temp_allocation/temp_allocation.rubex
370
534
  - spec/fixtures/typecasting/typecasting.rubex
371
535
  - spec/fixtures/var_declarations/var_declarations.rubex
372
536
  - spec/if_else_spec.rb
@@ -385,5 +549,6 @@ test_files:
385
549
  - spec/static_array_spec.rb
386
550
  - spec/string_literals_spec.rb
387
551
  - spec/struct_spec.rb
552
+ - spec/temp_allocation_spec.rb
388
553
  - spec/typecasting_spec.rb
389
554
  - spec/var_declarions_spec.rb