Class: Duby::Compiler::JavaSource::SimpleWhileLoop
- Inherits:
-
Object
- Object
- Duby::Compiler::JavaSource::SimpleWhileLoop
show all
- Defined in:
- lib/duby/jvm/source_generator/loops.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SimpleWhileLoop.
4
5
6
7
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 4
def initialize(loop, compiler)
@loop = loop
@compiler = compiler
end
|
Instance Attribute Details
Returns the value of attribute compiler.
3
4
5
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 3
def compiler
@compiler
end
|
Returns the value of attribute loop.
3
4
5
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 3
def loop
@loop
end
|
Instance Method Details
9
10
11
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 9
def break
compiler.method.puts "break;"
end
|
#compile(expression) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 21
def compile(expression)
prepare
@start.call
compiler.method.block do
compile_body
end
if @end_check
@end_check.call
compiler.method.puts ';'
end
if expression
compiler.method.puts "#{compiler.lvalue}null;"
end
end
|
#compile_body ⇒ Object
36
37
38
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 36
def compile_body
loop.body.compile(compiler, false)
end
|
13
14
15
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 13
def next
compiler.method.puts "continue;"
end
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 40
def prepare
predicate = loop.condition.predicate.precompile(compiler)
negative = loop.negative ? '!' : ''
check = lambda do
compiler.method.print "while (#{negative}"
predicate.compile(compiler, true)
compiler.method.print ')'
end
if loop.check_first
@start = check
else
@start = lambda {compiler.method.print 'do'}
@end_check = check
end
end
|
17
18
19
|
# File 'lib/duby/jvm/source_generator/loops.rb', line 17
def redo
raise "#{self.class.name} doesn't support redo"
end
|