Initial release of Maemo 5 port of gnuplot
[gnuplot] / src / eval.h
1 /*
2  * $Id: eval.h,v 1.26 2006/07/21 05:19:51 sfeam Exp $
3  */
4
5 /* GNUPLOT - eval.h */
6
7 /*[
8  * Copyright 1999, 2004   Thomas Williams, Colin Kelley
9  *
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.
15  *
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,
20  * provided you
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
28  *    software.
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.
32  *
33  * This software is provided "as is" without express or implied warranty
34  * to the extent permitted by applicable law.
35 ]*/
36
37 #ifndef GNUPLOT_EVAL_H
38 # define GNUPLOT_EVAL_H
39
40 /* #if... / #include / #define collection: */
41
42 #include "syscfg.h"
43 #include "gp_types.h"
44
45 #include <stdio.h>              /* for FILE* */
46
47 #define STACK_DEPTH 100         /* maximum size of the execution stack */
48 #define MAX_AT_LEN 150          /* max number of entries in action table */
49
50 /* Type definitions */
51
52 /* HBB 20010725: Moved here, from parse.h */
53 enum operators {
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 */
60 #ifdef GP_STRING_VARS
61     CONCATENATE, EQS, NES, RANGE,
62 #endif
63     /* only jump operators go between jump and sf_start, for is_jump() */
64     JUMP, JUMPZ, JUMPNZ, JTERN, SF_START
65 };
66 #define is_jump(operator) \
67     ((operator) >=(int)JUMP && (operator) <(int)SF_START)
68
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 */
77 } udft_entry;
78
79
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 */
86 } udvt_entry;
87
88 /* p-code argument */
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 */
94 } argument;
95
96
97 /* This type definition has to come after union argument has been declared. */
98 #ifdef __ZTC__
99 typedef void (*FUNC_PTR)(...);
100 #else
101 typedef void (*FUNC_PTR) __PROTO((union argument *arg));
102 #endif
103
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 */
108 } ft_entry;
109
110 /* action table entry */
111 struct at_entry {
112     enum operators index;       /* index of p-code function */
113     union argument arg;
114 };
115
116 struct at_type {
117     /* count of entries in .actions[] */
118     int a_count;
119     /* will usually be less than MAX_AT_LEN is malloc()'d copy */
120     struct at_entry actions[MAX_AT_LEN];
121 };
122
123
124 /* Variables of eval.c needed by other modules: */
125
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;
132
133 /* Prototypes of functions exported by eval.c */
134
135 double gp_exp __PROTO((double x));
136
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 *));
147 #endif
148 struct value * gpfree_string __PROTO((struct value *a));
149
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));
156
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));
162
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));
166 #ifdef APOLLO
167 void apollo_pfm_catch __PROTO((void));
168 #endif
169 struct udvt_entry * add_udv_by_name __PROTO((char *key));
170
171 /* update GPVAL_ variables available to user */
172 void update_gpval_variables __PROTO((int from_plot_command));
173
174 #endif /* GNUPLOT_EVAL_H */