-
Notifications
You must be signed in to change notification settings - Fork 1
/
arith.cc
142 lines (133 loc) · 3.08 KB
/
arith.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#define ICI_CORE
#include "parse.h"
#include "primes.h"
#ifdef BINOP_FUNC
#include "buf.h"
#include "exec.h"
#include "float.h"
#include "int.h"
#include "map.h"
#include "op.h"
#include "ptr.h"
#include "re.h"
#include "set.h"
#include "str.h"
#endif
namespace ici
{
/*
* binop.c
*
* In most configurations this file only defines binop_name() which
* merely returns the textual form of a binary operator for error messages.
* But in configuration where the function evaluate() (in exec.c) cannot
* be compiled with the whole binary operator switch statement in-line,
* it can be done as a seperate function here. This is only necessary
* if the compiler can't handle such a large function. Fortunately this
* sort of thing is becomming rare.
*/
/*
* Return the textual form of a binary operator. This is only to assist
* in error messages.
*/
const char *binop_name(int op)
{
switch (op)
{
case t_subtype(T_ASTERIX):
return "*";
case t_subtype(T_SLASH):
return "/";
case t_subtype(T_PERCENT):
return "%";
case t_subtype(T_PLUS):
return "+";
case t_subtype(T_MINUS):
return "-";
case t_subtype(T_GRTGRT):
return ">>";
case t_subtype(T_LESSLESS):
return "<<";
case t_subtype(T_LESS):
return "<";
case t_subtype(T_GRT):
return ">";
case t_subtype(T_LESSEQ):
return "<=";
case t_subtype(T_GRTEQ):
return ">=";
case t_subtype(T_EQEQ):
return "==";
case t_subtype(T_EXCLAMEQ):
return "!=";
case t_subtype(T_TILDE):
return "~";
case t_subtype(T_EXCLAMTILDE):
return "!~";
case t_subtype(T_2TILDE):
return "~~";
case t_subtype(T_3TILDE):
return "~~~";
case t_subtype(T_AND):
return "&";
case t_subtype(T_CARET):
return "^";
case t_subtype(T_BAR):
return "|";
case t_subtype(T_ANDAND):
return "&&";
case t_subtype(T_BARBAR):
return "||";
case t_subtype(T_COLON):
return ":";
case t_subtype(T_QUESTION):
return "?";
case t_subtype(T_EQ):
return "=";
case t_subtype(T_COLONEQ):
return ":=";
case t_subtype(T_PLUSEQ):
return "+=";
case t_subtype(T_MINUSEQ):
return "-=";
case t_subtype(T_ASTERIXEQ):
return "*=";
case t_subtype(T_SLASHEQ):
return "/=";
case t_subtype(T_PERCENTEQ):
return "%=";
case t_subtype(T_GRTGRTEQ):
return ">>=";
case t_subtype(T_LESSLESSEQ):
return "<<=";
case t_subtype(T_ANDEQ):
return "&=";
case t_subtype(T_CARETEQ):
return "^=";
case t_subtype(T_BAREQ):
return "|=";
case t_subtype(T_2TILDEEQ):
return "~~=";
case t_subtype(T_LESSEQGRT):
return "<=>";
case t_subtype(T_COMMA):
return ",";
default:
return "binop";
}
}
#ifdef BINOPFUNC
#include "pcre.h"
#include "userop.h"
/*
* See the comment in binop.h.
*/
int op_binop(object *o)
{
#include "binop.h"
return 0;
fail:
return 1;
}
#endif
} // namespace ici