rubex 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -2
- data/.travis.yml +9 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +4 -1
- data/Rakefile +2 -2
- data/bin/rubex +4 -5
- data/lib/rubex.rb +4 -4
- data/lib/rubex/ast.rb +4 -1
- data/lib/rubex/ast/expression.rb +22 -1191
- data/lib/rubex/ast/expression/actual_arg_list.rb +40 -0
- data/lib/rubex/ast/expression/analysed_element_ref.rb +26 -0
- data/lib/rubex/ast/expression/analysed_element_ref/c_var_element_ref.rb +30 -0
- data/lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb +42 -0
- data/lib/rubex/ast/expression/arg_declaration.rb +43 -0
- data/lib/rubex/ast/expression/binary.rb +57 -0
- data/lib/rubex/ast/expression/binary/binary_boolean.rb +23 -0
- data/lib/rubex/ast/expression/binary/binary_boolean_special_op.rb +20 -0
- data/lib/rubex/ast/expression/binary/empty_classes.rb +62 -0
- data/lib/rubex/ast/expression/block_given.rb +15 -0
- data/lib/rubex/ast/expression/coerce_object.rb +15 -0
- data/lib/rubex/ast/expression/command_call.rb +74 -0
- data/lib/rubex/ast/expression/command_call/struct_or_union_member_call.rb +38 -0
- data/lib/rubex/ast/expression/element_ref.rb +64 -0
- data/lib/rubex/ast/expression/empty.rb +13 -0
- data/lib/rubex/ast/expression/from_ruby_object.rb +20 -0
- data/lib/rubex/ast/expression/func_ptr_arg_declaration.rb +21 -0
- data/lib/rubex/ast/expression/func_ptr_internal_arg_declaration.rb +13 -0
- data/lib/rubex/ast/expression/literal.rb +30 -0
- data/lib/rubex/ast/expression/literal/array_lit.rb +51 -0
- data/lib/rubex/ast/expression/literal/c_null.rb +15 -0
- data/lib/rubex/ast/expression/literal/char.rb +36 -0
- data/lib/rubex/ast/expression/literal/double.rb +14 -0
- data/lib/rubex/ast/expression/literal/false.rb +33 -0
- data/lib/rubex/ast/expression/literal/hash_lit.rb +45 -0
- data/lib/rubex/ast/expression/literal/int.rb +14 -0
- data/lib/rubex/ast/expression/literal/nil.rb +14 -0
- data/lib/rubex/ast/expression/literal/ruby_symbol.rb +22 -0
- data/lib/rubex/ast/expression/literal/string_lit.rb +45 -0
- data/lib/rubex/ast/expression/literal/true.rb +29 -0
- data/lib/rubex/ast/expression/method_call.rb +52 -0
- data/lib/rubex/ast/expression/method_call/c_function_call.rb +40 -0
- data/lib/rubex/ast/expression/method_call/ruby_method_call.rb +83 -0
- data/lib/rubex/ast/expression/name.rb +127 -0
- data/lib/rubex/ast/expression/ruby_constant.rb +25 -0
- data/lib/rubex/ast/expression/ruby_object_element_ref/ruby_array_element_ref.rb +20 -0
- data/lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb +22 -0
- data/lib/rubex/ast/expression/self.rb +15 -0
- data/lib/rubex/ast/expression/size_of.rb +22 -0
- data/lib/rubex/ast/expression/struct_or_union_member_call/element_ref_member_call.rb +23 -0
- data/lib/rubex/ast/expression/to_ruby_object.rb +21 -0
- data/lib/rubex/ast/expression/typecast.rb +20 -0
- data/lib/rubex/ast/expression/typecast_to.rb +10 -0
- data/lib/rubex/ast/expression/unary.rb +37 -0
- data/lib/rubex/ast/expression/unary_base.rb +24 -0
- data/lib/rubex/ast/expression/unary_base/ampersand.rb +16 -0
- data/lib/rubex/ast/expression/unary_base/unary_bit_not.rb +18 -0
- data/lib/rubex/ast/expression/unary_base/unary_not.rb +18 -0
- data/lib/rubex/ast/expression/unary_base/unary_sub.rb +18 -0
- data/lib/rubex/ast/node.rb +111 -111
- data/lib/rubex/ast/statement.rb +9 -1160
- data/lib/rubex/ast/statement/alias.rb +43 -0
- data/lib/rubex/ast/statement/argument_list.rb +59 -0
- data/lib/rubex/ast/statement/assign.rb +35 -0
- data/lib/rubex/ast/statement/begin_block.rb +14 -0
- data/lib/rubex/ast/statement/begin_block/begin.rb +202 -0
- data/lib/rubex/ast/statement/begin_block/else.rb +21 -0
- data/lib/rubex/ast/statement/begin_block/ensure.rb +21 -0
- data/lib/rubex/ast/statement/begin_block/rescue.rb +34 -0
- data/lib/rubex/ast/statement/break.rb +18 -0
- data/lib/rubex/ast/statement/c_array_decl.rb +49 -0
- data/lib/rubex/ast/statement/c_base_type.rb +26 -0
- data/lib/rubex/ast/statement/c_function_decl.rb +30 -0
- data/lib/rubex/ast/statement/c_ptr_decl.rb +52 -0
- data/lib/rubex/ast/statement/c_ptr_decl/c_ptr_func_decl.rb +25 -0
- data/lib/rubex/ast/statement/c_struct_or_union_def.rb +49 -0
- data/lib/rubex/ast/statement/expression.rb +26 -0
- data/lib/rubex/ast/statement/for.rb +73 -0
- data/lib/rubex/ast/statement/forward_decl.rb +31 -0
- data/lib/rubex/ast/statement/if_block.rb +64 -0
- data/lib/rubex/ast/statement/if_block/else.rb +30 -0
- data/lib/rubex/ast/statement/if_block/elsif.rb +22 -0
- data/lib/rubex/ast/statement/if_block/helper.rb +38 -0
- data/lib/rubex/ast/statement/print.rb +49 -0
- data/lib/rubex/ast/statement/raise.rb +66 -0
- data/lib/rubex/ast/statement/return.rb +45 -0
- data/lib/rubex/ast/statement/var_decl.rb +49 -0
- data/lib/rubex/ast/statement/while.rb +34 -0
- data/lib/rubex/ast/statement/yield.rb +41 -0
- data/lib/rubex/ast/top_statement.rb +1 -815
- data/lib/rubex/ast/top_statement/c_bindings.rb +145 -0
- data/lib/rubex/ast/top_statement/klass.rb +125 -0
- data/lib/rubex/ast/top_statement/klass/attached_klass.rb +417 -0
- data/lib/rubex/ast/top_statement/method_def.rb +110 -0
- data/lib/rubex/ast/top_statement/method_def/c_function_def.rb +26 -0
- data/lib/rubex/ast/top_statement/method_def/ruby_method_def.rb +33 -0
- data/lib/rubex/cli.rb +26 -0
- data/lib/rubex/code_writer.rb +1 -1
- data/lib/rubex/compiler.rb +49 -28
- data/lib/rubex/compiler_config.rb +4 -2
- data/lib/rubex/constants.rb +71 -71
- data/lib/rubex/data_type.rb +9 -675
- data/lib/rubex/data_type/c_array.rb +33 -0
- data/lib/rubex/data_type/c_function.rb +23 -0
- data/lib/rubex/data_type/c_ptr.rb +71 -0
- data/lib/rubex/data_type/c_str.rb +23 -0
- data/lib/rubex/data_type/c_struct_or_union.rb +23 -0
- data/lib/rubex/data_type/char.rb +30 -0
- data/lib/rubex/data_type/f_32.rb +38 -0
- data/lib/rubex/data_type/f_64.rb +38 -0
- data/lib/rubex/data_type/int.rb +32 -0
- data/lib/rubex/data_type/int/c_boolean.rb +13 -0
- data/lib/rubex/data_type/int_16.rb +32 -0
- data/lib/rubex/data_type/int_32.rb +32 -0
- data/lib/rubex/data_type/int_64.rb +36 -0
- data/lib/rubex/data_type/int_8.rb +33 -0
- data/lib/rubex/data_type/l_int.rb +38 -0
- data/lib/rubex/data_type/l_l_int.rb +26 -0
- data/lib/rubex/data_type/ruby_method.rb +22 -0
- data/lib/rubex/data_type/ruby_object.rb +19 -0
- data/lib/rubex/data_type/ruby_object/boolean.rb +11 -0
- data/lib/rubex/data_type/ruby_object/boolean/false_type.rb +5 -0
- data/lib/rubex/data_type/ruby_object/boolean/true_type.rb +5 -0
- data/lib/rubex/data_type/ruby_object/nil_type.rb +9 -0
- data/lib/rubex/data_type/ruby_object/ruby_array.rb +10 -0
- data/lib/rubex/data_type/ruby_object/ruby_constant.rb +18 -0
- data/lib/rubex/data_type/ruby_object/ruby_constant/ruby_class.rb +18 -0
- data/lib/rubex/data_type/ruby_object/ruby_hash.rb +9 -0
- data/lib/rubex/data_type/ruby_object/ruby_string.rb +10 -0
- data/lib/rubex/data_type/ruby_object/ruby_symbol.rb +10 -0
- data/lib/rubex/data_type/type_def.rb +34 -0
- data/lib/rubex/data_type/u_char.rb +27 -0
- data/lib/rubex/data_type/u_int.rb +32 -0
- data/lib/rubex/data_type/u_int_16.rb +22 -0
- data/lib/rubex/data_type/u_int_32.rb +22 -0
- data/lib/rubex/data_type/u_int_64.rb +26 -0
- data/lib/rubex/data_type/u_int_8.rb +22 -0
- data/lib/rubex/data_type/u_l_int.rb +36 -0
- data/lib/rubex/data_type/u_l_int/size_t.rb +10 -0
- data/lib/rubex/data_type/u_l_l_int.rb +26 -0
- data/lib/rubex/data_type/void.rb +15 -0
- data/lib/rubex/data_type_helpers/float_helpers.rb +8 -0
- data/lib/rubex/data_type_helpers/helpers.rb +48 -0
- data/lib/rubex/data_type_helpers/int_helpers.rb +10 -0
- data/lib/rubex/data_type_helpers/u_int_helpers.rb +11 -0
- data/lib/rubex/helpers.rb +35 -118
- data/lib/rubex/helpers/node_type_methods.rb +9 -0
- data/lib/rubex/helpers/writers.rb +79 -0
- data/lib/rubex/parser.racc +83 -34
- data/lib/rubex/parser.racc.rb +233 -184
- data/lib/rubex/version.rb +2 -2
- data/rubex.gemspec +2 -0
- data/spec/basic_ruby_method_spec.rb +1 -1
- data/spec/binding_ptr_args_spec.rb +2 -2
- data/spec/bitwise_operators_spec.rb +1 -1
- data/spec/blocks_spec.rb +2 -2
- data/spec/c_bindings_spec.rb +1 -1
- data/spec/c_constants_spec.rb +1 -1
- data/spec/c_function_ptrs_spec.rb +1 -1
- data/spec/c_functions_spec.rb +2 -2
- data/spec/c_struct_interface_spec.rb +1 -1
- data/spec/call_by_reference_spec.rb +2 -2
- data/spec/class_methods_spec.rb +2 -2
- data/spec/class_spec.rb +4 -4
- data/spec/cli_spec.rb +43 -0
- data/spec/comments_spec.rb +2 -2
- data/spec/default_args_spec.rb +21 -23
- data/spec/error_handling_spec.rb +1 -1
- data/spec/examples_spec.rb +4 -4
- data/spec/expressions_spec.rb +1 -1
- data/spec/fixtures/cli/cli.rubex +3 -0
- data/spec/fixtures/examples/array_to_hash.rubex +1 -1
- data/spec/fixtures/examples/rcsv.rubex +10 -6
- data/spec/fixtures/loops/loops.rubex +1 -1
- data/spec/fixtures/ruby_strings/string_blank_bm.rb +7 -5
- data/spec/fixtures/struct/struct.rubex +7 -2
- data/spec/fixtures/temp_allocation/temp_allocation.rubex +8 -0
- data/spec/if_else_spec.rb +3 -7
- data/spec/implicit_lib_include_spec.rb +1 -1
- data/spec/init_ruby_objects_with_literal_syntax_spec.rb +1 -1
- data/spec/loops_spec.rb +1 -1
- data/spec/recursion_spec.rb +18 -21
- data/spec/ruby_constant_method_calls_spec.rb +4 -4
- data/spec/ruby_operators_spec.rb +1 -1
- data/spec/ruby_raise_spec.rb +1 -1
- data/spec/ruby_strings_spec.rb +3 -3
- data/spec/ruby_symbols_spec.rb +1 -1
- data/spec/ruby_types_spec.rb +2 -2
- data/spec/spec_helper.rb +42 -10
- data/spec/statement_expression_spec.rb +3 -3
- data/spec/static_array_spec.rb +3 -3
- data/spec/string_literals_spec.rb +2 -2
- data/spec/struct_spec.rb +4 -4
- data/spec/temp_allocation_spec.rb +35 -0
- data/spec/typecasting_spec.rb +2 -2
- data/spec/var_declarions_spec.rb +2 -2
- metadata +168 -3
data/lib/rubex/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Rubex
|
2
|
-
VERSION = "0.1".freeze
|
3
|
-
end
|
2
|
+
VERSION = "0.1.1".freeze
|
3
|
+
end
|
data/rubex.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
+
spec.add_dependency 'thor', '~> 0.20'
|
27
28
|
spec.add_runtime_dependency 'racc', '~> 1.4.14'
|
28
29
|
spec.add_runtime_dependency 'rake-compiler', '~> 1.0.4'
|
29
30
|
|
@@ -35,4 +36,5 @@ Gem::Specification.new do |spec|
|
|
35
36
|
spec.add_development_dependency 'pretty_backtrace'
|
36
37
|
spec.add_development_dependency 'ruby-prof'
|
37
38
|
spec.add_development_dependency 'benchmark-ips'
|
39
|
+
spec.add_development_dependency 'simplecov'
|
38
40
|
end
|
@@ -25,7 +25,7 @@ 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}
|
28
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
29
29
|
expect(addition(4,5)).to eq(9)
|
30
30
|
end
|
31
31
|
end
|
@@ -23,11 +23,11 @@ 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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
expect(test_function("hello")).to eq(104)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -24,7 +24,7 @@ describe Rubex do
|
|
24
24
|
context "Black Box testing" do
|
25
25
|
it "compiles and checks for valid output" do
|
26
26
|
setup_and_teardown_compiled_files(test_case) do |dir|
|
27
|
-
require_relative "#{dir}/#{test_case}
|
27
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
28
28
|
|
29
29
|
cls = BitWise.new
|
30
30
|
expect(cls.wise_or).to eq(3)
|
data/spec/blocks_spec.rb
CHANGED
@@ -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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
block_scene do |num|
|
29
29
|
expect([1,2,3,4,5,6].include?(num)).to eq(true)
|
@@ -32,4 +32,4 @@ describe Rubex do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
data/spec/c_bindings_spec.rb
CHANGED
@@ -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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
expect(maths(3,5,"hello")).to be_within(0.001).of(300.763)
|
29
29
|
expect(stray_cos).to be_within(0.001).of(-0.210)
|
data/spec/c_constants_spec.rb
CHANGED
@@ -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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
expect(have_ruby_h).to eq(1)
|
29
29
|
end
|
@@ -24,7 +24,7 @@ describe Rubex do
|
|
24
24
|
context "Black Box testing", focus: true do
|
25
25
|
it "compiles and checks for valid output" do
|
26
26
|
setup_and_teardown_compiled_files(test_case) do |dir|
|
27
|
-
require_relative "#{dir}/#{test_case}
|
27
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
28
28
|
|
29
29
|
cls = CFunctionPtrs.new
|
30
30
|
|
data/spec/c_functions_spec.rb
CHANGED
@@ -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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
c = CFunctions.new
|
29
29
|
expect(c.pure_ruby_method).to eq(50)
|
@@ -32,4 +32,4 @@ describe Rubex do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
end
|
35
|
+
end
|
@@ -24,7 +24,7 @@ describe Rubex do
|
|
24
24
|
context "Black Box testing", focus: true do
|
25
25
|
it "compiles and checks for valid output" do
|
26
26
|
setup_and_teardown_compiled_files(test_case) do |dir|
|
27
|
-
require_relative "#{dir}/#{test_case}
|
27
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
28
28
|
id = 44
|
29
29
|
m = Music.new("Animals as Leaders", "CAFO", id)
|
30
30
|
|
@@ -23,11 +23,11 @@ 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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
expect(CallByReference.new.ref_call).to eq(4)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
data/spec/class_methods_spec.rb
CHANGED
@@ -23,11 +23,11 @@ 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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
expect(Bhau.say_what("hello there!")).to eq(10)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
data/spec/class_spec.rb
CHANGED
@@ -14,16 +14,16 @@ describe Rubex do
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
context ".compile"
|
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"
|
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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
k = Kustom.new
|
29
29
|
expect(k.bye).to eq("Bye world!")
|
@@ -37,4 +37,4 @@ describe Rubex do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
include Rubex::AST
|
3
|
+
|
4
|
+
describe Rubex do
|
5
|
+
test_case = 'cli'
|
6
|
+
|
7
|
+
context "Case : #{test_case}" do
|
8
|
+
before do
|
9
|
+
@path = path_str test_case
|
10
|
+
@dir = dir_str test_case
|
11
|
+
@cli = Rubex::Cli.new
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'generate' do
|
15
|
+
it "is expected to create valid files for generating Makefile in current Directory" do
|
16
|
+
@cli.generate("#{@path}.rubex")
|
17
|
+
expect(File.exist?("#{test_case}/#{test_case}.c")).to be(true)
|
18
|
+
expect(File.exist?("#{test_case}/extconf.rb")).to be(true)
|
19
|
+
FileUtils.rm_rf("#{Dir.pwd}/cli")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is expected to create valid files for generating Makefile in specified directory" do
|
23
|
+
setup_and_teardown_compiled_files(test_case) do
|
24
|
+
@cli.options = {dir: @dir}
|
25
|
+
@cli.generate("#{@path}.rubex")
|
26
|
+
expect(File.exist?("#{@path}.c")).to be(true)
|
27
|
+
expect(File.exist?("#{@dir}/extconf.rb")).to be(true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'install' do
|
33
|
+
it "is expected to run make utility and create a valid .#{os_extension} file" do
|
34
|
+
setup_and_teardown_compiled_files(test_case) do
|
35
|
+
@cli.options = {dir: @dir}
|
36
|
+
@cli.generate("#{@path}.rubex")
|
37
|
+
@cli.install(@dir)
|
38
|
+
expect(File.exist?("#{@path}.#{os_extension}")).to be(true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/comments_spec.rb
CHANGED
@@ -23,11 +23,11 @@ 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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
expect(crazy_comment).to eq(4)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
data/spec/default_args_spec.rb
CHANGED
@@ -1,35 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rubex do
|
4
|
-
|
5
|
-
test_case = "default_args"
|
4
|
+
test_case = 'default_args'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
context "Case: #{test_case}" do
|
7
|
+
before do
|
8
|
+
@path = path_str test_case
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
17
|
+
context '.compile', focus: true 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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
23
|
+
context 'Black Box testing', focus: true 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
|
+
o = { a: 'world!!' }
|
28
|
+
expect(default_method(1)).to eq(nil)
|
29
|
+
expect(default_method(1, true, o)).to eq(7)
|
30
|
+
expect(default_method(1, nil, a: 44)).to eq(5)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
data/spec/error_handling_spec.rb
CHANGED
@@ -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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
cls = Handler.new
|
29
29
|
|
data/spec/examples_spec.rb
CHANGED
@@ -15,13 +15,13 @@ describe Rubex do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context ".compile"
|
18
|
+
context ".compile" do
|
19
19
|
it "compiles to valid C file" do
|
20
20
|
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
context "Black Box testing"
|
24
|
+
context "Black Box testing" do
|
25
25
|
it "compiles and checks for valid output" do
|
26
26
|
def rcsv
|
27
27
|
result = [
|
@@ -42,11 +42,11 @@ describe Rubex do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
setup_and_teardown_compiled_files(test_case, example) do |dir|
|
45
|
-
require_relative "#{dir}/#{example}
|
45
|
+
require_relative "#{dir}/#{example}/#{example}.#{os_extension}"
|
46
46
|
self.send(example.to_sym)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
data/spec/expressions_spec.rb
CHANGED
@@ -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}
|
26
|
+
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
27
27
|
|
28
28
|
expect(adder(1,3.4)).to eq(-548)
|
29
29
|
end
|
@@ -117,14 +117,18 @@ class Rcsv
|
|
117
117
|
parsed_field = ENCODED_STR_NEW(field_str, field_size, meta.encoding_index)
|
118
118
|
|
119
119
|
# Filter by row values listed in meta->only_rows */
|
120
|
-
if
|
121
|
-
|
122
|
-
|
120
|
+
if meta.only_rows != NULL
|
121
|
+
if (meta.current_col < meta.num_only_rows) && (meta.only_rows[meta.current_col] != nil) && (!rb_ary_includes(meta.only_rows[meta.current_col], parsed_field))
|
122
|
+
meta_p[0].skip_current_row = true
|
123
|
+
return
|
124
|
+
end
|
123
125
|
end
|
124
126
|
# Filter out by row values listed in meta->except_rows
|
125
|
-
if
|
126
|
-
meta.
|
127
|
-
|
127
|
+
if meta.except_rows != NULL
|
128
|
+
if (meta.current_col < meta.num_except_rows) && (meta.except_rows[meta.current_col] != nil) && (rb_ary_includes(meta.except_rows[meta.current_col], parsed_field))
|
129
|
+
meta.skip_current_row = true
|
130
|
+
return
|
131
|
+
end
|
128
132
|
end
|
129
133
|
|
130
134
|
# Assign the value to appropriate hash key if parsing into Hash */
|
@@ -1,24 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
# This file contains a benchmark between Rubex's blank? and the String#blank?
|
2
4
|
# from the the fast_blank gem.
|
3
5
|
|
4
|
-
require_relative
|
6
|
+
require_relative "ruby_strings.#{os_extension}"
|
5
7
|
require 'fast_blank'
|
6
8
|
require 'benchmark'
|
7
9
|
require 'benchmark/ips'
|
8
10
|
|
9
|
-
str=
|
11
|
+
str = ' ' * 2500 + 'dff'
|
10
12
|
|
11
13
|
Benchmark.ips do |x|
|
12
|
-
x.config(:
|
14
|
+
x.config(time: 5, warmup: 2)
|
13
15
|
|
14
16
|
x.time = 5
|
15
17
|
x.warmup = 2
|
16
18
|
|
17
|
-
x.report(
|
19
|
+
x.report('fast_blank') do
|
18
20
|
str.blank?
|
19
21
|
end
|
20
22
|
|
21
|
-
x.report(
|
23
|
+
x.report('blank?') do
|
22
24
|
blank? str
|
23
25
|
end
|
24
26
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
lib "rubex/ruby"; end
|
2
|
+
|
1
3
|
def structure(a, i32 b, i32 c)
|
2
4
|
fwd struct other_node
|
3
5
|
i32 f[10]
|
@@ -74,9 +76,12 @@ def struct_ptr
|
|
74
76
|
int i, j
|
75
77
|
end
|
76
78
|
|
77
|
-
node *a
|
79
|
+
node *a = <node*>xmalloc(sizeof(node))
|
78
80
|
a.i = 3
|
81
|
+
a.i += 1
|
82
|
+
a.i = a.i + 1
|
79
83
|
a.j = 4
|
80
84
|
|
81
85
|
return a.i + a.j
|
82
|
-
end
|
86
|
+
end
|
87
|
+
|