(array: *[..] $T, item: T)
Adds item to array unless it is zero.
#import "Code_Visit";
Walks the nodes of a Compiler.Code_Node tree.
Compiler :: #import "Compiler";
left := Compiler.make_integer_literal(13);
right := Compiler.make_integer_literal(29);
sum: Compiler.Code_Binary_Operator;
sum.kind = .BINARY_OPERATOR;
sum.left = left;
sum.right = right;
all: [..] *Compiler.Code_Node;
get_recursive_nodes_depth_first(*sum, *all);
assert(all.count == 3);Adds item to array unless it is zero.
Appends the direct children of node to pointers, in source order.
Compiler :: #import "Compiler";
left := Compiler.make_integer_literal(13);
right := Compiler.make_integer_literal(29);
sum: Compiler.Code_Binary_Operator;
sum.kind = .BINARY_OPERATOR;
sum.left = left;
sum.right = right;
children: [..] *Compiler.Code_Node;
get_subexpressions(*sum, *children);
assert(children.count == 2 && children[0] == cast(*Compiler.Code_Node) left);↗Appends node and everything below it to pointers, one level at a time. Each node is added once.
Compiler :: #import "Compiler";
n := Compiler.make_integer_literal(7);
all: [..] *Compiler.Code_Node;
get_recursive_nodes_breadth_first(cast(*Compiler.Code_Node) n, *all);
assert(all.count == 1);↗Like get_recursive_nodes_breadth_first, but follows each child's subtree to the end before moving to the next child.
Compiler :: #import "Compiler";
n := Compiler.make_integer_literal(7);
all: [..] *Compiler.Code_Node;
get_recursive_nodes_depth_first(cast(*Compiler.Code_Node) n, *all);
assert(all.count == 1);↗Walks node depth first and appends a Dumb_Value when it enters each node (preorder true) and again when it leaves (preorder false).
Compiler :: #import "Compiler";
n := Compiler.make_integer_literal(7);
events: [..] Dumb_Value;
get_values(cast(*Compiler.Code_Node) n, *events);
assert(events.count == 2 && events[0].preorder && !events[1].preorder);↗One step of a get_values walk: the node, and whether the walk is entering it (preorder) or leaving it.