rubybreaker 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS +48 -0
- data/README.md +56 -20
- data/Rakefile +9 -34
- data/TODO +10 -10
- data/VERSION +1 -0
- data/bin/gen_stub_rubylib +35 -36
- data/bin/rubybreaker +1 -4
- data/lib/rubybreaker/debug.rb +8 -4
- data/lib/rubybreaker/rubylib/core.rb +738 -571
- data/lib/rubybreaker/runtime/inspector.rb +16 -7
- data/lib/rubybreaker/runtime/monitor.rb +14 -18
- data/lib/rubybreaker/runtime/object_wrapper.rb +9 -3
- data/lib/rubybreaker/runtime/overrides.rb +51 -8
- data/lib/rubybreaker/runtime/pluggable.rb +1 -3
- data/lib/rubybreaker/runtime/type_placeholder.rb +2 -6
- data/lib/rubybreaker/runtime/type_system.rb +53 -17
- data/lib/rubybreaker/runtime/typesig_parser.rb +1 -0
- data/lib/rubybreaker/runtime/util.rb +18 -0
- data/lib/rubybreaker/runtime.rb +42 -15
- data/lib/rubybreaker/type/type_comparer.rb +10 -10
- data/lib/rubybreaker/type/type_grammar.treetop +30 -21
- data/lib/rubybreaker/type/type_unparser.rb +2 -2
- data/lib/rubybreaker/typing/subtyping.rb +21 -21
- data/lib/rubybreaker/util.rb +11 -1
- data/lib/rubybreaker.rb +75 -54
- data/test/integrated/tc_class_methods.rb +35 -0
- data/test/integrated/tc_inherit_broken.rb +29 -0
- data/test/integrated/tc_method_missing.rb +1 -1
- data/test/runtime/tc_obj_wrapper.rb +104 -4
- data/test/ts_integrated.rb +2 -0
- data/test/type/tc_comparer.rb +96 -96
- data/test/type/tc_parser.rb +18 -0
- data/test/type/tc_unparser.rb +16 -0
- data/test/typing/tc_typing.rb +20 -20
- data/webpage/footer.html +1 -1
- data/webpage/header.html +7 -7
- data/webpage/index.html +65 -28
- data/webpage/rdoc/RubyBreaker/Breakable.html +280 -0
- data/webpage/rdoc/RubyBreaker/Broken/BrokenEigen.html +304 -0
- data/webpage/rdoc/RubyBreaker/Broken.html +308 -0
- data/webpage/rdoc/RubyBreaker/Context.html +421 -0
- data/webpage/rdoc/RubyBreaker/Debug.html +411 -0
- data/webpage/rdoc/RubyBreaker/Errors/InternalError.html +263 -0
- data/webpage/rdoc/RubyBreaker/Errors/InvalidSubtypeCheck.html +263 -0
- data/webpage/rdoc/RubyBreaker/Errors/InvalidTypeConstruction.html +214 -0
- data/webpage/rdoc/RubyBreaker/Errors/SubtypeFailure.html +212 -0
- data/webpage/rdoc/RubyBreaker/Errors/TypeError.html +212 -0
- data/webpage/rdoc/RubyBreaker/Errors/UserError.html +264 -0
- data/webpage/rdoc/RubyBreaker/Errors.html +209 -0
- data/webpage/rdoc/RubyBreaker/Kernel.html +259 -0
- data/webpage/rdoc/RubyBreaker/Main.html +560 -0
- data/webpage/rdoc/RubyBreaker/ObjectPosition.html +334 -0
- data/webpage/rdoc/RubyBreaker/Position.html +463 -0
- data/webpage/rdoc/RubyBreaker/RubyTypeUtils.html +308 -0
- data/webpage/rdoc/RubyBreaker/Runtime/Inspector.html +380 -0
- data/webpage/rdoc/RubyBreaker/Runtime/MethodInfo.html +324 -0
- data/webpage/rdoc/RubyBreaker/Runtime/Monitor.html +354 -0
- data/webpage/rdoc/RubyBreaker/Runtime/MonitorInstaller.html +379 -0
- data/webpage/rdoc/RubyBreaker/Runtime/MonitorSwitch.html +382 -0
- data/webpage/rdoc/RubyBreaker/Runtime/MonitorUtils.html +400 -0
- data/webpage/rdoc/RubyBreaker/Runtime/ObjectWrapper.html +411 -0
- data/webpage/rdoc/RubyBreaker/Runtime/Pluggable.html +305 -0
- data/webpage/rdoc/RubyBreaker/Runtime/TypePlaceholder.html +280 -0
- data/webpage/rdoc/RubyBreaker/Runtime/TypeSigParser.html +283 -0
- data/webpage/rdoc/RubyBreaker/Runtime/TypeSystem.html +630 -0
- data/webpage/rdoc/RubyBreaker/Runtime.html +255 -0
- data/webpage/rdoc/RubyBreaker/TestCase.html +332 -0
- data/webpage/rdoc/RubyBreaker/TypeComparer.html +304 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/AnyType.html +260 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/BlockType.html +310 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/DuckType.html +320 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/FusionType.html +323 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/MethodListType.html +281 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/MethodType.html +282 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/NilType.html +260 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/NominalType.html +282 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/OptionalType.html +281 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/OrType.html +281 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/SelfType.html +329 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/Type.html +409 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs/VarLengthType.html +282 -0
- data/webpage/rdoc/RubyBreaker/TypeDefs.html +212 -0
- data/webpage/rdoc/RubyBreaker/TypeUnparser.html +273 -0
- data/webpage/rdoc/RubyBreaker/Typing.html +305 -0
- data/webpage/rdoc/RubyBreaker/Utilities.html +294 -0
- data/webpage/rdoc/RubyBreaker.html +337 -0
- data/webpage/rdoc/created.rid +26 -0
- data/webpage/rdoc/images/add.png +0 -0
- data/webpage/rdoc/images/brick.png +0 -0
- data/webpage/rdoc/images/brick_link.png +0 -0
- data/webpage/rdoc/images/bug.png +0 -0
- data/webpage/rdoc/images/bullet_black.png +0 -0
- data/webpage/rdoc/images/bullet_toggle_minus.png +0 -0
- data/webpage/rdoc/images/bullet_toggle_plus.png +0 -0
- data/webpage/rdoc/images/date.png +0 -0
- data/webpage/rdoc/images/delete.png +0 -0
- data/webpage/rdoc/images/find.png +0 -0
- data/webpage/rdoc/images/loadingAnimation.gif +0 -0
- data/webpage/rdoc/images/macFFBgHack.png +0 -0
- data/webpage/rdoc/images/package.png +0 -0
- data/webpage/rdoc/images/page_green.png +0 -0
- data/webpage/rdoc/images/page_white_text.png +0 -0
- data/webpage/rdoc/images/page_white_width.png +0 -0
- data/webpage/rdoc/images/plugin.png +0 -0
- data/webpage/rdoc/images/ruby.png +0 -0
- data/webpage/rdoc/images/tag_blue.png +0 -0
- data/webpage/rdoc/images/tag_green.png +0 -0
- data/webpage/rdoc/images/transparent.png +0 -0
- data/webpage/rdoc/images/wrench.png +0 -0
- data/webpage/rdoc/images/wrench_orange.png +0 -0
- data/webpage/rdoc/images/zoom.png +0 -0
- data/webpage/rdoc/index.html +165 -0
- data/webpage/rdoc/js/darkfish.js +153 -0
- data/webpage/rdoc/js/jquery.js +18 -0
- data/webpage/rdoc/js/navigation.js +142 -0
- data/webpage/rdoc/js/search.js +94 -0
- data/webpage/rdoc/js/search_index.js +1 -0
- data/webpage/rdoc/js/searcher.js +228 -0
- data/webpage/rdoc/rdoc.css +543 -0
- data/webpage/rdoc/table_of_contents.html +376 -0
- data/webpage/rubybreaker.css +31 -31
- metadata +93 -6
@@ -0,0 +1,630 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
6
|
+
|
7
|
+
<title>class RubyBreaker::Runtime::TypeSystem - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<link type="text/css" media="screen" href="../../rdoc.css" rel="stylesheet">
|
10
|
+
|
11
|
+
<script type="text/javascript">
|
12
|
+
var rdoc_rel_prefix = "../../";
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
|
16
|
+
<script type="text/javascript" charset="utf-8" src="../../js/navigation.js"></script>
|
17
|
+
<script type="text/javascript" charset="utf-8" src="../../js/search_index.js"></script>
|
18
|
+
<script type="text/javascript" charset="utf-8" src="../../js/search.js"></script>
|
19
|
+
<script type="text/javascript" charset="utf-8" src="../../js/searcher.js"></script>
|
20
|
+
<script type="text/javascript" charset="utf-8" src="../../js/darkfish.js"></script>
|
21
|
+
|
22
|
+
|
23
|
+
<body id="top" class="class">
|
24
|
+
<nav id="metadata">
|
25
|
+
<nav id="home-section" class="section">
|
26
|
+
<h3 class="section-header">
|
27
|
+
<a href="../../index.html">Home</a>
|
28
|
+
<a href="../../table_of_contents.html#classes">Classes</a>
|
29
|
+
<a href="../../table_of_contents.html#methods">Methods</a>
|
30
|
+
</h3>
|
31
|
+
</nav>
|
32
|
+
|
33
|
+
|
34
|
+
<nav id="search-section" class="section project-section" class="initially-hidden">
|
35
|
+
<form action="#" method="get" accept-charset="utf-8">
|
36
|
+
<h3 class="section-header">
|
37
|
+
<input type="text" name="search" placeholder="Search" id="search-field"
|
38
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
39
|
+
</h3>
|
40
|
+
</form>
|
41
|
+
|
42
|
+
<ul id="search-results" class="initially-hidden"></ul>
|
43
|
+
</nav>
|
44
|
+
|
45
|
+
|
46
|
+
<div id="file-metadata">
|
47
|
+
<nav id="file-list-section" class="section">
|
48
|
+
<h3 class="section-header">Defined In</h3>
|
49
|
+
<ul>
|
50
|
+
<li>lib/rubybreaker/runtime/type_system.rb
|
51
|
+
</ul>
|
52
|
+
</nav>
|
53
|
+
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div id="class-metadata">
|
58
|
+
|
59
|
+
<nav id="parent-class-section" class="section">
|
60
|
+
<h3 class="section-header">Parent</h3>
|
61
|
+
|
62
|
+
<p class="link">Object
|
63
|
+
|
64
|
+
</nav>
|
65
|
+
|
66
|
+
<!-- Included Modules -->
|
67
|
+
<nav id="includes-section" class="section">
|
68
|
+
<h3 class="section-header">Included Modules</h3>
|
69
|
+
|
70
|
+
<ul class="link-list">
|
71
|
+
|
72
|
+
|
73
|
+
<li><a class="include" href="Pluggable.html">RubyBreaker::Runtime::Pluggable</a>
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
<li><a class="include" href="../TypeDefs.html">RubyBreaker::TypeDefs</a>
|
78
|
+
|
79
|
+
|
80
|
+
</ul>
|
81
|
+
</nav>
|
82
|
+
|
83
|
+
<!-- Method Quickref -->
|
84
|
+
<nav id="method-list-section" class="section">
|
85
|
+
<h3 class="section-header">Methods</h3>
|
86
|
+
|
87
|
+
<ul class="link-list">
|
88
|
+
|
89
|
+
<li><a href="#method-i-after_method">#after_method</a>
|
90
|
+
|
91
|
+
<li><a href="#method-i-before_method">#before_method</a>
|
92
|
+
|
93
|
+
<li><a href="#method-i-is_object_wrapped-3F">#is_object_wrapped?</a>
|
94
|
+
|
95
|
+
<li><a href="#method-i-lub">#lub</a>
|
96
|
+
|
97
|
+
<li><a href="#method-i-lub_helper">#lub_helper</a>
|
98
|
+
|
99
|
+
</ul>
|
100
|
+
</nav>
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
<div id="project-metadata">
|
105
|
+
|
106
|
+
<nav id="classindex-section" class="section project-section">
|
107
|
+
<h3 class="section-header">Class and Module Index</h3>
|
108
|
+
|
109
|
+
<ul class="link-list">
|
110
|
+
|
111
|
+
<li><a href="../../RubyBreaker.html">RubyBreaker</a>
|
112
|
+
|
113
|
+
<li><a href="../../RubyBreaker/Breakable.html">RubyBreaker::Breakable</a>
|
114
|
+
|
115
|
+
<li><a href="../../RubyBreaker/Broken.html">RubyBreaker::Broken</a>
|
116
|
+
|
117
|
+
<li><a href="../../RubyBreaker/Broken/BrokenEigen.html">RubyBreaker::Broken::BrokenEigen</a>
|
118
|
+
|
119
|
+
<li><a href="../../RubyBreaker/Context.html">RubyBreaker::Context</a>
|
120
|
+
|
121
|
+
<li><a href="../../RubyBreaker/Debug.html">RubyBreaker::Debug</a>
|
122
|
+
|
123
|
+
<li><a href="../../RubyBreaker/Errors.html">RubyBreaker::Errors</a>
|
124
|
+
|
125
|
+
<li><a href="../../RubyBreaker/Errors/InternalError.html">RubyBreaker::Errors::InternalError</a>
|
126
|
+
|
127
|
+
<li><a href="../../RubyBreaker/Errors/InvalidSubtypeCheck.html">RubyBreaker::Errors::InvalidSubtypeCheck</a>
|
128
|
+
|
129
|
+
<li><a href="../../RubyBreaker/Errors/InvalidTypeConstruction.html">RubyBreaker::Errors::InvalidTypeConstruction</a>
|
130
|
+
|
131
|
+
<li><a href="../../RubyBreaker/Errors/SubtypeFailure.html">RubyBreaker::Errors::SubtypeFailure</a>
|
132
|
+
|
133
|
+
<li><a href="../../RubyBreaker/Errors/TypeError.html">RubyBreaker::Errors::TypeError</a>
|
134
|
+
|
135
|
+
<li><a href="../../RubyBreaker/Errors/UserError.html">RubyBreaker::Errors::UserError</a>
|
136
|
+
|
137
|
+
<li><a href="../../RubyBreaker/Kernel.html">RubyBreaker::Kernel</a>
|
138
|
+
|
139
|
+
<li><a href="../../RubyBreaker/Main.html">RubyBreaker::Main</a>
|
140
|
+
|
141
|
+
<li><a href="../../RubyBreaker/ObjectPosition.html">RubyBreaker::ObjectPosition</a>
|
142
|
+
|
143
|
+
<li><a href="../../RubyBreaker/Position.html">RubyBreaker::Position</a>
|
144
|
+
|
145
|
+
<li><a href="../../RubyBreaker/RubyTypeUtils.html">RubyBreaker::RubyTypeUtils</a>
|
146
|
+
|
147
|
+
<li><a href="../../RubyBreaker/Runtime.html">RubyBreaker::Runtime</a>
|
148
|
+
|
149
|
+
<li><a href="../../RubyBreaker/Runtime/Inspector.html">RubyBreaker::Runtime::Inspector</a>
|
150
|
+
|
151
|
+
<li><a href="../../RubyBreaker/Runtime/MethodInfo.html">RubyBreaker::Runtime::MethodInfo</a>
|
152
|
+
|
153
|
+
<li><a href="../../RubyBreaker/Runtime/Monitor.html">RubyBreaker::Runtime::Monitor</a>
|
154
|
+
|
155
|
+
<li><a href="../../RubyBreaker/Runtime/MonitorInstaller.html">RubyBreaker::Runtime::MonitorInstaller</a>
|
156
|
+
|
157
|
+
<li><a href="../../RubyBreaker/Runtime/MonitorSwitch.html">RubyBreaker::Runtime::MonitorSwitch</a>
|
158
|
+
|
159
|
+
<li><a href="../../RubyBreaker/Runtime/MonitorUtils.html">RubyBreaker::Runtime::MonitorUtils</a>
|
160
|
+
|
161
|
+
<li><a href="../../RubyBreaker/Runtime/ObjectWrapper.html">RubyBreaker::Runtime::ObjectWrapper</a>
|
162
|
+
|
163
|
+
<li><a href="../../RubyBreaker/Runtime/Pluggable.html">RubyBreaker::Runtime::Pluggable</a>
|
164
|
+
|
165
|
+
<li><a href="../../RubyBreaker/Runtime/TypePlaceholder.html">RubyBreaker::Runtime::TypePlaceholder</a>
|
166
|
+
|
167
|
+
<li><a href="../../RubyBreaker/Runtime/TypeSigParser.html">RubyBreaker::Runtime::TypeSigParser</a>
|
168
|
+
|
169
|
+
<li><a href="../../RubyBreaker/Runtime/TypeSystem.html">RubyBreaker::Runtime::TypeSystem</a>
|
170
|
+
|
171
|
+
<li><a href="../../RubyBreaker/TestCase.html">RubyBreaker::TestCase</a>
|
172
|
+
|
173
|
+
<li><a href="../../RubyBreaker/TypeComparer.html">RubyBreaker::TypeComparer</a>
|
174
|
+
|
175
|
+
<li><a href="../../RubyBreaker/TypeDefs.html">RubyBreaker::TypeDefs</a>
|
176
|
+
|
177
|
+
<li><a href="../../RubyBreaker/TypeDefs/AnyType.html">RubyBreaker::TypeDefs::AnyType</a>
|
178
|
+
|
179
|
+
<li><a href="../../RubyBreaker/TypeDefs/BlockType.html">RubyBreaker::TypeDefs::BlockType</a>
|
180
|
+
|
181
|
+
<li><a href="../../RubyBreaker/TypeDefs/DuckType.html">RubyBreaker::TypeDefs::DuckType</a>
|
182
|
+
|
183
|
+
<li><a href="../../RubyBreaker/TypeDefs/FusionType.html">RubyBreaker::TypeDefs::FusionType</a>
|
184
|
+
|
185
|
+
<li><a href="../../RubyBreaker/TypeDefs/MethodListType.html">RubyBreaker::TypeDefs::MethodListType</a>
|
186
|
+
|
187
|
+
<li><a href="../../RubyBreaker/TypeDefs/MethodType.html">RubyBreaker::TypeDefs::MethodType</a>
|
188
|
+
|
189
|
+
<li><a href="../../RubyBreaker/TypeDefs/NilType.html">RubyBreaker::TypeDefs::NilType</a>
|
190
|
+
|
191
|
+
<li><a href="../../RubyBreaker/TypeDefs/NominalType.html">RubyBreaker::TypeDefs::NominalType</a>
|
192
|
+
|
193
|
+
<li><a href="../../RubyBreaker/TypeDefs/OptionalType.html">RubyBreaker::TypeDefs::OptionalType</a>
|
194
|
+
|
195
|
+
<li><a href="../../RubyBreaker/TypeDefs/OrType.html">RubyBreaker::TypeDefs::OrType</a>
|
196
|
+
|
197
|
+
<li><a href="../../RubyBreaker/TypeDefs/SelfType.html">RubyBreaker::TypeDefs::SelfType</a>
|
198
|
+
|
199
|
+
<li><a href="../../RubyBreaker/TypeDefs/Type.html">RubyBreaker::TypeDefs::Type</a>
|
200
|
+
|
201
|
+
<li><a href="../../RubyBreaker/TypeDefs/VarLengthType.html">RubyBreaker::TypeDefs::VarLengthType</a>
|
202
|
+
|
203
|
+
<li><a href="../../RubyBreaker/TypeUnparser.html">RubyBreaker::TypeUnparser</a>
|
204
|
+
|
205
|
+
<li><a href="../../RubyBreaker/Typing.html">RubyBreaker::Typing</a>
|
206
|
+
|
207
|
+
<li><a href="../../RubyBreaker/Utilities.html">RubyBreaker::Utilities</a>
|
208
|
+
|
209
|
+
</ul>
|
210
|
+
</nav>
|
211
|
+
|
212
|
+
</div>
|
213
|
+
</nav>
|
214
|
+
|
215
|
+
<div id="documentation">
|
216
|
+
<h1 class="class">class RubyBreaker::Runtime::TypeSystem</h1>
|
217
|
+
|
218
|
+
<div id="description" class="description">
|
219
|
+
|
220
|
+
<p>This is the default type system for <a
|
221
|
+
href="../../RubyBreaker.html">RubyBreaker</a>. It can be overridden by a
|
222
|
+
user specified type system. See <code>pluggable.rb</code> for how this can
|
223
|
+
be done.</p>
|
224
|
+
|
225
|
+
</div><!-- description -->
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
<!-- Methods -->
|
240
|
+
|
241
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
|
242
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
243
|
+
|
244
|
+
|
245
|
+
<div id="method-i-after_method" class="method-detail ">
|
246
|
+
|
247
|
+
<div class="method-heading">
|
248
|
+
<span class="method-name">after_method</span><span
|
249
|
+
class="method-args">(obj, meth_info)</span>
|
250
|
+
<span class="method-click-advice">click to toggle source</span>
|
251
|
+
</div>
|
252
|
+
|
253
|
+
|
254
|
+
<div class="method-description">
|
255
|
+
|
256
|
+
<p>This method occurs after every “monitored” method call. It updates the type
|
257
|
+
information.</p>
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
<div class="method-source-code" id="after_method-source">
|
262
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker/runtime/type_system.rb, line 233</span>
|
263
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">after_method</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">meth_info</span>)
|
264
|
+
|
265
|
+
<span class="ruby-identifier">is_obj_mod</span> = (<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Class</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Module</span>)
|
266
|
+
<span class="ruby-identifier">mod</span> = <span class="ruby-identifier">is_obj_mod</span> <span class="ruby-operator">?</span> <span class="ruby-constant">Runtime</span>.<span class="ruby-identifier">eigen_class</span>(<span class="ruby-identifier">obj</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span>
|
267
|
+
|
268
|
+
<span class="ruby-comment"># Take things out</span>
|
269
|
+
<span class="ruby-identifier">meth_name</span> = <span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">meth_name</span>
|
270
|
+
<span class="ruby-identifier">retval</span> = <span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">ret</span>
|
271
|
+
<span class="ruby-identifier">args</span> = <span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">args</span>
|
272
|
+
<span class="ruby-identifier">blk</span> = <span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">blk</span>
|
273
|
+
|
274
|
+
<span class="ruby-constant">Debug</span>.<span class="ruby-identifier">msg</span>(<span class="ruby-node">"In module monitor_after #{meth_name}"</span>)
|
275
|
+
|
276
|
+
<span class="ruby-identifier">meth_type_map</span> = <span class="ruby-constant">Breakable</span><span class="ruby-operator">::</span><span class="ruby-constant">TYPE_PLACEHOLDER_MAP</span>[<span class="ruby-identifier">mod</span>].<span class="ruby-identifier">meth_type_map</span>
|
277
|
+
|
278
|
+
<span class="ruby-comment"># Compute the least upper bound</span>
|
279
|
+
<span class="ruby-identifier">lub</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">meth_type_map</span>,<span class="ruby-identifier">meth_name</span>,<span class="ruby-identifier">retval</span>,*<span class="ruby-identifier">args</span>,&<span class="ruby-identifier">blk</span>)
|
280
|
+
|
281
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">obj</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">retval</span>
|
282
|
+
<span class="ruby-comment"># It is possible that the method receiver is a wrapped object if</span>
|
283
|
+
<span class="ruby-comment"># it is an argument to a method in the current call stack. So this</span>
|
284
|
+
<span class="ruby-comment"># check is to return the wrapped object and not the stripped off</span>
|
285
|
+
<span class="ruby-comment"># version. (Remember, == is overridden for the wrapped object.)</span>
|
286
|
+
<span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">ret</span> = <span class="ruby-identifier">obj</span>
|
287
|
+
<span class="ruby-keyword">end</span>
|
288
|
+
|
289
|
+
<span class="ruby-keyword">end</span></pre>
|
290
|
+
</div><!-- after_method-source -->
|
291
|
+
|
292
|
+
</div>
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
</div><!-- after_method-method -->
|
298
|
+
|
299
|
+
|
300
|
+
<div id="method-i-before_method" class="method-detail ">
|
301
|
+
|
302
|
+
<div class="method-heading">
|
303
|
+
<span class="method-name">before_method</span><span
|
304
|
+
class="method-args">(obj, meth_info)</span>
|
305
|
+
<span class="method-click-advice">click to toggle source</span>
|
306
|
+
</div>
|
307
|
+
|
308
|
+
|
309
|
+
<div class="method-description">
|
310
|
+
|
311
|
+
<p>This method occurs before every “monitored” method call. It wraps each
|
312
|
+
argument with the object wrapper.</p>
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
<div class="method-source-code" id="before_method-source">
|
317
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker/runtime/type_system.rb, line 173</span>
|
318
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">before_method</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">meth_info</span>)
|
319
|
+
|
320
|
+
<span class="ruby-identifier">is_obj_mod</span> = (<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Class</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Module</span>)
|
321
|
+
<span class="ruby-identifier">mod</span> = <span class="ruby-identifier">is_obj_mod</span> <span class="ruby-operator">?</span> <span class="ruby-constant">Runtime</span>.<span class="ruby-identifier">eigen_class</span>(<span class="ruby-identifier">obj</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span>
|
322
|
+
|
323
|
+
<span class="ruby-identifier">meth_type_map</span> = <span class="ruby-constant">Breakable</span><span class="ruby-operator">::</span><span class="ruby-constant">TYPE_PLACEHOLDER_MAP</span>[<span class="ruby-identifier">mod</span>].<span class="ruby-identifier">meth_type_map</span>
|
324
|
+
|
325
|
+
<span class="ruby-comment"># Let's take things out of the MethodInfo object</span>
|
326
|
+
<span class="ruby-identifier">meth_name</span> = <span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">meth_name</span>
|
327
|
+
<span class="ruby-identifier">args</span> = <span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">args</span>
|
328
|
+
<span class="ruby-identifier">blk</span> = <span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">blk</span>
|
329
|
+
<span class="ruby-identifier">ret</span> = <span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">ret</span>
|
330
|
+
|
331
|
+
<span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">arg</span><span class="ruby-operator">|</span>
|
332
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">TrueClass</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">FalseClass</span>)
|
333
|
+
<span class="ruby-comment"># XXX: would overrides resolve this issue?</span>
|
334
|
+
<span class="ruby-identifier">arg</span>
|
335
|
+
<span class="ruby-keyword">else</span>
|
336
|
+
<span class="ruby-constant">ObjectWrapper</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">arg</span>)
|
337
|
+
<span class="ruby-keyword">end</span>
|
338
|
+
<span class="ruby-keyword">end</span>
|
339
|
+
|
340
|
+
<span class="ruby-constant">Debug</span>.<span class="ruby-identifier">msg</span>(<span class="ruby-node">"In module monitor_before #{meth_name}"</span>)
|
341
|
+
|
342
|
+
<span class="ruby-identifier">meth_type</span> = <span class="ruby-identifier">meth_type_map</span>[<span class="ruby-identifier">meth_name</span>]
|
343
|
+
|
344
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">meth_type</span>
|
345
|
+
<span class="ruby-comment"># This means the method type has been created previously.</span>
|
346
|
+
<span class="ruby-keyword">unless</span> (<span class="ruby-identifier">blk</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">meth_type</span>.<span class="ruby-identifier">blk_type</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">nil</span>) <span class="ruby-operator">&&</span>
|
347
|
+
(<span class="ruby-operator">!</span><span class="ruby-identifier">blk</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">blk</span>.<span class="ruby-identifier">arity</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">meth_type</span>.<span class="ruby-identifier">blk_type</span>.<span class="ruby-identifier">arg_types</span>.<span class="ruby-identifier">length</span>)
|
348
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">Errors</span><span class="ruby-operator">::</span><span class="ruby-constant">TypeError</span>(<span class="ruby-string">"Block usage is inconsistent"</span>)
|
349
|
+
<span class="ruby-keyword">end</span>
|
350
|
+
<span class="ruby-keyword">else</span>
|
351
|
+
<span class="ruby-comment"># No method type has been created for this method yet. Create a</span>
|
352
|
+
<span class="ruby-comment"># blank method type (where each argument type, block type, and</span>
|
353
|
+
<span class="ruby-comment"># return type are all nil).</span>
|
354
|
+
<span class="ruby-comment">#</span>
|
355
|
+
<span class="ruby-comment"># First, use the orignal method's arity to find out # of</span>
|
356
|
+
<span class="ruby-comment"># arguments. </span>
|
357
|
+
<span class="ruby-identifier">meth_obj</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">method</span>(<span class="ruby-constant">MonitorUtils</span>.<span class="ruby-identifier">get_alt_meth_name</span>(<span class="ruby-identifier">meth_name</span>))
|
358
|
+
<span class="ruby-identifier">arity</span> = <span class="ruby-identifier">meth_obj</span>.<span class="ruby-identifier">arity</span>
|
359
|
+
<span class="ruby-identifier">arg_types</span> = [<span class="ruby-keyword">nil</span>] * <span class="ruby-identifier">meth_obj</span>.<span class="ruby-identifier">arity</span>.<span class="ruby-identifier">abs</span>
|
360
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">blk</span>
|
361
|
+
<span class="ruby-comment"># Do the same for the block too if there is one</span>
|
362
|
+
<span class="ruby-identifier">blk_arity</span> = <span class="ruby-identifier">blk</span>.<span class="ruby-identifier">arity</span>
|
363
|
+
<span class="ruby-identifier">blk_arg_types</span> = [<span class="ruby-keyword">nil</span>] * <span class="ruby-identifier">blk_artiy</span>.<span class="ruby-identifier">abs</span>
|
364
|
+
<span class="ruby-identifier">blk_type</span> = <span class="ruby-constant">BlockType</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">blk_arg_types</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-keyword">nil</span>)
|
365
|
+
<span class="ruby-keyword">else</span>
|
366
|
+
<span class="ruby-identifier">blk_type</span> = <span class="ruby-keyword">nil</span>
|
367
|
+
<span class="ruby-keyword">end</span>
|
368
|
+
<span class="ruby-identifier">meth_type</span> = <span class="ruby-constant">MethodType</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">meth_name</span>, <span class="ruby-identifier">arg_types</span>, <span class="ruby-identifier">blk_type</span>, <span class="ruby-keyword">nil</span>)
|
369
|
+
<span class="ruby-identifier">meth_type_map</span>[<span class="ruby-identifier">meth_name</span>] = <span class="ruby-identifier">meth_type</span>
|
370
|
+
<span class="ruby-keyword">end</span>
|
371
|
+
|
372
|
+
<span class="ruby-identifier">meth_info</span>.<span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>
|
373
|
+
|
374
|
+
<span class="ruby-keyword">end</span></pre>
|
375
|
+
</div><!-- before_method-source -->
|
376
|
+
|
377
|
+
</div>
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
</div><!-- before_method-method -->
|
383
|
+
|
384
|
+
|
385
|
+
</section><!-- public-instance-method-details -->
|
386
|
+
|
387
|
+
<section id="protected-instance-5Buntitled-5D-method-details" class="method-section section">
|
388
|
+
<h3 class="section-header">Protected Instance Methods</h3>
|
389
|
+
|
390
|
+
|
391
|
+
<div id="method-i-is_object_wrapped-3F" class="method-detail ">
|
392
|
+
|
393
|
+
<div class="method-heading">
|
394
|
+
<span class="method-name">is_object_wrapped?</span><span
|
395
|
+
class="method-args">(obj)</span>
|
396
|
+
<span class="method-click-advice">click to toggle source</span>
|
397
|
+
</div>
|
398
|
+
|
399
|
+
|
400
|
+
<div class="method-description">
|
401
|
+
|
402
|
+
<p>Check if the object is wrapped by a monitor</p>
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
<div class="method-source-code" id="is_object_wrapped-3F-source">
|
407
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker/runtime/type_system.rb, line 29</span>
|
408
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">is_object_wrapped?</span>(<span class="ruby-identifier">obj</span>)
|
409
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-constant">WRAPPED_INDICATOR</span>)
|
410
|
+
<span class="ruby-keyword">end</span></pre>
|
411
|
+
</div><!-- is_object_wrapped-3F-source -->
|
412
|
+
|
413
|
+
</div>
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
</div><!-- is_object_wrapped-3F-method -->
|
419
|
+
|
420
|
+
|
421
|
+
<div id="method-i-lub" class="method-detail ">
|
422
|
+
|
423
|
+
<div class="method-heading">
|
424
|
+
<span class="method-name">lub</span><span
|
425
|
+
class="method-args">(obj, meth_type_map, meth_name, retval, *args, &blk)</span>
|
426
|
+
<span class="method-click-advice">click to toggle source</span>
|
427
|
+
</div>
|
428
|
+
|
429
|
+
|
430
|
+
<div class="method-description">
|
431
|
+
|
432
|
+
<p>This method computes the least upper bound of the existing method type and
|
433
|
+
newly observed argument/block/return types. There are a few cases to
|
434
|
+
consider:</p>
|
435
|
+
|
436
|
+
<p>If the existing type is a method list type, the new observed type will be
|
437
|
+
either “consolidated” into one of the method types in the list or added to
|
438
|
+
the list.</p>
|
439
|
+
|
440
|
+
<p>If there is no compatibility between the existing method type and the
|
441
|
+
observed type, then the method type will be promoted to a method list type.
|
442
|
+
And the newly observed type will be added to the list.</p>
|
443
|
+
|
444
|
+
<p>For each method type,</p>
|
445
|
+
|
446
|
+
<p>It basically consolidates the existing type information for the invoked
|
447
|
+
method and the observed type.</p>
|
448
|
+
|
449
|
+
<p>For arguments, we look for most general type that can handle all types we
|
450
|
+
have seen. This means we find the super type of all types we have seen
|
451
|
+
(excluding unknown types).</p>
|
452
|
+
|
453
|
+
<p>For return, we look for most specific type that can handle both types.
|
454
|
+
Therefore, if two types have no subtype relation, we AND them. But we do
|
455
|
+
not allow AND types in the return type. We must turn the method type to a
|
456
|
+
method list type.</p>
|
457
|
+
<dl class="rdoc-list note-list"><dt>obj
|
458
|
+
<dd>
|
459
|
+
<p>the receive of the method call</p>
|
460
|
+
</dd><dt>meth_type_map
|
461
|
+
<dd>
|
462
|
+
<p>a hash object that maps method names to method types</p>
|
463
|
+
</dd><dt>meth_name
|
464
|
+
<dd>
|
465
|
+
<p>the name of the method being invoked</p>
|
466
|
+
</dd><dt>retval
|
467
|
+
<dd>
|
468
|
+
<p>the return value of the original method call</p>
|
469
|
+
</dd><dt>args
|
470
|
+
<dd>
|
471
|
+
<p>the arguments</p>
|
472
|
+
</dd><dt>blk
|
473
|
+
<dd>
|
474
|
+
<p>the block argument</p>
|
475
|
+
</dd></dl>
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
<div class="method-source-code" id="lub-source">
|
480
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker/runtime/type_system.rb, line 114</span>
|
481
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">lub</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">meth_type_map</span>, <span class="ruby-identifier">meth_name</span>, <span class="ruby-identifier">retval</span>, *<span class="ruby-identifier">args</span>, &<span class="ruby-identifier">blk</span>)
|
482
|
+
|
483
|
+
<span class="ruby-identifier">exist_meth_type</span> = <span class="ruby-identifier">meth_type_map</span>[<span class="ruby-identifier">meth_name</span>.<span class="ruby-identifier">to_sym</span>]
|
484
|
+
|
485
|
+
<span class="ruby-comment"># Again, find the arity</span>
|
486
|
+
<span class="ruby-identifier">meth_obj</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">method</span>(<span class="ruby-constant">MonitorUtils</span>.<span class="ruby-identifier">get_alt_meth_name</span>(<span class="ruby-identifier">meth_name</span>))
|
487
|
+
<span class="ruby-identifier">arity</span> = <span class="ruby-identifier">meth_obj</span>.<span class="ruby-identifier">arity</span>
|
488
|
+
|
489
|
+
<span class="ruby-comment"># Construct the newly observed method type first</span>
|
490
|
+
<span class="ruby-identifier">new_meth_type</span> = <span class="ruby-constant">MethodType</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">meth_name</span>,[])
|
491
|
+
<span class="ruby-identifier">args</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">arg</span>,<span class="ruby-identifier">idx</span><span class="ruby-operator">|</span>
|
492
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">is_object_wrapped?</span>(<span class="ruby-identifier">arg</span>)
|
493
|
+
<span class="ruby-identifier">arg_type</span> = <span class="ruby-identifier">arg</span>.<span class="ruby-identifier">__rubybreaker_type</span>
|
494
|
+
<span class="ruby-keyword">else</span>
|
495
|
+
<span class="ruby-identifier">arg_type</span> = <span class="ruby-constant">NominalType</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">arg</span>.<span class="ruby-identifier">class</span>)
|
496
|
+
<span class="ruby-keyword">end</span>
|
497
|
+
<span class="ruby-comment"># Check if the last argument should be a variable length argument</span>
|
498
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">arity</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">idx</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">arity</span>.<span class="ruby-identifier">abs</span>)
|
499
|
+
<span class="ruby-identifier">new_meth_type</span>.<span class="ruby-identifier">arg_types</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">VarLengthType</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">arg_type</span>)
|
500
|
+
<span class="ruby-keyword">break</span>
|
501
|
+
<span class="ruby-keyword">end</span>
|
502
|
+
<span class="ruby-identifier">new_meth_type</span>.<span class="ruby-identifier">arg_types</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">arg_type</span>
|
503
|
+
<span class="ruby-keyword">end</span>
|
504
|
+
|
505
|
+
<span class="ruby-keyword">if</span> (<span class="ruby-identifier">obj</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">retval</span>)
|
506
|
+
<span class="ruby-comment"># the return value is same as the message receiver. This means the</span>
|
507
|
+
<span class="ruby-comment"># return value has the self type.</span>
|
508
|
+
<span class="ruby-constant">SelfType</span>.<span class="ruby-identifier">set_self</span>(<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">class</span>)
|
509
|
+
<span class="ruby-identifier">ret_type</span> = <span class="ruby-constant">SelfType</span>.<span class="ruby-identifier">new</span>()
|
510
|
+
<span class="ruby-keyword">else</span>
|
511
|
+
<span class="ruby-comment"># Otherwise, construct a nominal type.</span>
|
512
|
+
<span class="ruby-identifier">ret_type</span> = <span class="ruby-constant">NominalType</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">retval</span>.<span class="ruby-identifier">class</span>)
|
513
|
+
<span class="ruby-keyword">end</span>
|
514
|
+
<span class="ruby-identifier">new_meth_type</span>.<span class="ruby-identifier">ret_type</span> = <span class="ruby-identifier">ret_type</span>
|
515
|
+
|
516
|
+
<span class="ruby-identifier">resolved</span> = <span class="ruby-keyword">false</span>
|
517
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">exist_meth_type</span>.<span class="ruby-identifier">instance_of?</span>(<span class="ruby-constant">MethodListType</span>)
|
518
|
+
<span class="ruby-identifier">exist_meth_type</span>.<span class="ruby-identifier">types</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">meth_type</span><span class="ruby-operator">|</span>
|
519
|
+
<span class="ruby-identifier">resolved</span> = <span class="ruby-identifier">lub_helper</span>(<span class="ruby-identifier">meth_type</span>, <span class="ruby-identifier">new_meth_type</span>)
|
520
|
+
<span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">resolved</span>
|
521
|
+
}
|
522
|
+
<span class="ruby-keyword">else</span>
|
523
|
+
<span class="ruby-identifier">resolved</span> = <span class="ruby-identifier">lub_helper</span>(<span class="ruby-identifier">exist_meth_type</span>, <span class="ruby-identifier">new_meth_type</span>)
|
524
|
+
<span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">resolved</span>
|
525
|
+
<span class="ruby-comment"># Could not resolve the types, so promote the method type to a</span>
|
526
|
+
<span class="ruby-comment"># method list type</span>
|
527
|
+
<span class="ruby-identifier">exist_meth_type</span> = <span class="ruby-constant">MethodListType</span>.<span class="ruby-identifier">new</span>([<span class="ruby-identifier">exist_meth_type</span>])
|
528
|
+
<span class="ruby-identifier">meth_type_map</span>[<span class="ruby-identifier">meth_name</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">exist_meth_type</span>
|
529
|
+
<span class="ruby-keyword">end</span>
|
530
|
+
<span class="ruby-keyword">end</span>
|
531
|
+
<span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">resolved</span>
|
532
|
+
<span class="ruby-identifier">exist_meth_type</span>.<span class="ruby-identifier">types</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">new_meth_type</span>
|
533
|
+
<span class="ruby-keyword">end</span>
|
534
|
+
<span class="ruby-keyword">end</span></pre>
|
535
|
+
</div><!-- lub-source -->
|
536
|
+
|
537
|
+
</div>
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
|
542
|
+
</div><!-- lub-method -->
|
543
|
+
|
544
|
+
|
545
|
+
<div id="method-i-lub_helper" class="method-detail ">
|
546
|
+
|
547
|
+
<div class="method-heading">
|
548
|
+
<span class="method-name">lub_helper</span><span
|
549
|
+
class="method-args">(exist_meth_type, new_meth_type)</span>
|
550
|
+
<span class="method-click-advice">click to toggle source</span>
|
551
|
+
</div>
|
552
|
+
|
553
|
+
|
554
|
+
<div class="method-description">
|
555
|
+
|
556
|
+
<p>This method is a helper for computing the least upper bound. It handles the
|
557
|
+
case where existing method type is a method type (and not a method list
|
558
|
+
type). If there is no compatibility of the two types, then it returns
|
559
|
+
false.</p>
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
<div class="method-source-code" id="lub_helper-source">
|
564
|
+
<pre><span class="ruby-comment"># File lib/rubybreaker/runtime/type_system.rb, line 37</span>
|
565
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">lub_helper</span>(<span class="ruby-identifier">exist_meth_type</span>, <span class="ruby-identifier">new_meth_type</span>)
|
566
|
+
|
567
|
+
<span class="ruby-comment"># most restrictive for the given test cases. </span>
|
568
|
+
<span class="ruby-identifier">arg_types</span> = []
|
569
|
+
|
570
|
+
<span class="ruby-identifier">exist_meth_type</span>.<span class="ruby-identifier">arg_types</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">exist_arg_type</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
571
|
+
<span class="ruby-identifier">arg_type</span> = <span class="ruby-keyword">nil</span>
|
572
|
+
<span class="ruby-identifier">new_arg_type</span> = <span class="ruby-identifier">new_meth_type</span>.<span class="ruby-identifier">arg_types</span>[<span class="ruby-identifier">i</span>]
|
573
|
+
<span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">exist_arg_type</span>
|
574
|
+
<span class="ruby-comment"># nil means there hasn't been any type observed</span>
|
575
|
+
<span class="ruby-identifier">arg_type</span> = <span class="ruby-identifier">new_arg_type</span>
|
576
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">new_arg_type</span>.<span class="ruby-identifier">subtype_of?</span>(<span class="ruby-identifier">exist_arg_type</span>)
|
577
|
+
<span class="ruby-identifier">arg_type</span> = <span class="ruby-identifier">exist_arg_type</span>
|
578
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-operator">!</span><span class="ruby-identifier">exist_arg_type</span>.<span class="ruby-identifier">subtype_of?</span>(<span class="ruby-identifier">new_arg_type</span>)
|
579
|
+
<span class="ruby-comment"># No subtype relation between them, so OR them</span>
|
580
|
+
<span class="ruby-identifier">arg_type</span> = <span class="ruby-constant">OrType</span>.<span class="ruby-identifier">new</span>([<span class="ruby-identifier">new_arg_type</span>, <span class="ruby-identifier">exist_arg_type</span>])
|
581
|
+
<span class="ruby-keyword">end</span>
|
582
|
+
<span class="ruby-identifier">arg_types</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">arg_type</span>
|
583
|
+
<span class="ruby-keyword">end</span>
|
584
|
+
|
585
|
+
<span class="ruby-identifier">new_ret_type</span> = <span class="ruby-identifier">new_meth_type</span>.<span class="ruby-identifier">ret_type</span>
|
586
|
+
<span class="ruby-identifier">exist_ret_type</span> = <span class="ruby-identifier">exist_meth_type</span>.<span class="ruby-identifier">ret_type</span>
|
587
|
+
|
588
|
+
<span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">exist_ret_type</span>
|
589
|
+
<span class="ruby-identifier">ret_type</span> = <span class="ruby-identifier">new_ret_type</span>
|
590
|
+
<span class="ruby-identifier">resolved</span> = <span class="ruby-keyword">true</span>
|
591
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">exist_ret_type</span>.<span class="ruby-identifier">subtype_of?</span>(<span class="ruby-identifier">new_ret_type</span>)
|
592
|
+
<span class="ruby-identifier">ret_type</span> = <span class="ruby-identifier">exist_ret_type</span>
|
593
|
+
<span class="ruby-identifier">resolved</span> = <span class="ruby-keyword">true</span>
|
594
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">new_ret_type</span>.<span class="ruby-identifier">subtype_of?</span>(<span class="ruby-identifier">exist_ret_type</span>)
|
595
|
+
<span class="ruby-identifier">ret_type</span> = <span class="ruby-identifier">new_ret_type</span>
|
596
|
+
<span class="ruby-identifier">resolved</span> = <span class="ruby-keyword">true</span>
|
597
|
+
<span class="ruby-keyword">else</span>
|
598
|
+
<span class="ruby-identifier">resolved</span> = <span class="ruby-keyword">false</span>
|
599
|
+
<span class="ruby-keyword">end</span>
|
600
|
+
|
601
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">resolved</span>
|
602
|
+
<span class="ruby-identifier">exist_meth_type</span>.<span class="ruby-identifier">arg_types</span> = <span class="ruby-identifier">arg_types</span>
|
603
|
+
<span class="ruby-identifier">exist_meth_type</span>.<span class="ruby-identifier">ret_type</span> = <span class="ruby-identifier">ret_type</span>
|
604
|
+
<span class="ruby-keyword">end</span>
|
605
|
+
|
606
|
+
<span class="ruby-keyword">return</span> <span class="ruby-identifier">resolved</span>
|
607
|
+
<span class="ruby-keyword">end</span></pre>
|
608
|
+
</div><!-- lub_helper-source -->
|
609
|
+
|
610
|
+
</div>
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
</div><!-- lub_helper-method -->
|
616
|
+
|
617
|
+
|
618
|
+
</section><!-- protected-instance-method-details -->
|
619
|
+
|
620
|
+
</section><!-- 5Buntitled-5D -->
|
621
|
+
|
622
|
+
</div><!-- documentation -->
|
623
|
+
|
624
|
+
|
625
|
+
<footer id="validator-badges">
|
626
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
627
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
|
628
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
629
|
+
</footer>
|
630
|
+
|