Variable Widths

An attempt to assign a wider value to a fixed width integer at its declaration will generate a syntax error. If the width of the assigned value cannot be determined at compile time, then it will be truncated to the correct width when it is assigned at runtime.

A wider value may be assigned to a variable with a defined width after it is has been declared and the variable will be made wider to accomodate the value.

Example

GLOBAL Test()(INT result)
  // This will generate an error about the different lengths
  INT x WIDTH 8 := 0x1FF;
  // Whereas this will not
  INT y WIDTH 8 := 0x1FF[7..0];
END;

GLOBAL INT GlobalValue := 0xFF;

GLOBAL Test2()(INT result)
  // Assuming GlobalValue still holds the value 0xFF when this function is run,
  // the value will be truncated to 3 bits wide at runtime, and so x will be initialised to 7.
  INT x WIDTH 3 := GlobalValue;

  // No checking of the width is done after the variable's declaration and so x
  // will have the whole value of GlobalValue assigned to it
  x := GlobalValue;

  // To retain x's width of 3, any assignment should select the bits explicitly
  x := GlobalValue[2..0];
END;