Class: Duby::Compiler::JavaSource::SimpleWhileLoop
- Inherits:
-
Object
- Object
- Duby::Compiler::JavaSource::SimpleWhileLoop
- Defined in:
- lib/duby/jvm/source_generator/loops.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#compiler ⇒ Object
readonly
Returns the value of attribute compiler.
-
#loop ⇒ Object
readonly
Returns the value of attribute loop.
Instance Method Summary collapse
- #break ⇒ Object
- #compile(expression) ⇒ Object
- #compile_body ⇒ Object
-
#initialize(loop, compiler) ⇒ SimpleWhileLoop
constructor
A new instance of SimpleWhileLoop.
- #next ⇒ Object
- #prepare ⇒ Object
- #redo ⇒ Object
Constructor Details
#initialize(loop, compiler) ⇒ SimpleWhileLoop
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
#compiler ⇒ Object (readonly)
Returns the value of attribute compiler.
3 4 5 |
# File 'lib/duby/jvm/source_generator/loops.rb', line 3 def compiler @compiler end |
#loop ⇒ Object (readonly)
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
#break ⇒ Object
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 35 36 37 |
# File 'lib/duby/jvm/source_generator/loops.rb', line 21 def compile(expression) prepare @loop.init.compile(compiler, false) if @loop.init? @start.call compiler.method.block do @loop.pre.compile(compiler, false) if @loop.pre? compile_body @loop.post.compile(compiler, false) if @loop.post? end if @end_check @end_check.call compiler.method.puts ';' end if expression compiler.method.puts "#{compiler.lvalue}null;" end end |
#compile_body ⇒ Object
39 40 41 |
# File 'lib/duby/jvm/source_generator/loops.rb', line 39 def compile_body loop.body.compile(compiler, false) end |
#next ⇒ Object
13 14 15 |
# File 'lib/duby/jvm/source_generator/loops.rb', line 13 def next compiler.method.puts "continue;" end |
#prepare ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/duby/jvm/source_generator/loops.rb', line 43 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 |
#redo ⇒ Object
17 18 19 |
# File 'lib/duby/jvm/source_generator/loops.rb', line 17 def redo raise "#{self.class.name} doesn't support redo" end |