class Savi::AST::Loop

Overview

A Loop node indicates a looping flow control, with a #body Term which may be executed zero or more times. The #initial_cond Term is evaluated once at the start to determine whether any looping should be done. After the first execution of the #body Term, then the #repeat_cond Term is evaluated to determine whether looping will continue. If the #initial_cond returned False, the result value of the loop is the result of evaluating the #else_body Term; otherwise, the result of the final execution of the #body Term will be used as the result value. In simple cases, the #repeat_cond is the same as the #initial_cond and the #else_body just returns a simple value of the None module.

This is an internal AST type which has no corresponding source code syntax, because such a construct is only created inside macro expansions.

However, the most obvious example of use is in the while macro.

Defined in:

savi/ast.cr

Constructors

Instance Method Summary

Instance methods inherited from class Savi::AST::Node

accept(ctx : Compiler::Context, visitor : Visitor)
accept(ctx : Compiler::Context, visitor : CopyOnMutateVisitor)
accept
, annotations : Array(Annotation) | Nil annotations, annotations=(annotations : Array(Annotation) | Nil) annotations=, children_accept(ctx : Compiler::Context, visitor : Visitor)
children_accept(ctx : Compiler::Context, visitor : CopyOnMutateVisitor)
children_accept
, from(other : Node) from, pos pos, pos? : Savi::Source::Pos? pos?, span_pos(source) span_pos, with_pos(pos : Source::Pos) with_pos

Constructor Detail

def self.new(initial_cond : Savi::AST::Node, body : Savi::AST::Node, repeat_cond : Savi::AST::Node, else_body : Savi::AST::Node) #

[View source]

Instance Method Detail

def body : Term #

[View source]
def body=(body : Term) #

[View source]
def children_accept(ctx : Compiler::Context, visitor : Visitor) #

[View source]
def children_accept(ctx : Compiler::Context, visitor : CopyOnMutateVisitor) #

[View source]
def else_body : Term #

[View source]
def else_body=(else_body : Term) #

[View source]
def initial_cond : Term #

[View source]
def initial_cond=(initial_cond : Term) #

[View source]
def name #

[View source]
def repeat_cond : Term #

[View source]
def repeat_cond=(repeat_cond : Term) #

[View source]
def span_pos(source) #

[View source]
def to_a : Array(A) #

[View source]