Skip to content

Commit aada691

Browse files
committed
added test for fixing minor bug with attached class interface for C functions
1 parent 31a5c34 commit aada691

File tree

6 files changed

+29
-4
lines changed

6 files changed

+29
-4
lines changed

lib/rubex/ast/expression/command_call/raise.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def initialize(args)
99
def analyse_types(local_scope)
1010
@args.analyse_types local_scope
1111
@args.allocate_temps local_scope
12-
@args.release_temps local_scope
1312
unless @args.empty? || @args[0].is_a?(AST::Expression::Name) ||
1413
@args[0].is_a?(AST::Expression::Literal::StringLit)
1514
raise Rubex::TypeMismatchError, "Wrong argument list #{@args.inspect} for raise."
1615
end
1716
@subexprs = [@args]
17+
@args.release_temps local_scope
1818
end
1919

2020
def generate_evaluation_code(code, local_scope)

spec/c_functions_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
c = CFunctions.new
2929
expect(c.pure_ruby_method).to eq(50)
3030
expect { c.first_c_function(1,2) }.to raise_error(NoMethodError)
31+
32+
expect(TypeCast.new.foo(5,5)).to eq(10)
3133
end
3234
end
3335
end

spec/c_struct_interface_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
end
1616
end
1717

18-
context ".compile" do
18+
context ".compile", hell: true do
1919
it "generates valid C code" do
2020
t, c, e = Rubex::Compiler.compile @path + ".rubex", test: true
21+
puts c
2122
end
2223
end
2324

24-
context "Black Box testing" do
25+
context "Black Box testing", hell: true do
2526
it "compiles and checks for valid output" do
2627
setup_and_teardown_compiled_files(test_case) do |dir|
2728
require_relative "#{dir}/#{test_case}.#{os_extension}"
@@ -31,6 +32,7 @@
3132
expect(m.artist).to eq("Animals as Leaders")
3233
expect(m.title) .to eq("CAFO")
3334
expect(m.id) .to eq(id)
35+
expect(m.id_i) .to eq(id + 1)
3436
end
3537
end
3638
end

spec/fixtures/c_functions/c_functions.rubex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,16 @@ class CFunctions
2323

2424
end
2525
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

spec/fixtures/c_struct_interface/c_struct_interface.rubex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ class Music attach mp3info
3131
def id
3232
return data$.mp3info.id
3333
end
34+
35+
cfunc int inc_id
36+
return (data$.mp3info.id + 1)
37+
end
38+
39+
def id_i
40+
return inc_id
41+
end
3442
end

spec/instance_variables_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
end
2121
end
2222

23-
context "Black box testing", hell: true do
23+
context "Black box testing" do
2424
it "compiles and checks for valid output" do
2525
setup_and_teardown_compiled_files(test_case) do |dir|
2626
require_relative "#{dir}/#{test_case}.#{os_extension}"

0 commit comments

Comments
 (0)