All files / TRANSPILE/3-Render/codegen/types IPlannedFor.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                                                                 
import type IPlannedForAssignment from "./IPlannedForAssignment";
import type IPlannedForVarDecl from "./IPlannedForVarDecl";
 
/**
 * A `for` header and its body.
 *
 * Every render is a thunk, and that is the whole contract of this record.
 * Issue #250 hoists the temps each clause queues out in front of the loop, and
 * it does so by flushing between clauses: init, flush, condition, flush,
 * update, flush, body. A temp that is not flushed before the next clause
 * renders lands in the wrong group, and one not flushed before the BODY lands
 * inside the loop -- declared where the header that reads it cannot see it.
 * Rendering any clause at plan time collapses those four flush points.
 *
 * `for (;;)` never reaches codegen -- it is E0707 in pass 2.1 (ADR-068) -- so
 * the condition is always present and is not nullable here.
 */
interface IPlannedFor {
  /** The init clause, absent in `for (; i < n; i +<- 1)`. */
  readonly init: TPlannedForInit | null;
  readonly renderCondition: () => string;
  /** The update clause, absent in `for (u32 i <- 0; i < n;)`. */
  readonly update: IPlannedForAssignment | null;
  readonly renderBody: () => string;
}
 
/** A `for` init is either a declaration or an assignment to something existing. */
type TPlannedForInit =
  | { readonly kind: "varDecl"; readonly plan: IPlannedForVarDecl }
  | { readonly kind: "assignment"; readonly plan: IPlannedForAssignment };
 
export default IPlannedFor;