P6C::Util -- General utilities ^

This is a grab-bag of functions that are generally useful during compilation, a haven for refugees from IMCC.pm's madness.

unimp(@_)

Complain that something is unimplemented, and die.

diag(@_)

Issue a diagnostic message, but keep going.

error(@_)

A recent addition to the family. A fatal error has occurred, and it is the user's fault.

warning(@_)

warning is to error as diag is to unimp -- it indicates a possible non-fatal user error.

@items = flatten_leftop($tree, $opname)

Flatten $tree, a binary operator tree, into a sequence of items that were once the right- and left-hand operands of that operator. Only works if the indicated operator is the lowest-precedence operator in the tree. So (1,(2,(3,4))) becomes (1 2 3 4). Yes, this is undoing what we so laboriously did in Tree.pm turning <leftop:...> sequences into trees.

map_preorder(BLOCK, @trees)

Call BLOCK at each node of each tree in @trees, processing parents before children. The current node will be in $_.

map_postorder(BLOCK, @trees)

Call BLOCK at each node of each tree in @trees, processing parents after children. The current node will be in $_.

is_scalar($type)

True if $type is scalar.

is_pmc($type)

True if $type is a PMC type. Useful to know when you have to clone something, and when you can just set it.

is_array_expr($expr)

True if $expr looks like an array expression. This is just a guess for now -- if it says something is an array, then it definitely is, but if it says no, the caller should be conservative in the appropriate direction.

same_type($a, $b)

True if type $a and type $b are compatible. This is a hack that errs on the conservative side.


parrot