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
143
144
145
146
147
148
149
150
|
/*************************************************************************
*
* HTCd - Copyright (C) 1998-2006 Henrik Rydberg
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <lang/env.h>
//////////////////////////////////////////////////////
struct xop_t : public op_t {
typedef void (*xop1_t)(mstream&,Env&,const sref&);
typedef void (*xop2_t)(mstream&,Env&,const sref&,const sref&);
xop_t(const mstring& s,int p1,int p2,int l,int r,
xop1_t op1,xop2_t op2,const mstring& d):
op_t(s,p1,p2,l,r,(op1_t)op1,(op2_t)op2,d) {}
};
//////////////////////////////////////////////////////
#define X1_IMPL(name) \
static void impl_##name(mstream& out,Env& env,const sref& a) throw(merror_t)
#define X2_IMPL(name) \
static void impl_##name(mstream& out,Env& env,const sref& L,const sref& R) throw(merror_t)
#define X1_ADDN(p,l,r,f,n,d) M.add(new xop_t(#n,p,0,l,r,impl_##f,0,d))
#define X2_ADDN(p,l,r,f,n,d) M.add(new xop_t(#n,0,p,l,r,0,impl_##f,d))
//////////////////////////////////////////////////////
X1_IMPL(exist) {
mstring name;
swrite sw(name);
env.eval(sw,a,0);
out<<env.gloc_find(name);
}
X2_IMPL(new) {
mstring name;
swrite sw(name);
env.eval(sw,L,0);
env.aloc(name,R);
}
X2_IMPL(assign) {
mstring name;
swrite sw(name);
env.eval(sw,L,0);
env.sloc(name,R);
}
X2_IMPL(incr) {
mstring name;
swrite sw(name);
env.eval(sw,L,0);
env.sloc(name,ftoa(atof(env.gloc(name))+atof(R)));
}
X2_IMPL(decr) {
mstring name;
swrite sw(name);
env.eval(sw,L,0);
env.sloc(name,ftoa(atof(env.gloc(name))-atof(R)));
}
//////////////////////////////////////////////////////
X2_IMPL(new_rec) {
if(*L=='@') env.gloc_adb(L.popf(),R);
else {
rpile list; env.gloc_list(list,R);
int n=*R=='@'?R.size()-1:R.size();
for(int i=0;i<list.size();i++) env.aloc(L+list[i].right(n),env.gloc(list[i]));
}
}
X2_IMPL(copy_rec) {
rpile list; env.gloc_list(list,L);
int n=*L=='@'?L.size()-1:L.size();
for(int i=0;i<list.size();i++) env.sloc(R+list[i].right(n),env.gloc(list[i]));
}
//////////////////////////////////////////////////////
void envAddOps(opmap& M,tokmap& T)
{
opAddHEXP(M);
X1_ADDN(40,0,1,exist,?,
"True if a exist\n"
"Syntax: ? (varname)\n"
"Returns: (int)\n"
);
X2_ADDN(4,1,2,new,:=,
"New assignment\n"
"Syntax: (varname) := (expr)\n"
"Returns: nothing\n"
);
X2_ADDN(4,1,2,assign,=,
"Assignment to existing variable\n"
"Syntax: (varname) = (expr)\n"
"Returns: nothing\n"
);
X2_ADDN(4,1,2,incr,+=,
"Increment operator\n"
"Syntax: (varname) += (real)\n"
"Returns: nothing\n"
);
X2_ADDN(4,1,2,decr,-=,
"Decrement operator\n"
"Syntax: (varname) -= (real)\n"
"Returns: nothing\n"
);
X2_ADDN(4,1,1,new_rec,<-,
"New local record\n"
"Syntax: (partial name) <- (partial name)\n"
"Returns: nothing\n"
"\n"
"If the partial name @ is given as the left argument,\n"
"a new record is created or silently updated, depending\n"
"on whether it is unique or not according to the default order.\n"
"The index table must however exist in the right argument.\n"
"\n"
"The default order may only be set at creation or when saving\n"
"a database to disk.\n"
);
X2_ADDN(4,1,1,copy_rec,->,
"Copy local record\n"
"Syntax: (partial name) -> (partial name)\n"
"Returns: nothing\n"
"\n"
"The partial name @ for data base records works in both arguments.\n"
"\n"
"Generates an error if any of the expanded names of the right\n"
"partial argument does not exist.\n"
);
}
|