Skip to content

Commit 9044646

Browse files
committed
COMMON: fix uds regression
1 parent 6f9da0e commit 9044646

File tree

4 files changed

+73
-105
lines changed

4 files changed

+73
-105
lines changed

src/common/ceval.c

Lines changed: 46 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,46 @@
1010
#include "common/smbas.h"
1111
#include "common/bc.h"
1212

13-
extern void sc_raise(const char *fmt, ...);
14-
void cev_log(void);
13+
static bc_t *bc_in;
14+
static bc_t *bc_out;
15+
16+
#define cev_add1(x) bc_add_code(bc_out, (x))
17+
#define cev_add2(x, y) { bc_add1(bc_out, (x)); bc_add1(bc_out, (y)); }
18+
#define cev_add_addr(x) bc_add_addr(bc_out, (x))
19+
#define IP bc_in->cp
20+
#define CODE(x) bc_in->ptr[(x)]
21+
#define CODE_PEEK() CODE(IP)
22+
#define IF_ERR_RTN if (comp_error) return
1523

16-
#define IP bc_in->cp
17-
#define CODE(x) bc_in->ptr[(x)]
18-
#define CODE_PEEK() CODE(IP)
24+
void cev_log(void);
1925

2026
void cev_udp(void) {
2127
sc_raise("(EXPR): UDP INSIDE EXPR");
2228
}
2329

2430
void cev_missing_rp(void) {
25-
sc_raise("(EXPR): MISSING ')'");
31+
sc_raise("(EXPR): MISSING ')' %d", IP);
2632
}
2733

2834
void cev_opr_err(void) {
2935
sc_raise("(EXPR): SYNTAX ERROR (1st OP)");
3036
}
3137

32-
static bc_t *bc_in;
33-
static bc_t *bc_out;
34-
35-
#define cev_add1(x) bc_add_code(bc_out, (x))
36-
#define cev_add2(x, y) { bc_add1(bc_out, (x)); bc_add1(bc_out, (y)); }
37-
#define cev_add_addr(x) bc_add_addr(bc_out, (x))
38+
void cev_prim_str() {
39+
dword len;
40+
memcpy(&len, bc_in->ptr + bc_in->cp, OS_STRLEN);
41+
IP += OS_STRLEN;
42+
bc_add_dword(bc_out, len);
43+
bc_add_n(bc_out, bc_in->ptr + bc_in->cp, len);
44+
IP += len;
45+
}
3846

3947
/*
4048
* prim
4149
*/
4250
void cev_prim() {
43-
byte code;
44-
dword len;
45-
46-
if (comp_error) {
47-
return;
48-
}
49-
code = CODE(IP);
51+
IF_ERR_RTN;
52+
byte code = CODE(IP);
5053
IP++;
5154
cev_add1(code);
5255
switch (code) {
@@ -59,11 +62,7 @@ void cev_prim() {
5962
IP += OS_REALSZ;
6063
break;
6164
case kwTYPE_STR:
62-
memcpy(&len, bc_in->ptr + bc_in->cp, OS_STRLEN);
63-
IP += OS_STRLEN;
64-
bc_add_dword(bc_out, len);
65-
bc_add_n(bc_out, bc_in->ptr + bc_in->cp, len);
66-
IP += len;
65+
cev_prim_str();
6766
break;
6867
case kwTYPE_CALL_UDP:
6968
cev_udp();
@@ -78,6 +77,13 @@ void cev_prim() {
7877
bc_add_n(bc_out, bc_in->ptr + bc_in->cp, ADDRSZ); // 1 addr
7978
IP += ADDRSZ;
8079

80+
while (CODE_PEEK() == kwTYPE_UDS_EL) {
81+
cev_add1(kwTYPE_UDS_EL);
82+
cev_add1(kwTYPE_STR);
83+
IP += 2;
84+
cev_prim_str();
85+
}
86+
8187
// support multiple ()
8288
while (CODE_PEEK() == kwTYPE_LEVEL_BEGIN) {
8389
cev_add1(kwTYPE_LEVEL_BEGIN);
@@ -145,12 +151,7 @@ void cev_prim() {
145151
}
146152
}
147153

148-
if (CODE_PEEK() == kwTYPE_UDS_EL) {
149-
// code + string
150-
cev_add1(CODE(IP));
151-
IP++;
152-
cev_prim();
153-
} else if (CODE_PEEK() != kwTYPE_LEVEL_END) {
154+
if (CODE_PEEK() != kwTYPE_LEVEL_END) {
154155
cev_missing_rp();
155156
} else {
156157
cev_add1(kwTYPE_LEVEL_END);
@@ -164,29 +165,19 @@ void cev_prim() {
164165
* parenthesis
165166
*/
166167
void cev_parenth() {
167-
if (comp_error) {
168-
return;
169-
}
168+
IF_ERR_RTN;
170169
if (CODE_PEEK() == kwTYPE_LEVEL_BEGIN) {
171170
cev_add1(kwTYPE_LEVEL_BEGIN);
172171
IP++;
173172

174173
cev_log(); // R = cev_log
175-
176-
if (comp_error) {
177-
return;
178-
}
174+
IF_ERR_RTN;
179175

180176
if (CODE_PEEK() == kwTYPE_SEP) {
181177
cev_add1(kwTYPE_SEP);
182178
IP++;
183179
cev_add1(CODE(IP));
184180
IP++;
185-
} else if (CODE_PEEK() == kwTYPE_UDS_EL) {
186-
// code + string
187-
cev_add1(CODE(IP));
188-
IP++;
189-
cev_prim();
190181
} else if (CODE_PEEK() != kwTYPE_LEVEL_END) {
191182
cev_missing_rp();
192183
return;
@@ -205,9 +196,7 @@ void cev_parenth() {
205196
void cev_unary() {
206197
char op;
207198

208-
if (comp_error) {
209-
return;
210-
}
199+
IF_ERR_RTN;
211200
if (CODE(IP) == kwTYPE_UNROPR || CODE(IP) == kwTYPE_ADDOPR) {
212201
op = CODE(IP + 1);
213202
IP += 2;
@@ -227,17 +216,13 @@ void cev_unary() {
227216
void cev_pow() {
228217
cev_unary(); // R = cev_unary
229218

230-
if (comp_error) {
231-
return;
232-
}
219+
IF_ERR_RTN;
233220
while (CODE(IP) == kwTYPE_POWOPR) {
234221
IP += 2;
235222

236223
cev_add1(kwTYPE_EVPUSH); // PUSH R
237224
cev_unary(); // R = cev_unary
238-
if (comp_error) {
239-
return;
240-
}
225+
IF_ERR_RTN;
241226
cev_add1(kwTYPE_EVPOP); // POP LEFT
242227
cev_add2(kwTYPE_POWOPR, '^'); // R = LEFT op R
243228
}
@@ -249,9 +234,7 @@ void cev_pow() {
249234
void cev_mul() {
250235
cev_pow(); // R = cev_pow()
251236

252-
if (comp_error) {
253-
return;
254-
}
237+
IF_ERR_RTN;
255238
while (CODE(IP) == kwTYPE_MULOPR) {
256239
char op;
257240

@@ -260,9 +243,7 @@ void cev_mul() {
260243
cev_add1(kwTYPE_EVPUSH); // PUSH R
261244

262245
cev_pow();
263-
if (comp_error) {
264-
return;
265-
}
246+
IF_ERR_RTN;
266247
cev_add1(kwTYPE_EVPOP); // POP LEFT
267248
cev_add2(kwTYPE_MULOPR, op); // R = LEFT op R
268249
}
@@ -274,9 +255,7 @@ void cev_mul() {
274255
void cev_add() {
275256
cev_mul(); // R = cev_mul()
276257

277-
if (comp_error) {
278-
return;
279-
}
258+
IF_ERR_RTN;
280259
while (CODE(IP) == kwTYPE_ADDOPR) {
281260
char op;
282261

@@ -286,8 +265,7 @@ void cev_add() {
286265
cev_add1(kwTYPE_EVPUSH); // PUSH R
287266

288267
cev_mul(); // R = cev_mul
289-
if (comp_error)
290-
return;
268+
IF_ERR_RTN;
291269

292270
cev_add1(kwTYPE_EVPOP); // POP LEFT
293271
cev_add2(kwTYPE_ADDOPR, op); // R = LEFT op R
@@ -300,21 +278,16 @@ void cev_add() {
300278
void cev_cmp() {
301279
cev_add(); // R = cev_add()
302280

303-
if (comp_error) {
304-
return;
305-
}
281+
IF_ERR_RTN;
306282
while (CODE(IP) == kwTYPE_CMPOPR) {
307283
char op;
308284

309285
IP++;
310286
op = CODE(IP);
311287
IP++;
312288
cev_add1(kwTYPE_EVPUSH); // PUSH R
313-
314289
cev_add(); // R = cev_add()
315-
if (comp_error)
316-
return;
317-
290+
IF_ERR_RTN;
318291
cev_add1(kwTYPE_EVPOP); // POP LEFT
319292
cev_add2(kwTYPE_CMPOPR, op); // R = LEFT op R
320293
}
@@ -325,9 +298,7 @@ void cev_cmp() {
325298
*/
326299
void cev_log(void) {
327300
cev_cmp(); // R = cev_cmp()
328-
if (comp_error) {
329-
return;
330-
}
301+
IF_ERR_RTN;
331302
while (CODE(IP) == kwTYPE_LOGOPR) {
332303
char op;
333304
addr_t shortcut;
@@ -336,17 +307,15 @@ void cev_log(void) {
336307
IP++;
337308
op = CODE(IP);
338309
IP++;
339-
cev_add1(kwTYPE_EVPUSH); // PUSH R (push the left side result
340310

311+
cev_add1(kwTYPE_EVPUSH); // PUSH R (push the left side result
341312
cev_add1(kwTYPE_EVAL_SC);
342313
cev_add2(kwTYPE_LOGOPR, op);
343314
shortcut = bc_out->count; // shortcut jump target (calculated below)
344315
cev_add_addr(0);
345316

346317
cev_cmp(); // right seg // R = cev_cmp()
347-
if (comp_error) {
348-
return;
349-
}
318+
IF_ERR_RTN;
350319
cev_add1(kwTYPE_EVPOP); // POP LEFT
351320
cev_add2(kwTYPE_LOGOPR, op); // R = LEFT op R
352321

@@ -359,14 +328,12 @@ void cev_log(void) {
359328
* main
360329
*/
361330
void expr_parser(bc_t *bc_src) {
362-
byte code;
363-
364331
// init
365332
bc_in = bc_src;
366333
bc_out = tmp_alloc(sizeof(bc_t));
367334
bc_create(bc_out);
368335

369-
code = CODE_PEEK();
336+
byte code = CODE_PEEK();
370337

371338
//
372339
// empty!
@@ -397,7 +364,6 @@ void expr_parser(bc_t *bc_src) {
397364
if (kw_check_evexit(code)) { // separator
398365
cev_add1(code);
399366
IP++; // add sep.
400-
401367
if (code == kwUSE) {
402368
cev_add_addr(0);
403369
// USE needs 2 ips
@@ -416,11 +382,9 @@ void expr_parser(bc_t *bc_src) {
416382
IP++;
417383
}
418384
}
419-
420385
code = CODE_PEEK(); // next
421386
continue;
422387
}
423-
424388
cev_log(); // do it
425389
code = CODE_PEEK(); // next
426390
}

src/common/hotspots.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,18 @@ static inline var_t* code_getvarptr_parens(int until_parens) {
150150
if (code_peek() == kwTYPE_VAR) {
151151
code_skipnext();
152152
var_p = tvar[code_getaddr()];
153-
switch (var_p->type) {
154-
case V_HASH:
155-
case V_ARRAY:
153+
if (code_peek() == kwTYPE_UDS_EL) {
156154
var_p = code_resolve_varptr(var_p, until_parens);
157-
break;
158-
default:
159-
if (!until_parens && code_peek() == kwTYPE_LEVEL_BEGIN) {
160-
err_varisnotarray();
155+
} else {
156+
switch (var_p->type) {
157+
case V_HASH:
158+
case V_ARRAY:
159+
var_p = code_resolve_varptr(var_p, until_parens);
160+
break;
161+
default:
162+
if (!until_parens && code_peek() == kwTYPE_LEVEL_BEGIN) {
163+
err_varisnotarray();
164+
}
161165
}
162166
}
163167
}

src/common/sberr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void err_stackunderflow(void) {
103103
rt_raise(ERR_STACK_UNDERFLOW);
104104
}
105105

106+
// generic stack error
106107
void err_stackmess() {
107108
rt_raise(ERR_STACK);
108109
}
@@ -123,6 +124,7 @@ void err_typemismatch(void) {
123124
rt_raise(ERR_TYPE);
124125
}
125126

127+
// parameter with wrong value
126128
void err_argerr(void) {
127129
rt_raise(ERR_PARAM);
128130
}
@@ -199,6 +201,7 @@ void err_parfmt(const char *fmt) {
199201
rt_raise(ERR_PARFMT, fmt);
200202
}
201203

204+
// UDP/F: parameter is 'by reference' so const not allowed
202205
void err_parm_byref(int n) {
203206
rt_raise(ERR_BYREF, n);
204207
}
@@ -211,6 +214,7 @@ void err_fopen(void) {
211214
rt_raise(ERR_BAD_FILE_HANDLE);
212215
}
213216

217+
// no separator found
214218
void err_syntaxanysep(const char *seps) {
215219
rt_raise(ERR_SEP_FMT, seps);
216220
}

0 commit comments

Comments
 (0)