rubex 0.1.1 → 0.1.2
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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/CONTRIBUTING.md +73 -9
- data/HISTORY.md +19 -0
- data/README.md +53 -8
- data/REFERENCE.md +112 -44
- data/benchmarks/no_gil/no_gil.rb +24 -0
- data/benchmarks/no_gil/no_gil.rubex +22 -0
- data/bin/rubex +1 -1
- data/examples/c_struct_interface/c_struct_interface.rubex +1 -0
- data/lib/rubex.rb +1 -0
- data/lib/rubex/ast.rb +11 -7
- data/lib/rubex/ast/expression.rb +1 -1
- data/lib/rubex/ast/expression/actual_arg_list.rb +7 -0
- data/lib/rubex/ast/expression/analysed_element_ref/c_var_element_ref.rb +5 -2
- data/lib/rubex/ast/expression/analysed_element_ref/ruby_object_element_ref.rb +26 -9
- data/lib/rubex/ast/expression/binary/binary_boolean.rb +1 -1
- data/lib/rubex/ast/expression/binary/binary_expo.rb +34 -0
- data/lib/rubex/ast/expression/binary/colon2.rb +34 -0
- data/lib/rubex/ast/expression/binary/empty_classes.rb +0 -3
- data/lib/rubex/ast/expression/command_call.rb +24 -0
- data/lib/rubex/ast/{statement → expression/command_call}/print.rb +4 -5
- data/lib/rubex/ast/{statement → expression/command_call}/raise.rb +29 -24
- data/lib/rubex/ast/expression/command_call/require.rb +27 -0
- data/lib/rubex/ast/expression/command_call/yield.rb +36 -0
- data/lib/rubex/ast/expression/element_ref.rb +10 -5
- data/lib/rubex/ast/expression/instance_var.rb +33 -0
- data/lib/rubex/ast/expression/method_call.rb +4 -2
- data/lib/rubex/ast/expression/method_call/c_function_call.rb +4 -3
- data/lib/rubex/ast/expression/method_call/ruby_method_call.rb +7 -5
- data/lib/rubex/ast/expression/name.rb +10 -1
- data/lib/rubex/ast/expression/ruby_object_element_ref/ruby_array_element_ref.rb +5 -2
- data/lib/rubex/ast/expression/ruby_object_element_ref/ruby_hash_element_ref.rb +10 -2
- data/lib/rubex/ast/expression/to_ruby_object.rb +1 -0
- data/lib/rubex/ast/expression/unary.rb +7 -3
- data/lib/rubex/ast/expression/unary_base/ampersand.rb +5 -0
- data/lib/rubex/ast/node.rb +213 -185
- data/lib/rubex/ast/node/file_node.rb +25 -0
- data/lib/rubex/ast/node/main_node.rb +56 -0
- data/lib/rubex/ast/statement/begin_block/begin.rb +4 -3
- data/lib/rubex/ast/statement/c_array_decl.rb +1 -1
- data/lib/rubex/ast/statement/c_ptr_decl.rb +2 -0
- data/lib/rubex/ast/statement/no_gil_block.rb +70 -0
- data/lib/rubex/ast/statement/return.rb +1 -0
- data/lib/rubex/ast/top_statement.rb +1 -1
- data/lib/rubex/ast/top_statement/klass.rb +4 -0
- data/lib/rubex/ast/top_statement/klass/attached_klass.rb +88 -10
- data/lib/rubex/ast/top_statement/method_def.rb +2 -3
- data/lib/rubex/ast/top_statement/method_def/c_function_def.rb +10 -4
- data/lib/rubex/cli.rb +11 -6
- data/lib/rubex/code_supervisor.rb +49 -0
- data/lib/rubex/code_writer.rb +22 -1
- data/lib/rubex/compiler.rb +109 -30
- data/lib/rubex/compiler_config.rb +14 -1
- data/lib/rubex/constants.rb +3 -0
- data/lib/rubex/data_type.rb +2 -3
- data/lib/rubex/data_type/ruby_object/ruby_symbol.rb +0 -1
- data/lib/rubex/error.rb +4 -0
- data/lib/rubex/helpers/writers.rb +33 -4
- data/lib/rubex/lexer.rex +9 -1
- data/lib/rubex/lexer.rex.rb +15 -2
- data/lib/rubex/parser.racc +125 -49
- data/lib/rubex/parser.racc.rb +1526 -1376
- data/lib/rubex/rake_task.rb +42 -6
- data/lib/rubex/symbol_table/entry.rb +6 -0
- data/lib/rubex/symbol_table/scope.rb +28 -3
- data/lib/rubex/version.rb +1 -1
- data/rubex.gemspec +1 -0
- data/spec/basic_ruby_method_spec.rb +2 -2
- data/spec/blocks_spec.rb +2 -2
- data/spec/box_op_multi_args_spec.rb +34 -0
- data/spec/c_function_ptrs_spec.rb +2 -2
- data/spec/c_functions_spec.rb +2 -0
- data/spec/c_struct_interface_spec.rb +8 -3
- data/spec/default_args_spec.rb +2 -2
- data/spec/external_c_struct_spec.rb +33 -0
- data/spec/fixtures/api/consumer.rubex +0 -0
- data/spec/fixtures/api/implementation.rubex +0 -0
- data/spec/fixtures/api/implementation.rubexd +0 -0
- data/spec/fixtures/box_op_multi_args/box_op_multi_args.rubex +3 -0
- data/spec/fixtures/c_functions/c_functions.rubex +13 -0
- data/spec/fixtures/c_struct_interface/c_struct_interface.rubex +28 -0
- data/spec/fixtures/class_methods/class_methods.rubex +1 -1
- data/spec/fixtures/error_handling/error_handling.rubex +2 -2
- data/spec/fixtures/external_c_struct/external_c_struct.rubex +16 -0
- data/spec/fixtures/if_else/if_else.rubex +1 -1
- data/spec/fixtures/init_ruby_objects_with_literal_syntax/init_ruby_objects_with_literal_syntax.rubex +1 -1
- data/spec/fixtures/instance_variables/instance_variables.rubex +25 -0
- data/spec/fixtures/loops/loops.rubex +2 -2
- data/spec/fixtures/module/module.rubex +28 -0
- data/spec/fixtures/multi_file_programs/Rakefile +8 -0
- data/spec/fixtures/multi_file_programs/a.rubex +5 -0
- data/spec/fixtures/multi_file_programs/b.rubex +5 -0
- data/spec/fixtures/multi_file_programs/multi_file_programs.rubex +14 -0
- data/spec/fixtures/no_gil/no_gil.rubex +24 -0
- data/spec/fixtures/no_gil_attach_class/no_gil_attach_class.rubex +23 -0
- data/spec/fixtures/no_gil_compile_check/no_gil_compile_check.rubex +4 -0
- data/spec/fixtures/outside_stmts/outside_stmts.rubex +6 -0
- data/spec/fixtures/pow/pow.rubex +4 -0
- data/spec/fixtures/rake_task/single_file/test.rubex +3 -0
- data/spec/fixtures/recursion/recursion.rubex +1 -1
- data/spec/fixtures/ruby_constant_scoping/ruby_constant_scoping.rubex +7 -0
- data/spec/fixtures/ruby_operators/ruby_operators.rubex +1 -1
- data/spec/fixtures/ruby_raise/ruby_raise.rubex +2 -2
- data/spec/fixtures/ruby_types/ruby_types.rubex +4 -4
- data/spec/fixtures/statement_expression/statement_expression.rubex +2 -2
- data/spec/fixtures/static_array/static_array.rubex +3 -3
- data/spec/fixtures/string_literals/string_literals.rubex +12 -2
- data/spec/fixtures/struct/struct.rubex +1 -1
- data/spec/fixtures/var_declarations/var_declarations.rubex +1 -1
- data/spec/implicit_lib_include_spec.rb +2 -2
- data/spec/init_ruby_objects_with_literal_syntax_spec.rb +2 -2
- data/spec/instance_variables_spec.rb +33 -0
- data/spec/loops_spec.rb +2 -2
- data/spec/module_spec.rb +39 -0
- data/spec/multi_file_programs_spec.rb +41 -0
- data/spec/no_gil_attach_class_spec.rb +33 -0
- data/spec/no_gil_compile_check_spec.rb +25 -0
- data/spec/no_gil_spec.rb +36 -0
- data/spec/outside_stmts_spec.rb +34 -0
- data/spec/pow_spec.rb +33 -0
- data/spec/rake_task_spec.rb +142 -0
- data/spec/recursion_spec.rb +4 -4
- data/spec/ruby_constant_scoping_spec.rb +42 -0
- data/spec/ruby_raise_spec.rb +2 -2
- data/spec/ruby_symbols_spec.rb +2 -2
- data/spec/ruby_types_spec.rb +2 -2
- data/spec/spec_helper.rb +17 -3
- data/spec/string_literals_spec.rb +1 -0
- metadata +90 -6
- data/lib/rubex/ast/statement/yield.rb +0 -41
@@ -0,0 +1,25 @@
|
|
1
|
+
class Test
|
2
|
+
def initialize(foo, bar)
|
3
|
+
@foo = foo
|
4
|
+
@bar = bar
|
5
|
+
end
|
6
|
+
|
7
|
+
def addition
|
8
|
+
return @foo + @bar
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ToChar
|
13
|
+
def initialize(foo)
|
14
|
+
@foo = foo
|
15
|
+
end
|
16
|
+
|
17
|
+
def bar
|
18
|
+
char * b
|
19
|
+
b = @foo
|
20
|
+
|
21
|
+
char * c = @foo
|
22
|
+
|
23
|
+
return b
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Foo
|
2
|
+
class Bar
|
3
|
+
def initialize
|
4
|
+
end
|
5
|
+
|
6
|
+
def baz
|
7
|
+
return "hello world"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Bar
|
13
|
+
def self.a
|
14
|
+
return "a"
|
15
|
+
end
|
16
|
+
|
17
|
+
def b
|
18
|
+
return "b"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Outer
|
23
|
+
module Inner
|
24
|
+
def abc
|
25
|
+
return "abc"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'rubex/rake_task'
|
2
|
+
|
3
|
+
# specify all the rubex files to be compiled, along with the name of the main
|
4
|
+
# program that serves as the 'main' entry point.
|
5
|
+
Rubex::RakeTask.new("multi_file_programs") do
|
6
|
+
rubex_files ["a.rubex", "b.rubex", "multi_file_program.rubex"]
|
7
|
+
end
|
8
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib "rubex/ruby"; end
|
2
|
+
|
3
|
+
cfunc void _work_without_gil(double n) no_gil
|
4
|
+
while n > 0 do
|
5
|
+
n ** 0.5 + 4
|
6
|
+
n -= 1
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def work_without_gil(n)
|
11
|
+
double i = n
|
12
|
+
no_gil
|
13
|
+
_work_without_gil(i)
|
14
|
+
end
|
15
|
+
|
16
|
+
return i
|
17
|
+
end
|
18
|
+
|
19
|
+
def work_with_gil(double n)
|
20
|
+
while n > 0 do
|
21
|
+
n ** 0.5 + 4
|
22
|
+
n -= 1
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
struct test
|
2
|
+
int a
|
3
|
+
end
|
4
|
+
|
5
|
+
class A attach test
|
6
|
+
cfunc void __bar(int a) no_gil
|
7
|
+
int b = a
|
8
|
+
end
|
9
|
+
|
10
|
+
def foo
|
11
|
+
data$.test.a = 4
|
12
|
+
|
13
|
+
no_gil
|
14
|
+
__bar(data$.test.a)
|
15
|
+
end
|
16
|
+
|
17
|
+
return data$.test.a
|
18
|
+
end
|
19
|
+
|
20
|
+
cfunc void deallocate
|
21
|
+
xfree(data$.test)
|
22
|
+
end
|
23
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class RaiseTester
|
2
2
|
def test_raise(switch)
|
3
3
|
if switch
|
4
|
-
raise
|
4
|
+
raise(ArgumentError, "You raised an ArgumentError!")
|
5
5
|
else
|
6
6
|
raise(NoMethodError, "You raised an NoMethodError!")
|
7
7
|
end
|
@@ -10,4 +10,4 @@ class RaiseTester
|
|
10
10
|
def test_raise1
|
11
11
|
raise
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
@@ -5,7 +5,7 @@ def static_array
|
|
5
5
|
i32 e[size]
|
6
6
|
|
7
7
|
a[2] = 443
|
8
|
-
print
|
8
|
+
print(a[2])
|
9
9
|
|
10
10
|
if a[2] == 443
|
11
11
|
b[4] = 123
|
@@ -13,8 +13,8 @@ def static_array
|
|
13
13
|
|
14
14
|
e[53] = 4311
|
15
15
|
|
16
|
-
print
|
17
|
-
print
|
16
|
+
print(e[53])
|
17
|
+
print(b[4])
|
18
18
|
|
19
19
|
return b[4]
|
20
20
|
end
|
@@ -4,8 +4,8 @@ def strings
|
|
4
4
|
int a = 4
|
5
5
|
float b = 5.6
|
6
6
|
|
7
|
-
print
|
8
|
-
print
|
7
|
+
print("The number a is : #{a}\nThe number b is: #{b}.\n Their sum is #{a+b}.")
|
8
|
+
print("a - b :", a - b, " a * b : ", a * b, " a + b * a : ", a + b * a)
|
9
9
|
|
10
10
|
return obj
|
11
11
|
end
|
@@ -13,3 +13,13 @@ end
|
|
13
13
|
def string_ret
|
14
14
|
return "This is a returned string."
|
15
15
|
end
|
16
|
+
|
17
|
+
def char_literal
|
18
|
+
char *s = "hello world"
|
19
|
+
|
20
|
+
if (s[0] == 'h')
|
21
|
+
return true
|
22
|
+
else
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
end
|
@@ -14,13 +14,13 @@ 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
26
|
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
@@ -14,13 +14,13 @@ 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 code" 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
26
|
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = "instance_variables"
|
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
|
+
expect(Test.new("hello", " ruby").addition).to eq("hello ruby")
|
28
|
+
expect(ToChar.new("hello").bar).to eq("hello")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/loops_spec.rb
CHANGED
@@ -14,13 +14,13 @@ 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
26
|
require_relative "#{dir}/#{test_case}.#{os_extension}"
|