All files / src/generator memory.js

100% Statements 8/8
100% Branches 0/0
100% Functions 2/2
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  21x 21x     21x 9x 9x     10x 10x       9x        
// @flow
import Syntax from 'walt-syntax';
import walkNode from 'walt-parser-tools/walk-node';
import type { NodeType, IntermediateMemoryType } from './flow/types';
 
const generateMemory = (node: NodeType): IntermediateMemoryType => {
  const memory = { max: 0, initial: 0 };
  walkNode({
    [Syntax.Pair]: ({ params }) => {
      // This could produce garbage values but that is a fault of the source code
      const [{ value: key }, { value }] = params;
      memory[key] = parseInt(value);
    },
  })(node);
 
  return memory;
};
 
export default generateMemory;