2 * $Id: eval.h,v 1.26 2006/07/21 05:19:51 sfeam Exp $
8 * Copyright 1999, 2004 Thomas Williams, Colin Kelley
10 * Permission to use, copy, and distribute this software and its
11 * documentation for any purpose with or without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and
13 * that both that copyright notice and this permission notice appear
14 * in supporting documentation.
16 * Permission to modify the software is granted, but not the right to
17 * distribute the complete modified source code. Modifications are to
18 * be distributed as patches to the released version. Permission to
19 * distribute binaries produced by compiling modified sources is granted,
21 * 1. distribute the corresponding source modifications from the
22 * released version in the form of a patch file along with the binaries,
23 * 2. add special version identification to distinguish your version
24 * in addition to the base release version number,
25 * 3. provide your name and address as the primary contact for the
26 * support of your modified version, and
27 * 4. retain our contact information in regard to use of the base
29 * Permission to distribute the released version of the source code along
30 * with corresponding source modifications in the form of a patch file is
31 * granted with same provisions 2 through 4 for binary distributions.
33 * This software is provided "as is" without express or implied warranty
34 * to the extent permitted by applicable law.
37 #ifndef GNUPLOT_EVAL_H
38 # define GNUPLOT_EVAL_H
40 /* #if... / #include / #define collection: */
45 #include <stdio.h> /* for FILE* */
47 #define STACK_DEPTH 100 /* maximum size of the execution stack */
48 #define MAX_AT_LEN 150 /* max number of entries in action table */
50 /* Type definitions */
52 /* HBB 20010725: Moved here, from parse.h */
54 /* keep this in line with table in eval.c */
55 PUSH, PUSHC, PUSHD1, PUSHD2, PUSHD,
56 CALL, CALLN, LNOT, BNOT, UMINUS,
57 LOR, LAND, BOR, XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT,
58 DIV, MOD, POWER, FACTORIAL, BOOLE,
59 DOLLARS, /* for using extension - div */
61 CONCATENATE, EQS, NES, RANGE,
63 /* only jump operators go between jump and sf_start, for is_jump() */
64 JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
66 #define is_jump(operator) \
67 ((operator) >=(int)JUMP && (operator) <(int)SF_START)
69 /* user-defined function table entry */
70 typedef struct udft_entry {
71 struct udft_entry *next_udf; /* pointer to next udf in linked list */
72 char *udf_name; /* name of this function entry */
73 struct at_type *at; /* pointer to action table to execute */
74 char *definition; /* definition of function as typed */
75 int dummy_num; /* required number of input variables */
76 t_value dummy_values[MAX_NUM_VAR]; /* current value of dummy variables */
80 /* user-defined variable table entry */
81 typedef struct udvt_entry {
82 struct udvt_entry *next_udv; /* pointer to next value in linked list */
83 char *udv_name; /* name of this value entry */
84 TBOOLEAN udv_undef; /* true if not defined yet */
85 t_value udv_value; /* value it has */
89 typedef union argument {
90 int j_arg; /* offset for jump */
91 struct value v_arg; /* constant value */
92 struct udvt_entry *udv_arg; /* pointer to dummy variable */
93 struct udft_entry *udf_arg; /* pointer to udf to execute */
97 /* This type definition has to come after union argument has been declared. */
99 typedef void (*FUNC_PTR)(...);
101 typedef void (*FUNC_PTR) __PROTO((union argument *arg));
104 /* standard/internal function table entry */
105 typedef struct ft_entry {
106 const char *f_name; /* pointer to name of this function */
107 FUNC_PTR func; /* address of function to call */
110 /* action table entry */
112 enum operators index; /* index of p-code function */
117 /* count of entries in .actions[] */
119 /* will usually be less than MAX_AT_LEN is malloc()'d copy */
120 struct at_entry actions[MAX_AT_LEN];
124 /* Variables of eval.c needed by other modules: */
126 extern const struct ft_entry GPFAR ft[]; /* The table of builtin functions */
127 extern struct udft_entry *first_udf; /* user-def'd functions */
128 extern struct udvt_entry *first_udv; /* user-def'd variables */
129 extern struct udvt_entry udv_pi; /* 'pi' variable */
130 extern struct udvt_entry *udv_NaN; /* 'NaN' variable */
131 extern TBOOLEAN undefined;
133 /* Prototypes of functions exported by eval.c */
135 double gp_exp __PROTO((double x));
137 /* HBB 20010726: Moved these here, from util.h. */
138 double real __PROTO((struct value *));
139 double imag __PROTO((struct value *));
140 double magnitude __PROTO((struct value *));
141 double angle __PROTO((struct value *));
142 struct value * Gcomplex __PROTO((struct value *, double, double));
143 struct value * Ginteger __PROTO((struct value *, int));
144 #ifdef GP_STRING_VARS
145 struct value * Gstring __PROTO((struct value *, char *));
146 struct value * pop_or_convert_from_string __PROTO((struct value *));
148 struct value * gpfree_string __PROTO((struct value *a));
150 void reset_stack __PROTO((void));
151 void check_stack __PROTO((void));
152 TBOOLEAN more_on_stack __PROTO((void));
153 struct value *pop __PROTO((struct value *x));
154 void push __PROTO((struct value *x));
155 void int_check __PROTO((struct value * v));
157 void f_bool __PROTO((union argument *x));
158 void f_jump __PROTO((union argument *x));
159 void f_jumpz __PROTO((union argument *x));
160 void f_jumpnz __PROTO((union argument *x));
161 void f_jtern __PROTO((union argument *x));
163 void execute_at __PROTO((struct at_type *at_ptr));
164 void evaluate_at __PROTO((struct at_type *at_ptr, struct value *val_ptr));
165 void free_at __PROTO((struct at_type *at_ptr));
167 void apollo_pfm_catch __PROTO((void));
169 struct udvt_entry * add_udv_by_name __PROTO((char *key));
171 /* update GPVAL_ variables available to user */
172 void update_gpval_variables __PROTO((int from_plot_command));
174 #endif /* GNUPLOT_EVAL_H */