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.


Complain that something is unimplemented, and die.


Issue a diagnostic message, but keep going.


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


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 $_.


True if $type is scalar.


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


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.