rubex 0.0.1 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.travis.yml +14 -0
- data/CONTRIBUTING.md +101 -0
- data/HISTORY.md +3 -0
- data/README.md +112 -297
- data/REFERENCE.md +753 -0
- data/Rakefile +4 -1
- data/TUTORIAL.md +234 -0
- data/bin/rubex +1 -1
- data/docs/_config.yml +1 -0
- data/docs/index.html +1 -0
- data/examples/c_struct_interface/c_struct_interface.rb +6 -0
- data/examples/c_struct_interface/c_struct_interface.rubex +47 -0
- data/examples/linked_list/linked_list.rubex +39 -0
- data/examples/linked_list/rb_linked_list.rb +8 -0
- data/examples/rcsv wrapper/rcsv/README.md +1 -0
- data/examples/rcsv wrapper/rcsv/Rakefile +7 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/extconf.rb +3 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/rcsv.c +302 -0
- data/examples/rcsv wrapper/rcsv/ext/rcsv/rcsv.rubex +124 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv.rb +8 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv.so +0 -0
- data/examples/rcsv wrapper/rcsv/lib/rcsv/version.rb +1 -0
- data/examples/rcsv wrapper/rcsv/rcsv.gemspec +27 -0
- data/examples/rcsv wrapper/rcsv/spec/rcsv.csv +5 -0
- data/examples/rcsv wrapper/rcsv/spec/rcsv_spec.rb +17 -0
- data/examples/rcsv wrapper/rcsv/spec/spec_helper.rb +6 -0
- data/{spec/fixtures/basic_ruby_method/Makefile → examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/Makefile } +20 -20
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/rcsv.o +0 -0
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/rcsv/2.3.3/rcsv.so +0 -0
- data/examples/rcsv wrapper/rcsv/tmp/x86_64-linux/stage/lib/rcsv.so +0 -0
- data/lib/rubex.rb +6 -50
- data/lib/rubex/ast.rb +1 -3
- data/lib/rubex/ast/expression.rb +1257 -8
- data/lib/rubex/ast/node.rb +226 -28
- data/lib/rubex/ast/statement.rb +1162 -35
- data/lib/rubex/ast/top_statement.rb +815 -0
- data/lib/rubex/code_writer.rb +103 -26
- data/lib/rubex/compiler.rb +72 -0
- data/lib/rubex/compiler_config.rb +19 -0
- data/lib/rubex/constants.rb +145 -8
- data/lib/rubex/data_type.rb +667 -4
- data/lib/rubex/error.rb +15 -0
- data/lib/rubex/helpers.rb +154 -0
- data/lib/rubex/lexer.rex +186 -22
- data/lib/rubex/lexer.rex.rb +261 -35
- data/lib/rubex/parser.racc +876 -28
- data/lib/rubex/parser.racc.rb +2845 -90
- data/lib/rubex/rake_task.rb +34 -0
- data/lib/rubex/symbol_table/entry.rb +17 -3
- data/lib/rubex/symbol_table/scope.rb +298 -25
- data/lib/rubex/version.rb +1 -1
- data/rubex.gemspec +11 -3
- data/spec/basic_ruby_method_spec.rb +15 -21
- data/spec/binding_ptr_args_spec.rb +33 -0
- data/spec/bitwise_operators_spec.rb +40 -0
- data/spec/blocks_spec.rb +35 -0
- data/spec/c_bindings_spec.rb +36 -0
- data/spec/c_constants_spec.rb +33 -0
- data/spec/c_function_ptrs_spec.rb +38 -0
- data/spec/c_functions_spec.rb +35 -0
- data/spec/c_struct_interface_spec.rb +38 -0
- data/spec/call_by_reference_spec.rb +33 -0
- data/spec/class_methods_spec.rb +33 -0
- data/spec/class_spec.rb +40 -0
- data/spec/comments_spec.rb +33 -0
- data/spec/default_args_spec.rb +37 -0
- data/spec/error_handling_spec.rb +42 -0
- data/spec/examples_spec.rb +52 -0
- data/spec/expressions_spec.rb +33 -0
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.rubex +2 -0
- data/spec/fixtures/binding_ptr_args/binding_ptr_args.rubex +30 -0
- data/spec/fixtures/bitwise_operators/bitwise_operators.rubex +40 -0
- data/spec/fixtures/blocks/blocks.rubex +11 -0
- data/spec/fixtures/c_bindings/c_bindings.rubex +58 -0
- data/spec/fixtures/c_constants/c_constants.rubex +7 -0
- data/spec/fixtures/c_function_ptrs/c_function_ptrs.rubex +52 -0
- data/spec/fixtures/c_functions/c_functions.rubex +25 -0
- data/spec/fixtures/c_struct_interface/c_struct_interface.rubex +34 -0
- data/spec/fixtures/call_by_reference/call_by_reference.rubex +30 -0
- data/spec/fixtures/class/class.rubex +20 -0
- data/spec/fixtures/class_methods/class_methods.rubex +12 -0
- data/spec/fixtures/comments/comments.rubex +9 -0
- data/spec/fixtures/default_args/default_args.rubex +11 -0
- data/spec/fixtures/error_handling/error_handling.rubex +54 -0
- data/spec/fixtures/examples/array_to_hash.rubex +14 -0
- data/spec/fixtures/examples/rcsv.csv +5 -0
- data/spec/fixtures/examples/rcsv.rubex +329 -0
- data/spec/fixtures/expressions/expressions.rubex +10 -0
- data/spec/fixtures/if_else/if_else.rubex +77 -0
- data/spec/fixtures/implicit_lib_include/implicit_lib_include.rubex +15 -0
- data/spec/fixtures/init_ruby_objects_with_literal_syntax/init_ruby_objects_with_literal_syntax.rubex +17 -0
- data/spec/fixtures/loops/loops.rubex +33 -0
- data/spec/fixtures/recursion/recursion.rubex +9 -0
- data/spec/fixtures/ruby_constant_method_calls/ruby_constant_method_calls.rubex +17 -0
- data/spec/fixtures/ruby_operators/ruby_operators.rubex +29 -0
- data/spec/fixtures/ruby_raise/ruby_raise.rubex +13 -0
- data/spec/fixtures/ruby_strings/ruby_strings.rubex +19 -0
- data/spec/fixtures/ruby_strings/string_blank_bm.rb +37 -0
- data/spec/fixtures/ruby_symbols/ruby_symbols.rubex +12 -0
- data/spec/fixtures/ruby_types/ruby_types.rubex +15 -0
- data/spec/fixtures/statement_expression/statement_expression.rubex +23 -0
- data/spec/fixtures/static_array/static_array.rubex +20 -0
- data/spec/fixtures/string_literals/string_literals.rubex +15 -0
- data/spec/fixtures/struct/struct.rubex +82 -0
- data/spec/fixtures/typecasting/typecasting.rubex +23 -0
- data/spec/fixtures/var_declarations/var_declarations.rubex +39 -0
- data/spec/if_else_spec.rb +39 -0
- data/spec/implicit_lib_include_spec.rb +33 -0
- data/spec/init_ruby_objects_with_literal_syntax_spec.rb +39 -0
- data/spec/loops_spec.rb +34 -0
- data/spec/recursion_spec.rb +35 -0
- data/spec/ruby_constant_method_calls_spec.rb +35 -0
- data/spec/ruby_operators_spec.rb +40 -0
- data/spec/ruby_raise_spec.rb +35 -0
- data/spec/ruby_strings_spec.rb +33 -0
- data/spec/ruby_symbols_spec.rb +37 -0
- data/spec/ruby_types_spec.rb +35 -0
- data/spec/spec_helper.rb +54 -1
- data/spec/statement_expression_spec.rb +34 -0
- data/spec/static_array_spec.rb +33 -0
- data/spec/string_literals_spec.rb +34 -0
- data/spec/struct_spec.rb +36 -0
- data/spec/typecasting_spec.rb +38 -0
- data/spec/var_declarions_spec.rb +35 -0
- metadata +255 -29
- data/lib/rubex/ast/argument_list.rb +0 -20
- data/lib/rubex/ast/c_base_type.rb +0 -11
- data/lib/rubex/ast/ruby_method_def.rb +0 -84
- data/spec/fixtures/basic_ruby_method/basic.rb +0 -3
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.c +0 -16
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.o +0 -0
- data/spec/fixtures/basic_ruby_method/basic_ruby_method.so +0 -0
- data/spec/fixtures/basic_ruby_method/extconf.rb +0 -3
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = "comments"
|
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 "generate the AST." do
|
13
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".compile" do
|
18
|
+
it "compiles to C." 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}.so"
|
27
|
+
|
28
|
+
expect(crazy_comment).to eq(4)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
pending("implement default args") do
|
5
|
+
test_case = "default_args"
|
6
|
+
|
7
|
+
context "Case: #{test_case}" do
|
8
|
+
before do
|
9
|
+
@path = path_str test_case
|
10
|
+
end
|
11
|
+
|
12
|
+
context ".ast" do
|
13
|
+
it "generates a valid AST" do
|
14
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context ".compile", focus: true do
|
19
|
+
it "compiles to valid C code" do
|
20
|
+
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Black Box testing", focus: true 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
|
+
o = { a: "world!!" }
|
29
|
+
expect(default_method(1)).to eq(nil)
|
30
|
+
expect(default_method(1, true, o)).to eq(7)
|
31
|
+
expect(default_method(1, nil, {a: 44})).to eq(5)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = "error_handling"
|
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", focus: true 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", focus: true 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}.so"
|
27
|
+
|
28
|
+
cls = Handler.new
|
29
|
+
|
30
|
+
expect(cls.error_test(1)).to eq(6)
|
31
|
+
expect(cls.error_test(2)).to eq(7)
|
32
|
+
expect(cls.error_test(3)).to eq(8)
|
33
|
+
expect(cls.error_test(4)).to eq(9)
|
34
|
+
|
35
|
+
expect {cls.test_uncaught_error}.to raise_error(ArgumentError)
|
36
|
+
expect(cls.test_without_rescue).to eq(1)
|
37
|
+
expect(cls.test_decl_inside_begin).to eq(44)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = 'examples'
|
5
|
+
|
6
|
+
examples = ['rcsv', 'array_to_hash'].each do |example|
|
7
|
+
context "Case: #{test_case}/#{example}" do
|
8
|
+
before do
|
9
|
+
@path = path_str test_case, example
|
10
|
+
end
|
11
|
+
|
12
|
+
context ".ast" do
|
13
|
+
it "generates the AST" do
|
14
|
+
t = Rubex::Compiler.ast(@path + '.rubex')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context ".compile", now: true do
|
19
|
+
it "compiles to valid C file" do
|
20
|
+
t,c,e = Rubex::Compiler.compile(@path + '.rubex', test: true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Black Box testing", now: true do
|
25
|
+
it "compiles and checks for valid output" do
|
26
|
+
def rcsv
|
27
|
+
result = [
|
28
|
+
["Name", "age", "sex"],
|
29
|
+
["Sameer", "24", "M"],
|
30
|
+
["Ameya", "23", "M"],
|
31
|
+
["Neeraja", "23", "F"],
|
32
|
+
["Shounak", "24", "M"]
|
33
|
+
]
|
34
|
+
|
35
|
+
a = Rcsv.parse(File.read('spec/fixtures/examples/rcsv.csv'), {})
|
36
|
+
expect(a).to eq(result)
|
37
|
+
end
|
38
|
+
|
39
|
+
def array_to_hash
|
40
|
+
a = ["a", "b", "c"]
|
41
|
+
expect(a.each_with_index.to_h).to eq(Array2Hash.convert(a))
|
42
|
+
end
|
43
|
+
|
44
|
+
setup_and_teardown_compiled_files(test_case, example) do |dir|
|
45
|
+
require_relative "#{dir}/#{example}.so"
|
46
|
+
self.send(example.to_sym)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = "expressions"
|
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}.so"
|
27
|
+
|
28
|
+
expect(adder(1,3.4)).to eq(-548)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
lib "<ruby/encoding.h>"
|
2
|
+
struct rb_encoding
|
3
|
+
|
4
|
+
end
|
5
|
+
|
6
|
+
alias rb_encoding = struct rb_encoding
|
7
|
+
|
8
|
+
rb_encoding *rb_enc_from_index(int)
|
9
|
+
unsigned int rb_enc_codepoint(char *, char *, rb_encoding *)
|
10
|
+
int ENCODING_GET(object)
|
11
|
+
end
|
12
|
+
|
13
|
+
lib "<ruby.h>"
|
14
|
+
char* RSTRING_PTR(object)
|
15
|
+
char* RSTRING_END(object)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_function(string)
|
19
|
+
rb_encoding *enc
|
20
|
+
unsigned int cc
|
21
|
+
char* s
|
22
|
+
char* e
|
23
|
+
|
24
|
+
s = RSTRING_PTR(string)
|
25
|
+
e = RSTRING_END(string)
|
26
|
+
enc = rb_enc_from_index(ENCODING_GET(string))
|
27
|
+
cc = rb_enc_codepoint(s, e, enc)
|
28
|
+
|
29
|
+
return cc
|
30
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class BitWise
|
2
|
+
def wise_or
|
3
|
+
int a = 1
|
4
|
+
int b = 3
|
5
|
+
|
6
|
+
return a | b
|
7
|
+
end
|
8
|
+
|
9
|
+
def wise_and
|
10
|
+
int a = 1
|
11
|
+
char b = 5
|
12
|
+
|
13
|
+
return a & b
|
14
|
+
end
|
15
|
+
|
16
|
+
def wise_xor
|
17
|
+
int a = 4
|
18
|
+
int b = 4
|
19
|
+
|
20
|
+
return a ^ b
|
21
|
+
end
|
22
|
+
|
23
|
+
def wise_compli
|
24
|
+
int a = 4
|
25
|
+
|
26
|
+
return ~a
|
27
|
+
end
|
28
|
+
|
29
|
+
def wise_lshift
|
30
|
+
int a = 3
|
31
|
+
|
32
|
+
return a << 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def wise_rshift
|
36
|
+
int a = 4
|
37
|
+
|
38
|
+
return a >> 1
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
lib "<math.h>"
|
2
|
+
double cos(double a)
|
3
|
+
|
4
|
+
struct exception
|
5
|
+
int type
|
6
|
+
char *name
|
7
|
+
end
|
8
|
+
|
9
|
+
double pow(double, double)
|
10
|
+
|
11
|
+
alias exec = struct exception
|
12
|
+
end
|
13
|
+
|
14
|
+
lib "<math.h>"
|
15
|
+
double sin(double)
|
16
|
+
end
|
17
|
+
|
18
|
+
class RMath
|
19
|
+
def ruby_sin(double x)
|
20
|
+
return sin(x)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def maths(double a, double b, c)
|
25
|
+
alias int_64 = i64
|
26
|
+
int_64 p = cos(a)
|
27
|
+
int_64 rr
|
28
|
+
|
29
|
+
rr = 332
|
30
|
+
|
31
|
+
exec e
|
32
|
+
e.type = 3
|
33
|
+
|
34
|
+
struct new_struct
|
35
|
+
double a,b,c
|
36
|
+
char* string
|
37
|
+
end
|
38
|
+
|
39
|
+
new_struct s
|
40
|
+
s.a = a
|
41
|
+
s.b = b
|
42
|
+
|
43
|
+
if (s.a > s.b)
|
44
|
+
s.string = c
|
45
|
+
end
|
46
|
+
|
47
|
+
return pow(6.7, s.a)
|
48
|
+
end
|
49
|
+
|
50
|
+
def stray_cos
|
51
|
+
return cos(4.5)
|
52
|
+
end
|
53
|
+
|
54
|
+
class A
|
55
|
+
def ruby_cos
|
56
|
+
return cos(4.5)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
cfunc int foo1(int a)
|
2
|
+
return a + 1
|
3
|
+
end
|
4
|
+
|
5
|
+
cfunc int foo2(int a)
|
6
|
+
return a + 2
|
7
|
+
end
|
8
|
+
|
9
|
+
cfunc int baz1(int a, int b)
|
10
|
+
return a + b + 1
|
11
|
+
end
|
12
|
+
|
13
|
+
cfunc int baz2(int a, int b)
|
14
|
+
return a + b + 2
|
15
|
+
end
|
16
|
+
|
17
|
+
cfunc int bar(int (*func1)(int), int (*func2)(int, int), int a, int b)
|
18
|
+
int ans1
|
19
|
+
int ans2
|
20
|
+
|
21
|
+
ans1 = func1(a)
|
22
|
+
ans2 = func2(a, b)
|
23
|
+
|
24
|
+
return ans1 + ans2
|
25
|
+
end
|
26
|
+
|
27
|
+
class CFunctionPtrs
|
28
|
+
def test_c_function_pointers(switch)
|
29
|
+
alias goswim = int (*ernub)(int, int)
|
30
|
+
int (*func_ptr1)(int)
|
31
|
+
goswim func_ptr2
|
32
|
+
int a = 1
|
33
|
+
int b = 1
|
34
|
+
|
35
|
+
if switch
|
36
|
+
func_ptr1 = foo1
|
37
|
+
func_ptr2 = baz1
|
38
|
+
else
|
39
|
+
func_ptr1 = foo2
|
40
|
+
func_ptr2 = baz2
|
41
|
+
end
|
42
|
+
|
43
|
+
return bar(func_ptr1, func_ptr2, a, b)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_pass_by_name
|
47
|
+
int a = 5
|
48
|
+
int b = 5
|
49
|
+
|
50
|
+
return bar(&foo1, &baz1, a, b)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
cfunc object this_is_it
|
2
|
+
return "this is it."
|
3
|
+
end
|
4
|
+
|
5
|
+
class CFunctions
|
6
|
+
def pure_ruby_method
|
7
|
+
int a = 55
|
8
|
+
float b = 5.43
|
9
|
+
int c = first_c_function(a, b)
|
10
|
+
d = this_is_it
|
11
|
+
|
12
|
+
return a + c
|
13
|
+
end
|
14
|
+
|
15
|
+
cfunc int first_c_function(int a, float b)
|
16
|
+
int c = a + 5
|
17
|
+
int d = (c * b + 3)/5
|
18
|
+
|
19
|
+
return c - d
|
20
|
+
end
|
21
|
+
|
22
|
+
cfunc int empty
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
lib "rubex/ruby"; end
|
2
|
+
|
3
|
+
struct mp3info
|
4
|
+
char *artist, *title
|
5
|
+
int id
|
6
|
+
end
|
7
|
+
|
8
|
+
class Music attach mp3info
|
9
|
+
def initialize(artist, title, id)
|
10
|
+
mp3info* mp3 = data$.mp3info
|
11
|
+
int a_size = artist.size
|
12
|
+
int t_size = title.size
|
13
|
+
|
14
|
+
mp3.artist = artist # implicit conversion of Ruby String to char*
|
15
|
+
mp3.title = title # implicit conversion of Ruby String to char*
|
16
|
+
mp3.id = id # implicit typecast to int
|
17
|
+
end
|
18
|
+
|
19
|
+
cfunc void deallocate
|
20
|
+
xfree(data$.mp3info)
|
21
|
+
end
|
22
|
+
|
23
|
+
def artist
|
24
|
+
return data$.mp3info.artist # typecast to ruby string
|
25
|
+
end
|
26
|
+
|
27
|
+
def title
|
28
|
+
return data$.mp3info.title # typecast to ruby string
|
29
|
+
end
|
30
|
+
|
31
|
+
def id
|
32
|
+
return data$.mp3info.id
|
33
|
+
end
|
34
|
+
end
|