![]() |
This is Unofficial EPICS BASE Doxygen Site
|
The API for the EPICS Calculation Engine. More...
#include "libComAPI.h"
Go to the source code of this file.
Macros | |
#define | CALCPERFORM_NARGS 12 |
Number of input arguments to a calc expression (A-L) More... | |
#define | CALCPERFORM_STACK 80 |
Size of the internal partial result stack. More... | |
Postfix and Infix Buffer Sizes | |
#define | INFIX_TO_POSTFIX_SIZE(n) ((n)*21/6) |
Calculate required size of postfix buffer from infix. More... | |
#define | MAX_INFIX_SIZE 100 |
Size of a "standard" infix string. More... | |
#define | MAX_POSTFIX_SIZE INFIX_TO_POSTFIX_SIZE(MAX_INFIX_SIZE) |
Size of a "standard" postfix buffer. More... | |
Calc Engine Error Codes | |
| |
#define | CALC_ERR_NONE 0 |
No error. More... | |
#define | CALC_ERR_TOOMANY 1 |
Too many results returned. More... | |
#define | CALC_ERR_BAD_LITERAL 2 |
Bad numeric literal. More... | |
#define | CALC_ERR_BAD_ASSIGNMENT 3 |
Bad assignment target. More... | |
#define | CALC_ERR_BAD_SEPERATOR 4 |
Comma without parentheses. More... | |
#define | CALC_ERR_PAREN_NOT_OPEN 5 |
Close parenthesis without open. More... | |
#define | CALC_ERR_PAREN_OPEN 6 |
Open parenthesis at end of expression. More... | |
#define | CALC_ERR_CONDITIONAL 7 |
Unbalanced conditional ?: operators. More... | |
#define | CALC_ERR_INCOMPLETE 8 |
Incomplete expression, operand missing. More... | |
#define | CALC_ERR_UNDERFLOW 9 |
Runtime stack would underflow. More... | |
#define | CALC_ERR_OVERFLOW 10 |
Runtime stack would overflow. More... | |
#define | CALC_ERR_SYNTAX 11 |
Syntax error. More... | |
#define | CALC_ERR_NULL_ARG 12 |
NULL or empty input argument. More... | |
#define | CALC_ERR_INTERNAL 13 |
Internal error, bad element type. More... | |
Functions | |
LIBCOM_API long | postfix (const char *pinfix, char *ppostfix, short *perror) |
Compile an infix expression into postfix byte-code. More... | |
LIBCOM_API long | calcPerform (double *parg, double *presult, const char *ppostfix) |
Run the calculation engine. More... | |
LIBCOM_API long | calcArgUsage (const char *ppostfix, unsigned long *pinputs, unsigned long *pstores) |
Find the inputs and outputs of an expression. More... | |
LIBCOM_API const char * | calcErrorStr (short error) |
Convert an error code to a string. More... | |
LIBCOM_API void | calcExprDump (const char *pinst) |
Disassemble a postfix expression. More... | |
The API for the EPICS Calculation Engine.
Defines macros and the routines provided by the calculation engine for subsystems that need to evaluate mathematical expressions.
Definition in file postfix.h.
#define CALC_ERR_BAD_SEPERATOR 4 |
#define CALC_ERR_CONDITIONAL 7 |
#define CALC_ERR_INCOMPLETE 8 |
#define CALC_ERR_INTERNAL 13 |
#define CALC_ERR_NULL_ARG 12 |
#define CALC_ERR_OVERFLOW 10 |
#define CALC_ERR_PAREN_NOT_OPEN 5 |
#define CALC_ERR_PAREN_OPEN 6 |
#define CALC_ERR_UNDERFLOW 9 |
#define CALCPERFORM_NARGS 12 |
#define CALCPERFORM_STACK 80 |
#define INFIX_TO_POSTFIX_SIZE | ( | n | ) | ((n)*21/6) |
Calculate required size of postfix buffer from infix.
This macro calculates the maximum size of postfix buffer needed for an infix expression buffer of a given size. The argument n
must count the trailing nil byte in the input expression string. The actual size needed is never larger than this value, although it is actually a few bytes smaller for some sizes.
The maximum expansion from infix to postfix is for the sub-expression
which is 6 characters long and results in 21 bytes of postfix:
For other short expressions the factor 21/6 always gives a big enough postfix buffer (proven by hand, look at '1+' and '.1+' as well).
#define MAX_INFIX_SIZE 100 |
#define MAX_POSTFIX_SIZE INFIX_TO_POSTFIX_SIZE(MAX_INFIX_SIZE) |
LIBCOM_API long calcArgUsage | ( | const char * | ppostfix, |
unsigned long * | pinputs, | ||
unsigned long * | pstores | ||
) |
Find the inputs and outputs of an expression.
Software using the calc subsystem may need to know what expression arguments are used and/or modified by a particular expression. It can discover this from the postfix string by calling calcArgUsage(), which takes two pointers pinputs
and pstores
to a pair of unsigned long bitmaps which return that information to the caller. Passing a NULL value for either of these pointers is legal if only the other is needed.
The least signficant bit (bit 0) of the bitmap at *pinputs
will be set if the expression depends on the argument A, and so on through bit 11 for the argument L. An argument that is not used until after a value has been assigned to it will not be set in the pinputs bitmap, thus the bits can be used to determine whether a value needs to be supplied for their associated argument or not for the purposes of evaluating the expression.
Bit 0 of the bitmap at *pstores
will be set if the expression assigns a value to the argument A, bit 1 for argument B etc.
ppostfix | A postfix expression created by postfix(). |
pinputs | Bitmap pointer. |
pstores | Bitmap pointer. |
Definition at line 405 of file calcPerform.c.
LIBCOM_API const char* calcErrorStr | ( | short | error | ) |
Convert an error code to a string.
Gives out a printable version of an individual error code. The error codes are macros defined here with names starting CALC_ERR_
error | Error code |
Definition at line 493 of file postfix.c.
LIBCOM_API void calcExprDump | ( | const char * | pinst | ) |
Disassemble a postfix expression.
Convert the byte-code stream to text and print to stdout.
pinst | postfix instructions |
Definition at line 523 of file postfix.c.
LIBCOM_API long calcPerform | ( | double * | parg, |
double * | presult, | ||
const char * | ppostfix | ||
) |
Run the calculation engine.
Evaluates the postfix expression against a set ot input values.
parg | Pointer to an array of double values for the arguments A-L that can appear in the expression. Note that the argument values may be modified if the expression uses the assignment operator. |
presult | Where to put the calculated result, which may be a NaN or Infinity. |
ppostfix | The postfix expression created by postfix(). |
Definition at line 45 of file calcPerform.c.
LIBCOM_API long postfix | ( | const char * | pinfix, |
char * | ppostfix, | ||
short * | perror | ||
) |
Compile an infix expression into postfix byte-code.
Converts an expression from an infix string to postfix byte-code
pinfix | Pointer to the infix string |
ppostfix | Pointer to the postfix buffer |
perror | Place to return an error code |
It is the callers's responsibility to ensure that ppostfix
points to sufficient storage to hold the postfix expression. The macro INFIX_TO_POSTFIX_SIZE(n) can be used to calculate an appropriate postfix buffer size from the length of the infix buffer.
***Arithmetic Operators*** The usual binary arithmetic operators are provided: + - * and / with their usual relative precedence and left-to-right associativity, and - may also be used as a unary negate operator where it has a higher precedence and associates from right to left. There is no unary plus operator, so numeric literals cannot begin with a + sign.
Three other binary operators are also provided: % is the integer modulo operator, while the synonymous operators ** and ^ raise their left operand to the power of the right operand. % has the same precedence and associativity as * and /, while the power operators associate left-to-right and have a precedence in between * and unary minus.
Definition at line 209 of file postfix.c.