fastruby 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/Rakefile +1 -1
- data/lib/fastruby/translator/call.rb +2594 -0
- data/lib/fastruby/translator/iter.rb +2594 -0
- data/lib/fastruby/translator.rb +91 -43
- data/lib/fastruby.rb +1 -1
- data/spec/exception/exc_trap_spec.rb +0 -2
- data/spec/exception/internal_ex_spec.rb +86 -0
- data/spec/exception/syntaxis_spec.rb +77 -3
- metadata +7 -4
data/lib/fastruby/translator.rb
CHANGED
@@ -727,7 +727,7 @@ module FastRuby
|
|
727
727
|
plocals = (void*)pframe->plocals;
|
728
728
|
|
729
729
|
if (FIX2LONG(plocals->block_function_address) == 0) {
|
730
|
-
|
730
|
+
#{_raise("rb_eLocalJumpError", "no block given")};
|
731
731
|
} else {
|
732
732
|
return ((VALUE(*)(int,VALUE*,VALUE,VALUE))FIX2LONG(plocals->block_function_address))(#{tree.size-1}, block_args, FIX2LONG(plocals->block_function_param), (VALUE)pframe);
|
733
733
|
}
|
@@ -808,9 +808,7 @@ module FastRuby
|
|
808
808
|
target_frame_ = (void*)FIX2LONG(plocals->call_frame);
|
809
809
|
|
810
810
|
if (target_frame_ == 0) {
|
811
|
-
|
812
|
-
longjmp(pframe->jmp,FASTRUBY_TAG_RAISE);
|
813
|
-
return Qnil;
|
811
|
+
#{_raise("rb_eLocalJumpError","illegal break")};
|
814
812
|
}
|
815
813
|
|
816
814
|
plocals->call_frame = LONG2FIX(0);
|
@@ -829,9 +827,7 @@ module FastRuby
|
|
829
827
|
target_frame_ = (void*)FIX2LONG(plocals->call_frame);
|
830
828
|
|
831
829
|
if (target_frame_ == 0) {
|
832
|
-
|
833
|
-
longjmp(pframe->jmp, FASTRUBY_TAG_RAISE);
|
834
|
-
return Qnil;
|
830
|
+
#{_raise("rb_eLocalJumpError","illegal retry")};
|
835
831
|
}
|
836
832
|
|
837
833
|
target_frame_->targetted = 1;
|
@@ -846,11 +842,7 @@ module FastRuby
|
|
846
842
|
return Qnil;
|
847
843
|
"
|
848
844
|
else
|
849
|
-
|
850
|
-
pframe->thread_data->exception = #{literal_value LocalJumpError.exception};
|
851
|
-
longjmp(pframe->jmp,FASTRUBY_TAG_RAISE);
|
852
|
-
return Qnil;
|
853
|
-
"
|
845
|
+
_raise("rb_eLocalJumpError","illegal redo");
|
854
846
|
end
|
855
847
|
end
|
856
848
|
|
@@ -862,12 +854,7 @@ module FastRuby
|
|
862
854
|
return Qnil;
|
863
855
|
"
|
864
856
|
else
|
865
|
-
|
866
|
-
pframe->thread_data->exception = #{literal_value LocalJumpError.exception};
|
867
|
-
longjmp(pframe->jmp,FASTRUBY_TAG_RAISE);
|
868
|
-
return Qnil;
|
869
|
-
")
|
870
|
-
|
857
|
+
_raise("rb_eLocalJumpError","illegal next");
|
871
858
|
end
|
872
859
|
end
|
873
860
|
|
@@ -1541,7 +1528,11 @@ module FastRuby
|
|
1541
1528
|
end
|
1542
1529
|
|
1543
1530
|
def to_c_gvar(tree)
|
1544
|
-
|
1531
|
+
if (tree[1] == :$!)
|
1532
|
+
"pframe->thread_data->exception"
|
1533
|
+
else
|
1534
|
+
"rb_gvar_get((struct global_entry*)#{global_entry(tree[1])})"
|
1535
|
+
end
|
1545
1536
|
end
|
1546
1537
|
|
1547
1538
|
def to_c_gasgn(tree)
|
@@ -1570,8 +1561,7 @@ module FastRuby
|
|
1570
1561
|
return rb_const_get_from(klass, #{intern_num tree[2]});
|
1571
1562
|
break;
|
1572
1563
|
default:
|
1573
|
-
|
1574
|
-
RSTRING(rb_obj_as_string(klass))->ptr);
|
1564
|
+
#{_raise("rb_eTypeError","not a class/module")};
|
1575
1565
|
break;
|
1576
1566
|
}
|
1577
1567
|
}
|
@@ -1589,15 +1579,17 @@ module FastRuby
|
|
1589
1579
|
if klass
|
1590
1580
|
|
1591
1581
|
verify_type_function = proc { |name| "
|
1592
|
-
static VALUE #{name}(VALUE arg) {
|
1593
|
-
if (CLASS_OF(arg)!=#{literal_value klass})
|
1582
|
+
static VALUE #{name}(VALUE arg, void* pframe ) {
|
1583
|
+
if (CLASS_OF(arg)!=#{literal_value klass}) {
|
1584
|
+
#{_raise(literal_value(FastRuby::TypeMismatchAssignmentException), "Illegal assignment at runtime (type mismatch)")};
|
1585
|
+
}
|
1594
1586
|
return arg;
|
1595
1587
|
}
|
1596
1588
|
"
|
1597
1589
|
}
|
1598
1590
|
|
1599
1591
|
|
1600
|
-
"_lvar_assing(&#{locals_accessor}#{tree[1]}, #{anonymous_function(&verify_type_function)}(#{to_c tree[2]}))"
|
1592
|
+
"_lvar_assing(&#{locals_accessor}#{tree[1]}, #{anonymous_function(&verify_type_function)}(#{to_c tree[2]},pframe))"
|
1601
1593
|
else
|
1602
1594
|
"_lvar_assing(&#{locals_accessor}#{tree[1]},#{to_c tree[2]})"
|
1603
1595
|
end
|
@@ -1664,24 +1656,60 @@ module FastRuby
|
|
1664
1656
|
end
|
1665
1657
|
else
|
1666
1658
|
resbody_tree = tree[2]
|
1667
|
-
else_tree =
|
1659
|
+
else_tree = nil
|
1660
|
+
if tree[-1]
|
1661
|
+
if tree[-1][0] != :resbody
|
1662
|
+
else_tree = tree[-1]
|
1663
|
+
end
|
1664
|
+
end
|
1665
|
+
|
1666
|
+
catch_condition_array = []
|
1667
|
+
lasgn_code = ""
|
1668
|
+
resbody_code = to_c(resbody_tree[2])
|
1669
|
+
|
1670
|
+
rescue_code = ""
|
1671
|
+
|
1672
|
+
tree[1..-1].each do |resbody_tree|
|
1673
|
+
next if resbody_tree[0] != :resbody
|
1674
|
+
|
1675
|
+
if resbody_tree[1].size == 1
|
1676
|
+
resbody_tree[1][1] = [:const, :Exception]
|
1677
|
+
end
|
1678
|
+
|
1679
|
+
if resbody_tree[1].last[0] == :lasgn
|
1680
|
+
lasgn_code = to_c(resbody_tree[1].last)
|
1681
|
+
end
|
1682
|
+
|
1683
|
+
resbody_tree[1][1..-1].each do |xtree|
|
1684
|
+
if xtree[0] != :lasgn
|
1685
|
+
trapcode = "rb_eException";
|
1686
|
+
|
1687
|
+
if xtree
|
1688
|
+
trapcode = to_c(xtree)
|
1689
|
+
end
|
1690
|
+
|
1691
|
+
catch_condition_array << "(rb_obj_is_kind_of(frame.thread_data->exception,#{trapcode}) == Qtrue)"
|
1692
|
+
end
|
1693
|
+
end
|
1694
|
+
|
1695
|
+
rescue_code << "
|
1696
|
+
if (aux == FASTRUBY_TAG_RAISE) {
|
1697
|
+
if (#{catch_condition_array.join(" || ")})
|
1698
|
+
{
|
1699
|
+
// trap exception
|
1700
|
+
frame.targetted = 1;
|
1701
|
+
|
1702
|
+
#{lasgn_code};
|
1668
1703
|
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1704
|
+
#{resbody_code};
|
1705
|
+
}
|
1706
|
+
}
|
1707
|
+
"
|
1672
1708
|
end
|
1673
1709
|
|
1674
1710
|
frame_call(
|
1675
1711
|
frame(to_c(tree[1])+";","
|
1676
|
-
|
1677
|
-
if (rb_obj_is_kind_of(frame.thread_data->exception,#{trapcode}) == Qtrue)
|
1678
|
-
{
|
1679
|
-
// trap exception
|
1680
|
-
frame.targetted = 1;
|
1681
|
-
|
1682
|
-
#{to_c(resbody_tree[2])};
|
1683
|
-
}
|
1684
|
-
}
|
1712
|
+
#{rescue_code}
|
1685
1713
|
", else_tree ? to_c(else_tree) : nil, 1)
|
1686
1714
|
|
1687
1715
|
)
|
@@ -1699,6 +1727,31 @@ module FastRuby
|
|
1699
1727
|
end
|
1700
1728
|
end
|
1701
1729
|
|
1730
|
+
def _raise(class_tree, message_tree = nil)
|
1731
|
+
class_tree = to_c class_tree unless class_tree.instance_of? String
|
1732
|
+
|
1733
|
+
if message_tree.instance_of? String
|
1734
|
+
message_tree = "rb_str_new2(#{message_tree.inspect})"
|
1735
|
+
else
|
1736
|
+
message_tree = to_c message_tree
|
1737
|
+
end
|
1738
|
+
|
1739
|
+
if message_tree
|
1740
|
+
return inline_block("
|
1741
|
+
pframe->thread_data->exception = rb_funcall(#{class_tree}, #{intern_num :exception},1,#{message_tree});
|
1742
|
+
longjmp(pframe->jmp, FASTRUBY_TAG_RAISE);
|
1743
|
+
return Qnil;
|
1744
|
+
")
|
1745
|
+
else
|
1746
|
+
return inline_block("
|
1747
|
+
pframe->thread_data->exception = rb_funcall(#{class_tree}, #{intern_num :exception},0);
|
1748
|
+
longjmp(pframe->jmp, FASTRUBY_TAG_RAISE);
|
1749
|
+
return Qnil;
|
1750
|
+
")
|
1751
|
+
end
|
1752
|
+
|
1753
|
+
end
|
1754
|
+
|
1702
1755
|
def to_c_call(tree, repass_var = nil)
|
1703
1756
|
directive_code = directive(tree)
|
1704
1757
|
if directive_code
|
@@ -1710,12 +1763,7 @@ module FastRuby
|
|
1710
1763
|
elsif tree[2] == :raise
|
1711
1764
|
# raise code
|
1712
1765
|
args = tree[3]
|
1713
|
-
|
1714
|
-
return inline_block("
|
1715
|
-
pframe->thread_data->exception = rb_funcall(#{to_c args[1]}, #{intern_num :exception},0);
|
1716
|
-
longjmp(pframe->jmp, FASTRUBY_TAG_RAISE);
|
1717
|
-
return Qnil;
|
1718
|
-
")
|
1766
|
+
return _raise(args[1],args[2])
|
1719
1767
|
end
|
1720
1768
|
|
1721
1769
|
recv = tree[1]
|
data/lib/fastruby.rb
CHANGED
@@ -33,6 +33,6 @@ module FastRuby
|
|
33
33
|
FastRuby.fastruby_script_path = File.expand_path(__FILE__)
|
34
34
|
FastRuby.fastruby_load_path = File.expand_path(File.dirname(__FILE__))
|
35
35
|
|
36
|
-
VERSION = "0.0.
|
36
|
+
VERSION = "0.0.12" unless defined? FastRuby::VERSION
|
37
37
|
end
|
38
38
|
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require "fastruby"
|
2
|
+
|
3
|
+
describe FastRuby, "fastruby" do
|
4
|
+
|
5
|
+
it "should trap 'no block given" do
|
6
|
+
fastruby "
|
7
|
+
class LLJ1
|
8
|
+
attr_accessor :a
|
9
|
+
|
10
|
+
def bar
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
|
14
|
+
def foo
|
15
|
+
bar # this will raise LocalJumpError
|
16
|
+
ensure
|
17
|
+
@a = 1
|
18
|
+
end
|
19
|
+
end
|
20
|
+
"
|
21
|
+
|
22
|
+
llj1 = LLJ1.new
|
23
|
+
|
24
|
+
lambda {
|
25
|
+
llj1.foo
|
26
|
+
}.should raise_error(LocalJumpError)
|
27
|
+
|
28
|
+
llj1.a.should be == 1
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
it "should trap 'TypeError" do
|
33
|
+
fastruby "
|
34
|
+
class LLJ2
|
35
|
+
attr_accessor :a
|
36
|
+
|
37
|
+
def bar
|
38
|
+
4::X
|
39
|
+
end
|
40
|
+
|
41
|
+
def foo
|
42
|
+
bar # this will raise TypeError
|
43
|
+
ensure
|
44
|
+
@a = 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
"
|
48
|
+
|
49
|
+
llj2 = LLJ2.new
|
50
|
+
|
51
|
+
lambda {
|
52
|
+
llj2.foo
|
53
|
+
}.should raise_error(TypeError)
|
54
|
+
|
55
|
+
llj2.a.should be == 1
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should trap FastRuby::TypeMismatchAssignmentException" do
|
59
|
+
fastruby "
|
60
|
+
class LLJ3
|
61
|
+
attr_accessor :a
|
62
|
+
|
63
|
+
def bar
|
64
|
+
a = 0
|
65
|
+
lvar_type(a,Fixnum)
|
66
|
+
a = 'wrong value'
|
67
|
+
end
|
68
|
+
|
69
|
+
def foo
|
70
|
+
bar # this will raise FastRuby::TypeMismatchAssignmentException
|
71
|
+
ensure
|
72
|
+
@a = 1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
", :validate_lvar_types => true
|
76
|
+
|
77
|
+
llj3 = LLJ3.new
|
78
|
+
|
79
|
+
lambda {
|
80
|
+
llj3.foo
|
81
|
+
}.should raise_error(FastRuby::TypeMismatchAssignmentException)
|
82
|
+
|
83
|
+
llj3.a.should be == 1
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -60,9 +60,9 @@ describe FastRuby, "fastruby" do
|
|
60
60
|
end
|
61
61
|
"
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
l = eval(random_name).new
|
64
|
+
l.foo.should be == 222
|
65
|
+
end
|
66
66
|
|
67
67
|
def self.argumentless_rescue(exceptionname)
|
68
68
|
fastruby "
|
@@ -86,4 +86,78 @@ describe FastRuby, "fastruby" do
|
|
86
86
|
|
87
87
|
argumentless_rescue("RuntimeError")
|
88
88
|
|
89
|
+
it "should read exception into local" do
|
90
|
+
fastruby "
|
91
|
+
class ::LLX1
|
92
|
+
def foo
|
93
|
+
begin
|
94
|
+
raise Exception,'message'
|
95
|
+
rescue Exception => a
|
96
|
+
end
|
97
|
+
|
98
|
+
a
|
99
|
+
end
|
100
|
+
end
|
101
|
+
"
|
102
|
+
|
103
|
+
llx1 = ::LLX1.new
|
104
|
+
llx1.foo.message.should be == "message"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should read exception into local with traps of two exceptions" do
|
108
|
+
fastruby "
|
109
|
+
class ::LLX2
|
110
|
+
def foo
|
111
|
+
begin
|
112
|
+
raise RuntimeError,'message2'
|
113
|
+
rescue LocalJumpError, RuntimeError => b
|
114
|
+
end
|
115
|
+
|
116
|
+
b
|
117
|
+
end
|
118
|
+
end
|
119
|
+
"
|
120
|
+
|
121
|
+
llx2 = ::LLX2.new
|
122
|
+
llx2.foo.message.should be == "message2"
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should trap exception with multiple rescue clauses" do
|
126
|
+
fastruby "
|
127
|
+
class ::LLX3
|
128
|
+
def foo
|
129
|
+
begin
|
130
|
+
raise RuntimeError,'message2'
|
131
|
+
rescue LocalJumpError
|
132
|
+
rescue RuntimeError => b
|
133
|
+
end
|
134
|
+
|
135
|
+
b
|
136
|
+
end
|
137
|
+
end
|
138
|
+
"
|
139
|
+
|
140
|
+
llx3 = ::LLX3.new
|
141
|
+
llx3.foo.message.should be == "message2"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should trap exception with multiple rescue clauses 2" do
|
145
|
+
fastruby "
|
146
|
+
class ::LLX4
|
147
|
+
def foo
|
148
|
+
begin
|
149
|
+
raise LocalJumpError,'message2'
|
150
|
+
rescue LocalJumpError => a
|
151
|
+
rescue RuntimeError
|
152
|
+
end
|
153
|
+
|
154
|
+
a
|
155
|
+
end
|
156
|
+
end
|
157
|
+
"
|
158
|
+
|
159
|
+
llx4 = ::LLX4.new
|
160
|
+
llx4.foo.message.should be == "message2"
|
161
|
+
end
|
162
|
+
|
89
163
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 12
|
10
|
+
version: 0.0.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dario Seminara
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-06 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- lib/fastruby/sexp_extension.rb
|
80
80
|
- lib/fastruby/translator.rb
|
81
81
|
- lib/fastruby/object.rb
|
82
|
+
- lib/fastruby/translator/iter.rb
|
83
|
+
- lib/fastruby/translator/call.rb
|
82
84
|
- lib/fastruby/fastruby_sexp.rb
|
83
85
|
- lib/fastruby/method_extension.rb
|
84
86
|
- lib/fastruby/cache/cache.rb
|
@@ -100,6 +102,7 @@ files:
|
|
100
102
|
- spec/exception/syntaxis_spec.rb
|
101
103
|
- spec/exception/base_spec.rb
|
102
104
|
- spec/exception/ensure_spec.rb
|
105
|
+
- spec/exception/internal_ex_spec.rb
|
103
106
|
- spec/block_spec.rb
|
104
107
|
- spec/flow_control/case_spec.rb
|
105
108
|
- spec/flow_control/for_spec.rb
|