class Savi::Compiler::Macros

Overview

The purpose of the Macros pass is to parse and expand semantic forms that may be more context-sensitive/dynamic than those parsed in the parser itself. Eventually we wish to allow the user code to register this macro logic in the earlier passes of evaluation in the compiler, to make them fully dynamic. This is not possible yet, as all macros are hard-coded here in the compiler.

This pass uses copy-on-mutate patterns to "mutate" the Program topology. This pass uses copy-on-mutate patterns to "mutate" the AST. This pass may raise a compilation error. This pass keeps temporary state at the per-function level. This pass produces no output state.

Defined in:

savi/compiler/macros.cr

Constructors

Class Method Summary

Instance Method Summary

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

visit(ctx : Compiler::Context, node : Node) visit, visit_any?(ctx : Compiler::Context, node : Node) visit_any?, visit_children?(ctx : Compiler::Context, node : Node) visit_children?, visit_pre(ctx : Compiler::Context, node : Node) visit_pre

Constructor Detail

def self.new(func : Program::Function) #

[View source]

Class Method Detail

def self.cached_or_run(ctx, l, t, f, &) : Program::Function #

[View source]
def self.run(ctx, package) #

[View source]

Instance Method Detail

def build_assert_has_error(node : AST::Relate, expr : AST::Node, expects_error : Bool) #

[View source]

[View source]
def maybe_compiler_intrinsic #

[View source]
def next_local_name #

[View source]
def run(ctx) #

[View source]
def visit_assert(node : AST::Relate, expr : AST::Relate) #

The #visit_assert methods compiles different forms of the assert macro. The expression to evaluate is the rhs of the assert: expr Relate node.

When the expression itself contains operators it will compile into Spec.Assert.relation.

assert: True == True assert: foo || bar && baz

When the relation uses the <: and !<: operator the assert is compiled into a special Spec.Assert.type_relation method.

When the expression is any other kind of node it will compile into a Spec.Assert.condition.

assert: True assert: Something.foo


[View source]
def visit_assert(node : AST::Relate, expr : AST::Node) #

[View source]
def visit_assert_error(node : AST::Relate, expr : AST::Node) #

[View source]
def visit_assert_no_error(node : AST::Relate, expr : AST::Node) #

[View source]
def visit_assert_type_relation(node : AST::Relate, expr : AST::Relate) #

[View source]
def visit_case(node : AST::Group) #

[View source]
def visit_case_relate(orig : AST::Node, node : AST::Relate) #

[View source]
def visit_conditional_jump(node : AST::Group, kind : AST::Jump::Kind, cond : AST::Term, term : AST::Term | Nil = nil, negate : Bool = false) #

[View source]
def visit_conditional_yield(node : AST::Group, cond : AST::Term, negate : Bool = false) #

[View source]
def visit_identity_digest_of(node : AST::Group) #

[View source]
def visit_if(node : AST::Group) #

[View source]
def visit_jump(node : AST::Group, kind : AST::Jump::Kind) #

[View source]
def visit_pre(ctx, node : AST::Group) #

[View source]
def visit_pre(ctx, node : AST::Call) #

[View source]
def visit_pre(ctx, node : AST::Relate) #

[View source]
def visit_pre(ctx, node : AST::ComposeString) #

[View source]
def visit_reflection_of_runtime_type_name(node : AST::Group) #

[View source]
def visit_reflection_of_type(node : AST::Group) #

[View source]
def visit_source_code_position_of_argument(node : AST::Group) #

[View source]
def visit_stack_address_of_variable(node : AST::Group) #

[View source]
def visit_static_address_of_function(node : AST::Group) #

[View source]
def visit_try(node : AST::Group) #

[View source]
def visit_unconditional_jump(node : AST::Group, kind : AST::Jump::Kind) #

[View source]
def visit_unconditional_yield(node : AST::Group) #

[View source]
def visit_while(node : AST::Group) #

[View source]
def visit_yield(node : AST::Group) #

[View source]