extend calc records and expressions to inputs A-U

This commit is contained in:
2025-05-22 16:34:16 +02:00
parent 1804bcef7d
commit 45ea3d5664
11 changed files with 457 additions and 54 deletions

View File

@@ -18,7 +18,7 @@ stringchar [^"\n\\]
name [a-zA-Z0-9_\-+:.\[\]<>;]
digit [0-9]
punctuation [(){},]
link [A-L]
link [A-U]
%{
static ASINPUTFUNCPTR *my_yyinput;

View File

@@ -86,6 +86,15 @@ LIBCOM_API long
case FETCH_J:
case FETCH_K:
case FETCH_L:
case FETCH_M:
case FETCH_N:
case FETCH_O:
case FETCH_P:
case FETCH_Q:
case FETCH_R:
case FETCH_S:
case FETCH_T:
case FETCH_U:
*++ptop = parg[op - FETCH_A];
break;
@@ -101,6 +110,15 @@ LIBCOM_API long
case STORE_J:
case STORE_K:
case STORE_L:
case STORE_M:
case STORE_N:
case STORE_O:
case STORE_P:
case STORE_Q:
case STORE_R:
case STORE_S:
case STORE_T:
case STORE_U:
parg[op - STORE_A] = *ptop--;
break;
@@ -441,6 +459,15 @@ calcArgUsage(const char *pinst, unsigned long *pinputs, unsigned long *pstores)
case FETCH_J:
case FETCH_K:
case FETCH_L:
case FETCH_M:
case FETCH_N:
case FETCH_O:
case FETCH_P:
case FETCH_Q:
case FETCH_R:
case FETCH_S:
case FETCH_T:
case FETCH_U:
/* Don't claim to use an arg we already stored to */
inputs |= (1 << (op - FETCH_A)) & ~stores;
break;
@@ -457,6 +484,15 @@ calcArgUsage(const char *pinst, unsigned long *pinputs, unsigned long *pstores)
case STORE_J:
case STORE_K:
case STORE_L:
case STORE_M:
case STORE_N:
case STORE_O:
case STORE_P:
case STORE_Q:
case STORE_R:
case STORE_S:
case STORE_T:
case STORE_U:
stores |= (1 << (op - STORE_A));
break;

View File

@@ -117,20 +117,29 @@ static const ELEMENT operands[] = {
{"LN", 7, 8, 0, UNARY_OPERATOR, LOG_E},
{"LOG", 7, 8, 0, UNARY_OPERATOR, LOG_10},
{"LOGE", 7, 8, 0, UNARY_OPERATOR, LOG_E},
{"M", 0, 0, 1, OPERAND, FETCH_M},
{"MAX", 7, 8, 0, VARARG_OPERATOR,MAX},
{"MIN", 7, 8, 0, VARARG_OPERATOR,MIN},
{"N", 0, 0, 1, OPERAND, FETCH_N},
{"NINT", 7, 8, 0, UNARY_OPERATOR, NINT},
{"NAN", 0, 0, 1, LITERAL_OPERAND,LITERAL_DOUBLE},
{"NOT", 7, 8, 0, UNARY_OPERATOR, BIT_NOT},
{"O", 0, 0, 1, OPERAND, FETCH_O},
{"P", 0, 0, 1, OPERAND, FETCH_P},
{"PI", 0, 0, 1, OPERAND, CONST_PI},
{"Q", 0, 0, 1, OPERAND, FETCH_Q},
{"R", 0, 0, 1, OPERAND, FETCH_R},
{"R2D", 0, 0, 1, OPERAND, CONST_R2D},
{"RNDM", 0, 0, 1, OPERAND, RANDOM},
{"S", 0, 0, 1, OPERAND, FETCH_S},
{"SIN", 7, 8, 0, UNARY_OPERATOR, SIN},
{"SINH", 7, 8, 0, UNARY_OPERATOR, SINH},
{"SQR", 7, 8, 0, UNARY_OPERATOR, SQU_RT},
{"SQRT", 7, 8, 0, UNARY_OPERATOR, SQU_RT},
{"T", 0, 0, 1, OPERAND, FETCH_T},
{"TAN", 7, 8, 0, UNARY_OPERATOR, TAN},
{"TANH", 7, 8, 0, UNARY_OPERATOR, TANH},
{"U", 0, 0, 1, OPERAND, FETCH_U},
{"VAL", 0, 0, 1, OPERAND, FETCH_VAL},
{"~", 7, 8, 0, UNARY_OPERATOR, BIT_NOT},
};
@@ -287,7 +296,7 @@ LIBCOM_API long
case STORE_OPERATOR:
if (pout == pdest || pstacktop > stack ||
*--pout < FETCH_A || *pout > FETCH_L) {
*--pout < FETCH_A || *pout >= FETCH_A + CALCPERFORM_NARGS) {
*perror = CALC_ERR_BAD_ASSIGNMENT;
goto bad;
}
@@ -549,9 +558,13 @@ LIBCOM_API void
"LITERAL_DOUBLE", "LITERAL_INT", "VAL",
"FETCH_A", "FETCH_B", "FETCH_C", "FETCH_D", "FETCH_E", "FETCH_F",
"FETCH_G", "FETCH_H", "FETCH_I", "FETCH_J", "FETCH_K", "FETCH_L",
"FETCH_M", "FETCH_N", "FETCH_O", "FETCH_P", "FETCH_Q", "FETCH_R",
"FETCH_S", "FETCH_T", "FETCH_U",
/* Assignment */
"STORE_A", "STORE_B", "STORE_C", "STORE_D", "STORE_E", "STORE_F",
"STORE_G", "STORE_H", "STORE_I", "STORE_J", "STORE_K", "STORE_L",
"STORE_M", "STORE_N", "STORE_O", "STORE_P", "STORE_Q", "STORE_R",
"STORE_S", "STORE_T", "STORE_U",
/* Trigonometry Constants */
"CONST_PI",
"CONST_D2R",

View File

@@ -22,8 +22,8 @@
#include "libComAPI.h"
/** \brief Number of input arguments to a calc expression (A-L) */
#define CALCPERFORM_NARGS 12
/** \brief Number of input arguments to a calc expression (A-U) */
#define CALCPERFORM_NARGS 21
/** \brief Size of the internal partial result stack */
#define CALCPERFORM_STACK 80
@@ -163,11 +163,11 @@ extern "C" {
*
* -# ***Variables***
* Variables are used to provide inputs to an expression, and are named
* using the single letters A through L inclusive or the keyword VAL which
* using the single letters A through U inclusive or the keyword VAL which
* refers to the previous result of this calculation. The software that
* makes use of the expression evaluation code should document how the
* individual variables are given values; for the calc record type the input
* links INPA through INPL can be used to obtain these from other record fields,
* links INPA through INPU can be used to obtain these from other record fields,
* and VAL refers to the the VAL field (which can be overwritten from outside
* the record via Channel Access or a database link).
*
@@ -310,7 +310,7 @@ LIBCOM_API long
*
* Evaluates the postfix expression against a set ot input values.
*
* \param parg Pointer to an array of double values for the arguments A-L
* \param parg Pointer to an array of double values for the arguments A-U
* that can appear in the expression. Note that the argument values may be
* modified if the expression uses the assignment operator.
* \param presult Where to put the calculated result, which may be a NaN or Infinity.
@@ -331,8 +331,8 @@ LIBCOM_API long
* for either of these pointers is legal if only the other is needed.
*
* The least significant bit (bit 0) of the bitmap at \c *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
* if the expression depends on the argument A, and so on through bit 20 for
* the argument U. 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.

View File

@@ -13,7 +13,7 @@
*/
/* Notes:
* 1. The FETCH_A through FETCH_L and STORE_A through STORE_L opcodes must
* 1. The FETCH_A through FETCH_U and STORE_A through STORE_U opcodes must
* be contiguous.
* 2. The LITERAL opcodes are followed by a binary representation of their
* values, but these are not aligned properly.
@@ -34,9 +34,13 @@ typedef enum {
LITERAL_DOUBLE, LITERAL_INT, FETCH_VAL,
FETCH_A, FETCH_B, FETCH_C, FETCH_D, FETCH_E, FETCH_F,
FETCH_G, FETCH_H, FETCH_I, FETCH_J, FETCH_K, FETCH_L,
FETCH_M, FETCH_N, FETCH_O, FETCH_P, FETCH_Q, FETCH_R,
FETCH_S, FETCH_T, FETCH_U,
/* Assignment */
STORE_A, STORE_B, STORE_C, STORE_D, STORE_E, STORE_F,
STORE_G, STORE_H, STORE_I, STORE_J, STORE_K, STORE_L,
STORE_M, STORE_N, STORE_O, STORE_P, STORE_Q, STORE_R,
STORE_S, STORE_T, STORE_U,
/* Trigonometry Constants */
CONST_PI,
CONST_D2R,