rubex 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/rubex/rake_task.rb
CHANGED
@@ -5,30 +5,66 @@ require_relative '../rubex.rb'
|
|
5
5
|
|
6
6
|
module Rubex
|
7
7
|
class RakeTask < ::Rake::TaskLib
|
8
|
+
attr_reader :ext_dir, :rubex_files
|
9
|
+
attr_accessor :debug
|
8
10
|
|
9
|
-
def initialize name, gem_spec=nil
|
11
|
+
def initialize name, gem_spec=nil, &block
|
10
12
|
@name = name
|
11
13
|
@gem_spec = gem_spec
|
12
|
-
@ext_dir = "ext/#{@name}"
|
14
|
+
@ext_dir = "#{Dir.pwd}/ext/#{@name}"
|
13
15
|
@lib_dir = 'lib'
|
14
16
|
@source_pattern = "*.rubex"
|
15
17
|
@compiled_pattern = "*.c"
|
16
18
|
@config_script = "extconf.rb"
|
19
|
+
@debug = true
|
20
|
+
instance_eval(&block) if block_given?
|
17
21
|
define_compile_tasks
|
18
22
|
end
|
19
23
|
|
24
|
+
# Change the directory that contains rubex files. Overrides default
|
25
|
+
# assumption of gem file structure.
|
26
|
+
#
|
27
|
+
# @param [String] ext_dir Path to new ext dir.
|
28
|
+
def ext ext_dir
|
29
|
+
@ext_dir = ext_dir
|
30
|
+
end
|
31
|
+
|
32
|
+
# Specify the names of Rubex files with respect to ext directory if compiling
|
33
|
+
# multiple files.
|
34
|
+
#
|
35
|
+
# @param [Array[String]] files Array containing names of all files relative to
|
36
|
+
# ext directory as Strings.
|
37
|
+
def files files
|
38
|
+
@rubex_files = files
|
39
|
+
end
|
40
|
+
|
20
41
|
def define_compile_tasks
|
21
42
|
namespace :rubex do
|
22
43
|
desc "Compile a Rubex file into a shared object."
|
23
44
|
task :compile do
|
24
|
-
file_name = "#{
|
25
|
-
Rubex::Compiler.compile file_name,
|
45
|
+
file_name = "#{@ext_dir}/#{@name}#{@source_pattern[1..-1]}"
|
46
|
+
Rubex::Compiler.compile file_name, target_dir: "#{@ext_dir}", debug: @debug
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Delete all generated files."
|
50
|
+
task :clobber do
|
51
|
+
path = @ext_dir
|
52
|
+
unless path.end_with?(@name)
|
53
|
+
path += "/#{@name}"
|
54
|
+
end
|
55
|
+
|
56
|
+
Dir.chdir(path) do
|
57
|
+
FileUtils.rm(
|
58
|
+
Dir.glob(
|
59
|
+
"#{path}/*.{c,h,so,o,bundle,dll}") + ["Makefile", "extconf.rb"], force: true
|
60
|
+
)
|
61
|
+
end
|
26
62
|
end
|
27
63
|
end
|
28
64
|
Rake::ExtensionTask.new(@name)
|
29
65
|
|
30
66
|
desc "Compile Rubex code into a .so file for use in Ruby scripts."
|
31
|
-
task
|
67
|
+
task "compile" => "rubex:compile"
|
32
68
|
end
|
33
69
|
end # class RakeTask
|
34
|
-
end # module Rubex
|
70
|
+
end # module Rubex
|
@@ -13,9 +13,15 @@ module Rubex
|
|
13
13
|
attr_accessor :extern
|
14
14
|
# Is a Ruby singleton method
|
15
15
|
attr_accessor :singleton
|
16
|
+
# Number of times this entry is called in a function. Useful for Ruby methods.
|
17
|
+
attr_accessor :times_called
|
18
|
+
# Whether this entry has a no_gil tag or not. Applicable for C functions.
|
19
|
+
attr_accessor :no_gil
|
16
20
|
|
17
21
|
def initialize name, c_name, type, value
|
18
22
|
@name, @c_name, @type, @value = name, c_name, type, value
|
23
|
+
@times_called = 0
|
24
|
+
@no_gil = false
|
19
25
|
end
|
20
26
|
|
21
27
|
def c_code local_scope
|
@@ -191,7 +191,11 @@ module Rubex
|
|
191
191
|
class Klass
|
192
192
|
include Rubex::SymbolTable::Scope
|
193
193
|
attr_accessor :include_files #TODO: this should probably not be here.
|
194
|
+
# Stores callbacks for begin blocks since they cannot be a part of the
|
195
|
+
# statements of a class.
|
194
196
|
attr_accessor :begin_block_callbacks
|
197
|
+
# Similar to begin_block_callbacks
|
198
|
+
attr_accessor :no_gil_block_callbacks
|
195
199
|
|
196
200
|
def initialize name, outer_scope
|
197
201
|
super(outer_scope)
|
@@ -199,6 +203,7 @@ module Rubex
|
|
199
203
|
@klass_name = @name
|
200
204
|
@include_files = []
|
201
205
|
@begin_block_callbacks = []
|
206
|
+
@no_gil_block_callbacks = []
|
202
207
|
end
|
203
208
|
|
204
209
|
def object_scope
|
@@ -214,17 +219,24 @@ module Rubex
|
|
214
219
|
def add_begin_block_callback func
|
215
220
|
@begin_block_callbacks << func
|
216
221
|
end
|
222
|
+
|
223
|
+
# Stores CFunctionDef nodes that represent no_gil block callbacks.
|
224
|
+
def add_no_gil_block_callback func
|
225
|
+
@no_gil_block_callbacks << func
|
226
|
+
end
|
217
227
|
end # class Klass
|
218
228
|
|
219
229
|
class Local
|
220
230
|
include Rubex::SymbolTable::Scope
|
221
|
-
attr_reader :begin_block_counter
|
231
|
+
attr_reader :begin_block_counter,
|
232
|
+
:no_gil_block_counter
|
222
233
|
|
223
234
|
def initialize name, outer_scope
|
224
235
|
super(outer_scope)
|
225
236
|
@name = name
|
226
237
|
@klass_name = outer_scope.klass_name
|
227
238
|
@begin_block_counter = 0
|
239
|
+
@no_gil_block_counter = 0
|
228
240
|
end
|
229
241
|
|
230
242
|
# args - Rubex::AST::ArgumentList. Creates sym. table entries for args.
|
@@ -240,6 +252,10 @@ module Rubex
|
|
240
252
|
def found_begin_block
|
241
253
|
@begin_block_counter += 1
|
242
254
|
end
|
255
|
+
|
256
|
+
def found_no_gil_block
|
257
|
+
@no_gil_block_counter += 1
|
258
|
+
end
|
243
259
|
end # class Local
|
244
260
|
|
245
261
|
class BeginBlock
|
@@ -254,11 +270,14 @@ module Rubex
|
|
254
270
|
def upgrade_symbols_to_global
|
255
271
|
@block_entries.uniq!
|
256
272
|
@block_entries.each do |entry|
|
257
|
-
entry.c_name = Rubex::GLOBAL_PREFIX + @name + entry.c_name
|
258
273
|
@outer_scope.global_entries << entry
|
259
274
|
end
|
260
275
|
|
261
276
|
remove_global_from_local_entries
|
277
|
+
|
278
|
+
@outer_scope.global_entries.each do |entry|
|
279
|
+
entry.c_name = Rubex::GLOBAL_PREFIX + @name + entry.c_name
|
280
|
+
end
|
262
281
|
end
|
263
282
|
|
264
283
|
# IMPORTANT NOTE TO PROGRAMMER:
|
@@ -268,6 +287,10 @@ module Rubex
|
|
268
287
|
# C, the begin block must be put inside its own C function, which is then
|
269
288
|
# sent as a callback to rb_protect().
|
270
289
|
#
|
290
|
+
# The same as above applies to a no_gil block, which is why the NoGilBlock
|
291
|
+
# (defined below) inherits from this class and completely imitates its
|
292
|
+
# behaviour.
|
293
|
+
#
|
271
294
|
# As a result, it is necesary to 'upgrade' the local variables present
|
272
295
|
# inside the begin block to C global variables so that they can be shared
|
273
296
|
# between the callback C function encapsulating the begin block and the
|
@@ -286,7 +309,7 @@ module Rubex
|
|
286
309
|
# of @outer_scope get carried forward into this begin block callback.
|
287
310
|
# Therefore these variables get declared inside the begin block callback
|
288
311
|
# as well. So whenever one of these Arrays is called for this particular
|
289
|
-
# scope, we
|
312
|
+
# scope, we preturn an empty array so that nothing gets declared.
|
290
313
|
def method_missing meth, *args, &block
|
291
314
|
return [] if meth == :var_entries
|
292
315
|
ret = @outer_scope.send(meth, *args, &block)
|
@@ -315,6 +338,8 @@ module Rubex
|
|
315
338
|
end
|
316
339
|
end # class BeginBlock
|
317
340
|
|
341
|
+
class NoGilBlock < BeginBlock; end
|
342
|
+
|
318
343
|
class StructOrUnion
|
319
344
|
include Rubex::SymbolTable::Scope
|
320
345
|
# FIXME: Change scope structure to identify struct scopes by name too.
|
data/lib/rubex/version.rb
CHANGED
data/rubex.gemspec
CHANGED
@@ -15,9 +15,9 @@ describe Rubex do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context ".compile" do
|
18
|
+
context ".compile", tit: true do
|
19
19
|
it "generates valid C code" do
|
20
|
-
t, c, e = Rubex::Compiler.compile @path + ".rubex", test: true
|
20
|
+
t, c, e, h = Rubex::Compiler.compile @path + ".rubex", test: true
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
data/spec/blocks_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}"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rubex do
|
4
|
+
test_case = "box_op_multi_args"
|
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
|
+
require 'numo/narray'
|
28
|
+
n = Numo::DFloat.new(3,3).seq
|
29
|
+
expect(multi_arg_box(n)).to eq(4.0)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -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 "generates valid C code" 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
|
setup_and_teardown_compiled_files(test_case) do |dir|
|
27
27
|
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
data/spec/c_functions_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 "generates valid C code" do
|
20
|
-
t, c, e = Rubex::Compiler.compile @path + ".rubex", test: true
|
20
|
+
t, c, e, h = 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
|
setup_and_teardown_compiled_files(test_case) do |dir|
|
27
27
|
require_relative "#{dir}/#{test_case}.#{os_extension}"
|
@@ -31,6 +31,11 @@ describe Rubex do
|
|
31
31
|
expect(m.artist).to eq("Animals as Leaders")
|
32
32
|
expect(m.title) .to eq("CAFO")
|
33
33
|
expect(m.id) .to eq(id)
|
34
|
+
expect(m.id_i) .to eq(id + 1)
|
35
|
+
|
36
|
+
t = A.new
|
37
|
+
|
38
|
+
expect(t.foo).to eq(55)
|
34
39
|
end
|
35
40
|
end
|
36
41
|
end
|
data/spec/default_args_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
|
skip '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
|
skip '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 = 'external_c_struct'
|
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(HelloFile.new.foo).to eq(false)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -23,3 +23,16 @@ class CFunctions
|
|
23
23
|
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
# Try to typecast ruby object to target type when sending to function with a
|
28
|
+
# given type.
|
29
|
+
class TypeCast
|
30
|
+
cfunc int bar(char * s, int a, int b)
|
31
|
+
return a + b
|
32
|
+
end
|
33
|
+
|
34
|
+
def foo(i, j)
|
35
|
+
s = "hello world!"
|
36
|
+
return bar(s,i,j)
|
37
|
+
end
|
38
|
+
end
|
@@ -31,4 +31,32 @@ class Music attach mp3info
|
|
31
31
|
def id
|
32
32
|
return data$.mp3info.id
|
33
33
|
end
|
34
|
+
|
35
|
+
cfunc int inc_id
|
36
|
+
return (data$.mp3info.id + 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
def id_i
|
40
|
+
inc_id()
|
41
|
+
return inc_id()
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
struct test
|
46
|
+
int *a
|
47
|
+
end
|
48
|
+
|
49
|
+
class A attach test
|
50
|
+
cfunc object allocate
|
51
|
+
data$.test.a = <int*>xmalloc(sizeof(int)*100)
|
52
|
+
end
|
53
|
+
|
54
|
+
def foo
|
55
|
+
data$.test.a[3] = 55
|
56
|
+
return data$.test.a[3]
|
57
|
+
end
|
58
|
+
|
59
|
+
cfunc void deallocate
|
60
|
+
xfree(data$.test.a)
|
61
|
+
end
|
34
62
|
end
|
@@ -24,7 +24,7 @@ class Handler
|
|
24
24
|
|
25
25
|
def test_uncaught_error
|
26
26
|
begin
|
27
|
-
raise
|
27
|
+
raise(ArgumentError)
|
28
28
|
rescue SyntaxError
|
29
29
|
end
|
30
30
|
end
|
@@ -32,7 +32,7 @@ class Handler
|
|
32
32
|
def test_without_rescue
|
33
33
|
int i = 1
|
34
34
|
begin
|
35
|
-
raise
|
35
|
+
raise(ArgumentError)
|
36
36
|
ensure
|
37
37
|
return i
|
38
38
|
end
|