All files / src/generator declaration.js

100% Statements 12/12
100% Branches 4/4
100% Functions 1/1
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 26 27 28 29 30 31  22x 22x 22x 22x 22x     22x 104x   104x 101x   101x   101x                   3x        
// @flow
import { i32 } from 'walt-syntax';
import generateExpression from './expression';
import { isBuiltinType } from './utils';
import opcode from '../emitter/opcode';
import { LOCAL_INDEX } from '../semantics/metadata';
import type { GeneratorType } from './flow/types';
 
const generateDeclaration: GeneratorType = (node, parent) => {
  const initNode = node.params[0];
 
  if (initNode) {
    const metaIndex = node.meta[LOCAL_INDEX];
 
    const type = isBuiltinType(node.type) ? node.type : i32;
 
    return [
      ...generateExpression({ ...initNode, type }, parent),
      {
        kind: opcode.SetLocal,
        params: [metaIndex],
        debug: `${node.value}<${String(node.type)}>`,
      },
    ];
  }
 
  return [];
};
 
export default generateDeclaration;