Class: Nydp::Loop

Inherits:
Object show all
Extended by:
Helper
Includes:
Helper
Defined in:
lib/nydp/loop.rb

Overview

def to_s

  "#{@loop_body.to_s}"
end

end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

cons, list, literal?, pair?, sig, sym, sym?

Methods included from Converter

#n2r, #r2n, #rubify

Constructor Details

#initialize(cond, loop_body) ⇒ Loop

Returns a new instance of Loop.



38
39
40
# File 'lib/nydp/loop.rb', line 38

def initialize cond, loop_body
  @condition, @loop_body = cond, loop_body
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



36
37
38
# File 'lib/nydp/loop.rb', line 36

def condition
  @condition
end

#loop_bodyObject (readonly)

Returns the value of attribute loop_body.



36
37
38
# File 'lib/nydp/loop.rb', line 36

def loop_body
  @loop_body
end

Class Method Details

.build(expressions, bindings, ns) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/nydp/loop.rb', line 54

def self.build expressions, bindings, ns
  if expressions.is_a? Nydp::Pair
    cond       = Compiler.compile expressions.car, bindings, ns
    loop_body  = Compiler.compile expressions.cdr.car, bindings, ns
    csig       = sig(cond)
    new(cond, loop_body)
  else
    raise "can't compile Loop: #{expressions._nydp_inspect}"
  end
end

Instance Method Details

#compile_to_ruby(indent, srcs, opts = nil) ⇒ Object



65
66
67
68
69
70
# File 'lib/nydp/loop.rb', line 65

def compile_to_ruby indent, srcs, opts=nil
  "#{indent}##> #{to_s.split(/\n/).join('\n')}\n" +
  "#{indent}while (#{condition.compile_to_ruby "", srcs})
#{loop_body.compile_to_ruby(indent + "  ", srcs, cando: true)}
#{indent}end"
end

#inspectObject



46
47
48
# File 'lib/nydp/loop.rb', line 46

def inspect
  "loop:#{condition._nydp_inspect}:#{loop_body._nydp_inspect}"
end

#lexical_reach(n) ⇒ Object



42
43
44
# File 'lib/nydp/loop.rb', line 42

def lexical_reach n
  [condition.lexical_reach(n), loop_body.lexical_reach(n)].max
end

#to_sObject



50
51
52
# File 'lib/nydp/loop.rb', line 50

def to_s
  "(loop #{condition.to_s} #{loop_body.to_s})"
end