SMOP Code Implementation


Code is the object responsible for invoking a specific chunk of code inside a specific lexical scope. Every code object has an "outer scope", which may be the file's scope.

In Perl 6, every block is a closure, so the Code object can only be initialized with the proper outer scope that is dinamically defined when the containing block is executed.

Every block also has a Signature, the default block signature is ($_ is rw = OUTER::<$_>), as discussed in SMOP Lexical Scope Implementation.

The current implementation of block uses mold as the "source code".

Modelling

This is the structure of the Code object.

class Code {
  has $.outer;
  has $.signature = :($_ is rw = OUTER::<$_>);
  has Mold $.mold;
  method postcircumfix:<()> ($invocation_capture) {
    my $inner_scope = LexicaScope.new();
    $inner_scope.outer = $.outer;
    $.signature.BIND($invocation_capture, $inner_scope);
    my $frame = MoldFrame.new($.mold);
    $frame.set_reg(0, $inner_scope);
    $frame();
  }
}