1 /*
2  * opcodes - opcode execution module definition
3  *
4  * Copyright (C) 1999-2007,2014,2021  David I. Bell
5  *
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.
9  *
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.
14  *
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.
19  *
20  * Under source code control:	1990/02/15 01:48:35
21  * File existed as early as:	before 1990
22  *
23  * Share and enjoy!  :-)	http://www.isthe.com/chongo/tech/comp/calc/
24  */
25 
26 
27 #if !defined(INCLUDE_OPCODES_H)
28 #define INCLUDE_OPCODES_H
29 
30 
31 #if defined(CALC_SRC)	/* if we are building from the calc source tree */
32 # include "decl.h"
33 #else
34 # include <calc/decl.h>
35 #endif
36 
37 
38 /*
39  * Opcodes
40  */
41 #define OP_NOP		0L	/* no operation */
42 #define OP_LOCALADDR	1L	/* load address of local variable */
43 #define OP_GLOBALADDR	2L	/* load address of global variable */
44 #define OP_PARAMADDR	3L	/* load address of parameter variable */
45 #define OP_LOCALVALUE	4L	/* load value of local variable */
46 #define OP_GLOBALVALUE	5L	/* load value of global variable */
47 #define OP_PARAMVALUE	6L	/* load value of parameter variable */
48 #define OP_NUMBER	7L	/* load constant real numeric value */
49 #define OP_INDEXADDR	8L	/* load array index address */
50 #define OP_PRINTRESULT	9L	/* print result of top-level expression */
51 #define OP_ASSIGN	10L	/* assign value to variable */
52 #define OP_ADD		11L	/* add top two values */
53 #define OP_SUB		12L	/* subtract top two values */
54 #define OP_MUL		13L	/* multiply top two values */
55 #define OP_DIV		14L	/* divide top two values */
56 #define OP_MOD		15L	/* take mod of top two values */
57 #define OP_SAVE		16L	/* save value for later use */
58 #define OP_NEGATE	17L	/* negate top value */
59 #define OP_INVERT	18L	/* invert top value */
60 #define OP_INT		19L	/* take integer part of top value */
61 #define OP_FRAC		20L	/* take fraction part of top value */
62 #define OP_NUMERATOR	21L	/* take numerator of top value */
63 #define OP_DENOMINATOR	22L	/* take denominator of top value */
64 #define OP_DUPLICATE	23L	/* duplicate top value on stack */
65 #define OP_POP		24L	/* pop top value from stack */
66 #define OP_RETURN	25L	/* return value of function */
67 #define OP_JUMPZ	26L	/* jump if top value is zero */
68 #define OP_JUMPNZ	27L	/* jump if top value is nonzero */
69 #define OP_JUMP		28L	/* jump unconditionally */
70 #define OP_USERCALL	29L	/* call a user-defined function */
71 #define OP_GETVALUE	30L	/* convert address to value */
72 #define OP_EQ		31L	/* test top two elements for equality */
73 #define OP_NE		32L	/* test top two elements for inequality */
74 #define OP_LE		33L	/* test top two elements for <= */
75 #define OP_GE		34L	/* test top two elements for >= */
76 #define OP_LT		35L	/* test top two elements for < */
77 #define OP_GT		36L	/* test top two elements for > */
78 #define OP_PREINC	37L	/* add one to variable (++x) */
79 #define OP_PREDEC	38L	/* subtract one from variable (--x) */
80 #define OP_POSTINC	39L	/* add one to variable (x++) */
81 #define OP_POSTDEC	40L	/* subtract one from variable (x--) */
82 #define OP_DEBUG	41L	/* debugging point */
83 #define OP_PRINT	42L	/* print value */
84 #define OP_ASSIGNPOP	43L	/* assign to variable and remove it */
85 #define OP_ZERO		44L	/* put zero on the stack */
86 #define OP_ONE		45L	/* put one on the stack */
87 #define OP_PRINTEOL	46L	/* print end of line */
88 #define OP_PRINTSPACE	47L	/* print a space */
89 #define OP_PRINTSTRING	48L	/* print constant string */
90 #define OP_DUPVALUE	49L	/* duplicate value of top value */
91 #define OP_OLDVALUE	50L	/* old calculation value */
92 #define OP_QUO		51L	/* integer quotient of top two values */
93 #define OP_POWER	52L	/* number raised to a power */
94 #define OP_QUIT		53L	/* quit program */
95 #define OP_CALL		54L	/* call built-in routine */
96 #define OP_GETEPSILON	55L	/* get allowed error for calculations */
97 #define OP_AND		56L	/* arithmetic and */
98 #define OP_OR		57L	/* arithmetic or */
99 #define OP_NOT		58L	/* logical not */
100 #define OP_ABS		59L	/* absolute value */
101 #define OP_SGN		60L	/* sign of number */
102 #define OP_ISINT	61L	/* whether top value is integer */
103 #define OP_CONDORJUMP	62L	/* conditional or jump */
104 #define OP_CONDANDJUMP	63L	/* conditional and jump */
105 #define OP_SQUARE	64L	/* square top value */
106 #define OP_STRING	65L	/* load constant string value */
107 #define OP_ISNUM	66L	/* whether top value is a number */
108 #define OP_UNDEF	67L	/* load undefined value on stack */
109 #define OP_ISNULL	68L	/* whether variable is the null value */
110 #define OP_ARGVALUE	69L	/* load value of argument (parameter) n */
111 #define OP_MATCREATE	70L	/* create matrix */
112 #define OP_ISMAT	71L	/* whether variable is a matrix */
113 #define OP_ISSTR	72L	/* whether variable is a string */
114 #define OP_GETCONFIG	73L	/* get value of configuration parameter */
115 #define OP_LEFTSHIFT	74L	/* left shift of integer */
116 #define OP_RIGHTSHIFT	75L	/* right shift of integer */
117 #define OP_CASEJUMP	76L	/* test case and jump if not matched */
118 #define OP_ISODD	77L	/* whether value is an odd integer */
119 #define OP_ISEVEN	78L	/* whether value is even integer */
120 #define OP_FIADDR	79L	/* 'fast index' matrix value address */
121 #define OP_FIVALUE	80L	/* 'fast index' matrix value */
122 #define OP_ISREAL	81L	/* test value for real number */
123 #define OP_IMAGINARY	82L	/* load imaginary numeric constant */
124 #define OP_RE		83L	/* real part of complex number */
125 #define OP_IM		84L	/* imaginary part of complex number */
126 #define OP_CONJUGATE	85L	/* complex conjugate of complex number */
127 #define OP_OBJCREATE	86L	/* create object */
128 #define OP_ISOBJ	87L	/* whether value is an object */
129 #define OP_NORM		88L	/* norm of value (square of abs) */
130 #define OP_ELEMADDR	89L	/* address of element of object */
131 #define OP_ELEMVALUE	90L	/* value of element of object */
132 #define OP_ISTYPE	91L	/* whether two values are the same type */
133 #define OP_SCALE	92L	/* scale value by a power of two */
134 #define OP_ISLIST	93L	/* whether value is a list */
135 #define OP_SWAP		94L	/* swap values of two variables */
136 #define OP_ISSIMPLE	95L	/* whether value is a simple type */
137 #define OP_CMP		96L	/* compare values returning -1, 0, or 1 */
138 #define OP_SETCONFIG	97L	/* set configuration parameter */
139 #define OP_SETEPSILON	98L	/* set allowed error for calculations */
140 #define OP_ISFILE	99L	/* whether value is a file */
141 #define OP_ISASSOC	100L	/* whether value is an association */
142 #define OP_INITSTATIC	101L	/* once only code for static initialization */
143 #define OP_ELEMINIT	102L	/* assign element of matrix or object */
144 #define OP_ISCONFIG	103L	/* whether value is a configuration state */
145 #define OP_ISHASH	104L	/* whether value is a hash state */
146 #define OP_ISRAND	105L	/* whether value is subtractive 100 state */
147 #define OP_ISRANDOM	106L	/* whether value is a Blum random state */
148 #define OP_SHOW		107L	/* show data about current state */
149 #define OP_INITFILL	108L	/* fill new matrix with copies of a value */
150 #define OP_ASSIGNBACK	109L	/* assign in reverse order */
151 #define OP_TEST		110L	/* test whether value is "nonzero" */
152 #define OP_ISDEFINED	111L	/* whether string names a function */
153 #define OP_ISOBJTYPE	112L	/* whether string names an object type */
154 #define OP_ISBLK	113L	/* whether value is a block */
155 #define OP_PTR		114L	/* octet pointer */
156 #define OP_DEREF	115L	/* dereference an octet pointer */
157 #define OP_ISOCTET	116L	/* whether value is an octet */
158 #define OP_ISPTR	117L	/* whether value is a pointer */
159 #define OP_SAVEVAL	118L	/* activate updating */
160 #define OP_LINKS	119L	/* return links for numbers and strings */
161 #define OP_BIT		120L	/* whether specified bit is set */
162 #define OP_COMP		121L	/* complement value */
163 #define OP_XOR		122L	/* xor (~) of values */
164 #define OP_HIGHBIT	123L	/* index of high bit of value */
165 #define OP_LOWBIT	124L	/* index of low bit of value */
166 #define OP_CONTENT	125L	/* value returned by unary # */
167 #define OP_HASHOP	126L	/* binary # */
168 #define OP_BACKSLASH	127L	/* unary backslash */
169 #define OP_SETMINUS	128L	/* binary backslash */
170 #define OP_PLUS		129L	/* unary + */
171 #define OP_JUMPNN	130L	/* jump if top value is non-null */
172 #define OP_ABORT	131L	/* abort operation */
173 #define MAX_OPCODE	131L	/* highest legal opcode */
174 
175 
176 /*
177  * external declarations
178  */
179 EXTERN char *funcname;		/* function being executed */
180 EXTERN long funcline;		/* function line being executed */
181 
182 
183 #endif /* !INCLUDE_OPCODES_H */
184