All files / src/generator table.js

100% Statements 13/13
100% Branches 3/3
100% Functions 2/2
100% Lines 13/13
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  21x 21x       3x   3x     7x 7x   3x 3x   3x 3x   1x 1x         3x    
// @flow
import Syntax from 'walt-syntax';
import walkNode from 'walt-parser-tools/walk-node';
import type { NodeType, IntermediateTableType } from './flow/types';
 
export default function generateMemory(node: NodeType): IntermediateTableType {
  const table = { max: 0, initial: 0, type: 'element' };
 
  walkNode({
    [Syntax.Pair]: ({ params }) => {
      // This could produce garbage values but that is a fault of the source code
      const [{ value: key }, { value }] = params;
      switch (key) {
        case 'initial':
          table.initial = parseInt(value);
          break;
        case 'element':
          table.type = value;
          break;
        case 'max':
          table.max = parseInt(value);
          break;
      }
    },
  })(node);
 
  return table;
}