2 * func - built-in function interface definitions
4 * Copyright (C) 1999-2007 David I. Bell
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.1 $
21 * @(#) $Id: func.h,v 30.1 2007/03/16 11:09:46 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/RCS/func.h,v $
24 * Under source code control: 1990/02/15 01:48:33
25 * File existed as early as: before 1990
27 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
31 #if !defined(__FUNC_H__)
35 #if defined(CALC_SRC) /* if we are building from the calc source tree */
39 # include <calc/calc.h>
40 # include <calc/label.h>
45 * Structure of a function.
46 * The f_opcodes array is actually of variable size.
48 typedef struct func FUNC
;
50 FUNC
*f_next
; /* next function in list */
51 unsigned long f_opcodecount
; /* size of opcode array */
52 unsigned int f_localcount
; /* number of local variables */
53 unsigned int f_paramcount
; /* max number of parameters */
54 char *f_name
; /* function name */
55 VALUE f_savedvalue
; /* saved value of last expression */
56 unsigned long f_opcodes
[1]; /* array of opcodes (variable length) */
61 * Amount of space needed to allocate a function of n opcodes.
63 #define funcsize(n) (sizeof(FUNC) + (n) * sizeof(long))
67 * Size of a character pointer rounded up to a number of opcodes.
69 #define PTR_SIZE ((sizeof(char *) + sizeof(long) - 1) / sizeof(long))
73 * The current function being compiled.
75 E_FUNC FUNC
*curfunc
; /* NOTE: This is a function pointer, we need E_FUNC */
79 * Functions to handle functions.
81 E_FUNC FUNC
*findfunc(long index
);
82 E_FUNC
char *namefunc(long index
);
83 E_FUNC BOOL
evaluate(BOOL nestflag
);
84 E_FUNC
long adduserfunc(char *name
);
85 E_FUNC
void rmuserfunc(char *name
);
86 E_FUNC
void rmalluserfunc(void);
87 E_FUNC
long getuserfunc(char *name
);
88 E_FUNC
void beginfunc(char *name
, BOOL newflag
);
89 E_FUNC
int builtinopcode(long index
);
90 E_FUNC
char *builtinname(long index
);
91 E_FUNC
int dumpop(unsigned long *pc
);
92 E_FUNC
void addop(long op
);
93 E_FUNC
void endfunc(void);
94 E_FUNC
void addopone(long op
, long arg
);
95 E_FUNC
void addoptwo(long op
, long arg1
, long arg2
);
96 E_FUNC
void addoplabel(long op
, LABEL
*label
);
97 E_FUNC
void addopptr(long op
, char *ptr
);
98 E_FUNC
void writeindexop(void);
99 E_FUNC
void showbuiltins(void);
100 E_FUNC
int getbuiltinfunc(char *name
);
101 E_FUNC
void builtincheck(long index
, int count
);
102 E_FUNC
void addopfunction(long op
, long index
, int count
);
103 E_FUNC
void showfunctions(void);
104 E_FUNC
void initfunctions(void);
105 E_FUNC
void clearopt(void);
106 E_FUNC
void updateoldvalue(FUNC
*fp
);
107 E_FUNC
void calculate(FUNC
*fp
, int argcount
);
108 E_FUNC VALUE
builtinfunc(long index
, int argcount
, VALUE
*stck
);
109 E_FUNC
void freenumbers(FUNC
*);
110 E_FUNC
void freefunc(FUNC
*);
113 #endif /* !__FUNC_H__ */