remove currentDesktop from server request but allow -do macros on new Untitled
[nedit-bw.git] / unify-branch-setup.patch
blob38cb0e0db0926b1d7e77a0ef38673809d8576ea9
1 ---
3 source/interpret.c | 66 ++++++++++++++++++++++++++++++++++++-----------------
4 source/interpret.h | 9 ++++---
5 source/parse.y | 58 ++++++++++++++++++++++++++++++++--------------
6 3 files changed, 91 insertions(+), 42 deletions(-)
8 diff --quilt old/source/interpret.c new/source/interpret.c
9 --- old/source/interpret.c
10 +++ new/source/interpret.c
11 @@ -80,7 +80,7 @@ static const char CVSID[] = "$Id: interp
13 enum opStatusCodes {STAT_OK=2, STAT_DONE, STAT_ERROR, STAT_PREEMPT};
15 -static void addLoopAddr(Inst *addr);
16 +static int addLoopAddr(Inst *addr, char **msg);
17 static void saveContext(RestartData *context);
18 static void restoreContext(RestartData *context);
20 @@ -388,6 +388,16 @@ int AddBranchOffset(Inst *to, char **msg
24 +** Set a branch offset to an operand previously added with AddBranchOffset()
25 +*/
26 +int SetBranchOffset(Inst *from, Inst *to, char **msg)
28 + from->value = to - from;
30 + return 1;
33 +/*
34 ** Return the address at which the next instruction will be stored
36 Inst *GetPC(void)
37 @@ -424,43 +434,54 @@ Inst *SwapCode(Inst *start, Inst *bounda
38 ** address for a break or continue statement, and FillLoopAddrs to fill
39 ** in all the addresses and return to the level of the enclosing loop.
41 -void StartLoopAddrList(void)
42 +int StartLoopAddrList(char **msg)
44 - addLoopAddr(NULL);
45 + return addLoopAddr(NULL, msg);
48 -int AddBreakAddr(Inst *addr)
49 +int AddBreakAddr(Inst *addr, char **msg)
51 - if (LoopStackPtr == LoopStack) return 1;
52 - addLoopAddr(addr);
53 + if (LoopStackPtr == LoopStack) {
54 + *msg = "break outside loop";
55 + return 0;
56 + }
57 + if (!addLoopAddr(addr, msg)) {
58 + return 0;
59 + }
60 addr->value = NEEDS_BREAK;
61 - return 0;
62 + return 1;
65 -int AddContinueAddr(Inst *addr)
66 -{
67 - if (LoopStackPtr == LoopStack) return 1;
68 - addLoopAddr(addr);
69 +int AddContinueAddr(Inst *addr, char **msg)
71 + if (LoopStackPtr == LoopStack) {
72 + *msg = "continue outside loop";
73 + return 0;
74 + }
75 + if (!addLoopAddr(addr, msg)) {
76 + return 0;
77 + }
78 addr->value = NEEDS_CONTINUE;
79 - return 0;
80 + return 1;
83 -static void addLoopAddr(Inst *addr)
84 +static int addLoopAddr(Inst *addr, char **msg)
86 - if (LoopStackPtr > &LoopStack[LOOP_STACK_SIZE-1]) {
87 - fprintf(stderr, "NEdit: loop stack overflow in macro parser");
88 - return;
89 + if (LoopStackPtr >= &LoopStack[LOOP_STACK_SIZE]) {
90 + *msg = "loop stack overflow";
91 + return 0;
93 *LoopStackPtr++ = addr;
94 + return 1;
97 -void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr)
98 +int FillLoopAddrs(Inst *breakAddr, Inst *continueAddr, char **msg)
100 while (True) {
101 LoopStackPtr--;
102 if (LoopStackPtr < LoopStack) {
103 - fprintf(stderr, "NEdit: internal error (lsu) in macro parser\n");
104 - return;
105 + *msg = "internal error (lsu)";
106 + return 0;
108 if (*LoopStackPtr == NULL)
109 break;
110 @@ -468,9 +489,12 @@ void FillLoopAddrs(Inst *breakAddr, Inst
111 (*LoopStackPtr)->value = breakAddr - *LoopStackPtr;
112 else if ((*LoopStackPtr)->value == NEEDS_CONTINUE)
113 (*LoopStackPtr)->value = continueAddr - *LoopStackPtr;
114 - else
115 - fprintf(stderr, "NEdit: internal error (uat) in macro parser\n");
116 + else {
117 + *msg = "internal error (uat)";
118 + return 0;
121 + return 1;
125 diff --quilt old/source/interpret.h new/source/interpret.h
126 --- old/source/interpret.h
127 +++ new/source/interpret.h
128 @@ -151,6 +151,7 @@ int AddOp(int op, char **msg);
129 int AddSym(Symbol *sym, char **msg);
130 int AddImmediate(int value, char **msg);
131 int AddBranchOffset(Inst *to, char **msg);
132 +int SetBranchOffset(Inst *from, Inst *to, char **msg);
133 Inst *GetPC(void);
134 Symbol *InstallIteratorSymbol(void);
135 Symbol *LookupStringConstSymbol(const char *value);
136 @@ -160,10 +161,10 @@ Symbol *InstallSymbol(const char *name,
137 Symbol *InstallMultiAssignExpr(void);
138 Program *FinishCreatingProgram(AccumulatorData *acc);
139 Inst *SwapCode(Inst *start, Inst *boundary, Inst *end);
140 -void StartLoopAddrList(void);
141 -int AddBreakAddr(Inst *addr);
142 -int AddContinueAddr(Inst *addr);
143 -void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr);
144 +int StartLoopAddrList(char **msg);
145 +int AddBreakAddr(Inst *addr, char **msg);
146 +int AddContinueAddr(Inst *addr, char **msg);
147 +int FillLoopAddrs(Inst *breakAddr, Inst *continueAddr, char **msg);
149 /* create a permanently allocated static string (only for use with static strings) */
150 #define PERM_ALLOC_STR(xStr) (((char *)("\001" xStr)) + 1)
151 diff --quilt old/source/parse.y new/source/parse.y
152 --- old/source/parse.y
153 +++ new/source/parse.y
154 @@ -55,7 +55,33 @@
155 } while (0)
156 #define SET_BR_OFF(from, to) \
157 do { \
158 - ((from)->value) = ((Inst *)(to)) - ((Inst *)(from)); \
159 + if (!SetBranchOffset(from, to, &ErrMsg)) { \
160 + return 1; \
161 + } \
162 + } while (0)
163 +#define START_LOOP() \
164 + do { \
165 + if (!StartLoopAddrList(&ErrMsg)) { \
166 + return 1; \
167 + } \
168 + } while (0)
169 +#define END_LOOP(breakAddr, continueAddr) \
170 + do { \
171 + if (!FillLoopAddrs(breakAddr, continueAddr, &ErrMsg)) { \
172 + return 1; \
173 + } \
174 + } while (0)
175 +#define ADD_BREAK(addr) \
176 + do { \
177 + if (!AddBreakAddr(addr, &ErrMsg)) { \
178 + return 1; \
179 + } \
180 + } while (0)
181 +#define ADD_CONTINUE(addr) \
182 + do { \
183 + if (!AddContinueAddr(addr, &ErrMsg)) { \
184 + return 1; \
185 + } \
186 } while (0)
188 /* Max. length for a string constant (... there shouldn't be a maximum) */
189 @@ -228,14 +254,16 @@ stmt: ';' blank
191 | while '(' cond ')' blank block {
192 ADD_OP(OP_BRANCH); ADD_BR_OFF($1);
193 - SET_BR_OFF($3, GetPC()); FillLoopAddrs(GetPC(), $1);
194 + SET_BR_OFF($3, GetPC());
195 + END_LOOP(GetPC(), $1);
197 | do block WHILE blank '(' mark cond ')' stmtend blank {
198 ADD_OP(OP_BRANCH); ADD_BR_OFF($1);
199 - SET_BR_OFF($7, GetPC()); FillLoopAddrs(GetPC(), $6);
200 + SET_BR_OFF($7, GetPC());
201 + END_LOOP(GetPC(), $6);
203 | for '(' comastmts ';' cond ';' comastmts ')' blank block {
204 - FillLoopAddrs(GetPC()+2+($7-($5+1)), GetPC());
205 + END_LOOP(GetPC()+2+($7-($5+1)), GetPC());
206 SwapCode($5+1, $7, GetPC());
207 ADD_OP(OP_BRANCH); ADD_BR_OFF($3); SET_BR_OFF($5, GetPC());
209 @@ -253,7 +281,7 @@ stmt: ';' blank
210 ADD_OP(OP_BRANCH);
211 ADD_BR_OFF($7+2);
212 SET_BR_OFF($7+6, GetPC());
213 - FillLoopAddrs(GetPC(), $7+2);
214 + END_LOOP(GetPC(), $7+2);
216 | for '(' blank SYMBOL KEYVAL SYMBOL IN blank arrayexpr blank ')' {
217 Symbol *iterSym = InstallIteratorSymbol();
218 @@ -270,7 +298,7 @@ stmt: ';' blank
219 ADD_OP(OP_BRANCH);
220 ADD_BR_OFF($9+2);
221 SET_BR_OFF($9+7, GetPC());
222 - FillLoopAddrs(GetPC(), $9+2);
223 + END_LOOP(GetPC(), $9+2);
225 | for '(' blank SYMBOL '[' numexpropt ']' IN blank arrayexpr blank ')' {
226 Symbol *iterSym = InstallIteratorSymbol();
227 @@ -286,7 +314,7 @@ stmt: ';' blank
228 ADD_OP(OP_BRANCH);
229 ADD_BR_OFF($10+2);
230 SET_BR_OFF($10+6, GetPC());
231 - FillLoopAddrs(GetPC(), $10+2);
232 + END_LOOP(GetPC(), $10+2);
233 ADD_OP(OP_POP); /* remove nDim from stack */
235 | for '(' blank SYMBOL '[' numexpropt ']' KEYVAL SYMBOL IN blank arrayexpr blank ')' {
236 @@ -304,20 +332,16 @@ stmt: ';' blank
237 ADD_OP(OP_BRANCH);
238 ADD_BR_OFF($12+2);
239 SET_BR_OFF($12+7, GetPC());
240 - FillLoopAddrs(GetPC(), $12+2);
241 + END_LOOP(GetPC(), $12+2);
242 ADD_OP(OP_POP); /* remove nDim from stack */
244 | BREAK stmtend blank {
245 ADD_OP(OP_BRANCH); ADD_BR_OFF(0);
246 - if (AddBreakAddr(GetPC()-1)) {
247 - yyerror("break outside loop"); YYERROR;
249 + ADD_BREAK(GetPC() - 1);
251 | CONTINUE stmtend blank {
252 ADD_OP(OP_BRANCH); ADD_BR_OFF(0);
253 - if (AddContinueAddr(GetPC()-1)) {
254 - yyerror("continue outside loop"); YYERROR;
256 + ADD_CONTINUE(GetPC() - 1);
258 | RETURN expr stmtend blank {
259 ADD_OP(OP_RETURN);
260 @@ -771,15 +795,15 @@ numexpropt: blank {
263 while: WHILE blank {
264 - $$ = GetPC(); StartLoopAddrList();
265 + $$ = GetPC(); START_LOOP();
268 do: DO blank {
269 - $$ = GetPC(); StartLoopAddrList();
270 + $$ = GetPC(); START_LOOP();
273 for: FOR blank {
274 - StartLoopAddrList(); $$ = GetPC();
275 + START_LOOP(); $$ = GetPC();
278 else: ELSE blank {