P6C::Context ^

Represents a semantic context.

A Context object supports the following operations:

$x = type($ctx)

type($ctx, $x)

Get or set the context type, which may be either:

$x = flatten($ctx)

flatten($ctx, $x)

Get or set the flattening property, corresponding to the * prefix operator. Flattening contexts are also created implicitly in a number of places, such as when passing parameters to a sub with no parameter list, and when assigning to an array.

When a context is "flattening", its elements are evaluated in PerlArray context, and the results are concatenated. This is wasteful, as it builds up a temporary array for each item. It would be more efficient to have each element just append its results to the final array, but this is harder.

$x = hype($ctx)

hype($ctx, $x)

Get or set hyper-operating context property, corresponding to a ^ on an adjacent operator. Currently unused, as it's easier to just brute-force hyper-operation during code generation.

nelem($ctx)

Return the number of items wanted in $ctx. For scalars, one, for arrays, undef, for lists/tuples, the number of elements in the tuple.

is_scalar($ctx)

is_tuple($ctx)

is_array($ctx)

is_sig($ctx)

True if the type($ctx) is some kind of scalar, tuple, array, or function signature.

copy($ctx)

Return a copy of $ctx.

same($ctx, $ctx2)

Return true if $ctx and $ctx are "the same".

P6C::Context also defines the following variables:

$DEFAULT_ARGUMENT_CONTEXT

Flattening array context for subs with no parameter declaration.

%CONTEXT

The hash %P6C::Context::CONTEXT maps operator names to Contexts or, in a few messy cases, code refs. Infix and suffix operators are named "infix X" and "suffix X" where X is the operator symbol. The messy cases include things like if, which don't play well with our current notion of context. I'm not sure if can ever really be handled in a standard way, since it takes an arbitrary number of parameters of particular types.


parrot