# All files / src/generator table.js

100% Statements 12/12
83.33% Branches 5/6
100% Functions 2/2
100% Lines 12/12

    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
    21x
    21x

    2x

    2x

    5x
    5x
    2x
    3x
    2x
    1x
    1x

    2x

     // @flow
    import Syntax from "../Syntax";
    import walkNode from "../utils/walk-node";
    import type { NodeType, IntermediateTableType } from "./flow/types";

    export default function generateMemory(node: NodeType): IntermediateTableType {
      const table = { max: 0, initial: 0, type: "" };

      walkNode({
        [Syntax.Pair]: ({ params }) => {
          // This could procude garbage values but that is a fault of the source code
          const [{ value: key }, { value }] = params;
          if (key === "initial") {
            table.initial = parseInt(value);
          } else if (key === "element") {
            table.type = value;
          } else Eif (key === "max") {
            table.max = parseInt(value);
          }
        },
      })(node);

      return table;
    }