Calling Functions

Functions may be called either from within the same scope as the calling function, or from a higher level, containing scope. For example, a LOCAL function can call functions declared in the containing INTERNAL scope and from the GLOBAL scope, but not vice-versa. One consequence of this is that it is not possible to make any function calls between XJEase device files.

XJEase function calls in statements

To call a function, the following syntax can be used:

functionName( inputExpressions )( outputVariables );

The inputExpressions arguments are evaluated and passed into the function's input parameters. The outputVariables receive the values assigned to the output parameters by the function. The inputs and outputs must be of the same types as those in the function definition. If the function call does not require any return parameters, the second set of brackets may be omitted.

Example

GLOBAL Test()()
  INT value := 10;
  INT result;

  // call function without any output parameters
  Function1(value);

  // call function with an input and output
  Function2(value + 1)(result);

  // result should now equal 11
  // value will still be 10
END;

LOCAL Function1(INT value)()
  PRINT("Value: ", value, "\n");
END;

LOCAL Function2(INT value)(INT result)
  result := value;

  // input parameters can be treated like local variables
  value := 0;
END;

XJEase function calls in expressions

If a function has a single return argument, it can also be used in an expression. The value returned from the function is then used in the expression.

A function being called in an expression must have been either defined or declared before the call. Functions can be declared before they are defined by using DECLARE.

Example

LOCAL Square(INT value)(INT result)
  result := value * value;
END;

GLOBAL Test()()
  INT value := Square(3);

  // value will now contain the value 9
END;

Calling functions in device files

GLOBAL functions in device files can be called from Circuit Code Files. This is useful when a test needs to access more than once device, so can't be written inside a device file. Because a device file can be assigned to more than one device, the device on which to call the function needs to be specified, and so a special CALL function is used.

CALL ( STRING deviceReference, STRING functionName )( inputExpressions )( outputVariables );

See the CALL function for a more detailed description.