(ast: SchemaAST.Arrays)
| 2563 | } |
| 2564 | |
| 2565 | function compileArray(ast: SchemaAST.Arrays): ArrayLayout { |
| 2566 | const hasCount = ast.rest.length > 0 || ast.elements.some((e) => e.context?.isOptional === true) |
| 2567 | const requiredElements = ast.elements.filter((e) => e.context?.isOptional !== true).length |
| 2568 | const tailLen = Math.max(0, ast.rest.length - 1) |
| 2569 | const layout: ArrayLayout = { |
| 2570 | _: "array", |
| 2571 | ast, |
| 2572 | elements: [], |
| 2573 | rest: [], |
| 2574 | hasCount, |
| 2575 | minCount: requiredElements + tailLen, |
| 2576 | uniform: undefined, |
| 2577 | uniformInline: false, |
| 2578 | uniformPacked: undefined, |
| 2579 | uniformNumbers: false, |
| 2580 | run: undefined |
| 2581 | } |
| 2582 | memo.set(ast, layout) |
| 2583 | for (const element of ast.elements) { |
| 2584 | layout.elements.push({ |
| 2585 | optional: element.context?.isOptional === true, |
| 2586 | layout: compile(element) |
| 2587 | }) |
| 2588 | } |
| 2589 | for (const rest of ast.rest) { |
| 2590 | layout.rest.push(compile(rest)) |
| 2591 | } |
| 2592 | if (layout.elements.length === 0 && layout.rest.length === 1) { |
| 2593 | const slot = layout.rest[0] |
| 2594 | layout.uniform = slot |
| 2595 | layout.uniformPacked = packedSize(slot) |
| 2596 | layout.uniformNumbers = slot._ === "number" |
| 2597 | layout.uniformInline = isInlineSlot(slot) |
| 2598 | } |
| 2599 | return layout |
| 2600 | } |
| 2601 | |
| 2602 | function compileDeclaration(ast: SchemaAST.Declaration): Layout { |
| 2603 | const id = representationId(ast) |
no test coverage detected