--- /dev/null
+#include "parser.h"
+#include "tabular.h"
+
+#include "argument.h"
+
+/* global variables */
+
+tab_t *argument = NULL;
+
+/* argument management */
+
+/* get argument */
+
+double arg (int n)
+{
+ return get_tab (argument, n);
+}
+
+/* set arguments */
+
+double def (int nbops, element_t **ops)
+{
+ int i;
+ argument = resize_tab (argument, nbops);
+ for (i = 0; i < nbops; i++) {
+ set_tab (argument, i + 1, evaluate_element (ops[i], 0));
+ }
+ return size_tab (argument);
+}
+
+/* vim: set ts=4 sw=4 et: */
--- /dev/null
+#ifndef __ARGUMENT_H__
+#define __ARGUMENT_H__
+
+#include "parser.h"
+#include "tabular.h"
+
+/* global variables */
+
+extern tab_t *argument;
+
+/* argument management */
+
+double arg (int n);
+double def (int nbops, element_t **ops);
+
+#endif /* __ARGUMENT_H__ */
+
+/* vim: set ts=4 sw=4 et: */
#include <string.h>
#include "alloc.h"
+#include "argument.h"
#include "debug.h"
#include "parser.h"
#include "stack.h"
/* global variables */
-int argument_size = 0;
-double *argument = NULL;
-
workspace_t *programs = NULL;
int nb_programs = 0;
(programs + n)->root = dupelement (root);
}
-double arg (int id)
-{
- double ret = 0;
- if ((id <= 0) || (id > argument_size)) {
- VERBOSE (WARNING, fprintf (stdout, "error out of bound (%d/%d)\n", id, argument_size));
- } else {
- ret = argument[id - 1];
- }
- return ret;
-}
-
double call (int id, int nbargs, element_t **args)
{
workspace_t tmp = {0};
- int i, l, n = -1;
+ int i, n = -1;
double ret = 0;
if (programs) {
/* store context */
tmp.answer = answer;
tmp.argument = argument;
- tmp.argument_size = argument_size;
- tmp.storage = storage;
tmp.stack = stack;
+ tmp.storage = storage;
/* change context */
answer = 0;
- storage = (programs + n)->storage;
argument = NULL;
- argument_size = 0;
- stack = (programs + n)->stack;
if (nbargs > 0) {
- argument = (double *) callocordie (nbargs, sizeof (double));
- for (i = 0, l = 0; i < nbargs; l++) {
- if (args[l]) {
- argument[i++] = evaluate_element (args[l], 0);
- }
- }
- argument_size = nbargs;
+ def (nbargs, args);
}
+ stack = (programs + n)->stack;
+ storage = (programs + n)->storage;
/* evaluate program */
element_t *elements = dupelement ((programs + n)->root);
ret = evaluate_element (elements, 0);
delelement (elements);
+
+ /* cleaning context */
(programs + n)->answer = answer;
- (programs + n)->storage = storage;
if (argument) {
- free (argument);
+ free_tab (argument);
}
(programs + n)->stack = stack;
+ (programs + n)->storage = storage;
/* restore context */
answer = tmp.answer;
- storage = tmp.storage;
argument = tmp.argument;
- argument_size = tmp.argument_size;
+ storage = tmp.storage;
stack = tmp.stack;
return ret;
/* global variables */
-extern int argument_size;
-extern double *argument;
-
/* workspace type */
typedef struct _workspace_t {
- int id;
double answer;
- tab_t *storage;
- double *argument;
- int argument_size;
+ tab_t *argument;
+ int id;
element_t *root;
tab_t *stack;
+ tab_t *storage;
char *string;
} workspace_t;
/* program function */
void prog (int id, element_t *root);
-double arg (int id);
double call (int id, int nbargs, element_t **args);
void list ();
void edit (int id);