comment reduxed MultipleAssignment
[nedit-bw.git] / unify-branch-setup.patch
blob9179174bad18ee4cc2c3f5fcd43a7ada46de4fed
1 ---
3 source/interpret.c | 53 +++++++++++++++++++++++++++++++++++++----------------
4 source/interpret.h | 7 ++++---
5 source/parse.y | 36 ++++++++++++++++++++++++++----------
6 3 files changed, 67 insertions(+), 29 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 @@ -387,6 +387,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 @@ -423,34 +433,45 @@ 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 diff --quilt old/source/interpret.h new/source/interpret.h
99 --- old/source/interpret.h
100 +++ new/source/interpret.h
101 @@ -152,6 +152,7 @@ int AddOp(int op, char **msg);
102 int AddSym(Symbol *sym, char **msg);
103 int AddImmediate(int value, char **msg);
104 int AddBranchOffset(Inst *to, char **msg);
105 +int SetBranchOffset(Inst *from, Inst *to, char **msg);
106 Inst *GetPC(void);
107 Symbol *InstallIteratorSymbol(void);
108 Symbol *LookupStringConstSymbol(const char *value);
109 @@ -161,9 +162,9 @@ Symbol *InstallSymbol(const char *name,
110 Symbol *InstallMultiAssignExpr(void);
111 Program *FinishCreatingProgram(AccumulatorData *acc);
112 Inst *SwapCode(Inst *start, Inst *boundary, Inst *end);
113 -void StartLoopAddrList(void);
114 -int AddBreakAddr(Inst *addr);
115 -int AddContinueAddr(Inst *addr);
116 +int StartLoopAddrList(char **msg);
117 +int AddBreakAddr(Inst *addr, char **msg);
118 +int AddContinueAddr(Inst *addr, char **msg);
119 void FillLoopAddrs(Inst *breakAddr, Inst *continueAddr);
121 /* create a permanently allocated static string (only for use with static strings) */
122 diff --quilt old/source/parse.y new/source/parse.y
123 --- old/source/parse.y
124 +++ new/source/parse.y
125 @@ -55,7 +55,27 @@
126 } while (0)
127 #define SET_BR_OFF(from, to) \
128 do { \
129 - ((from)->value) = ((Inst *)(to)) - ((Inst *)(from)); \
130 + if (!SetBranchOffset(from, to, &ErrMsg)) { \
131 + return 1; \
132 + } \
133 + } while (0)
134 +#define START_LOOP() \
135 + do { \
136 + if (!StartLoopAddrList(&ErrMsg)) { \
137 + return 1; \
138 + } \
139 + } while (0)
140 +#define ADD_BREAK(addr) \
141 + do { \
142 + if (!AddBreakAddr(addr, &ErrMsg)) { \
143 + return 1; \
144 + } \
145 + } while (0)
146 +#define ADD_CONTINUE(addr) \
147 + do { \
148 + if (!AddContinueAddr(addr, &ErrMsg)) { \
149 + return 1; \
150 + } \
151 } while (0)
153 /* Max. length for a string constant (... there shouldn't be a maximum) */
154 @@ -309,15 +329,11 @@ stmt: ';' blank
156 | BREAK stmtend blank {
157 ADD_OP(OP_BRANCH); ADD_BR_OFF(0);
158 - if (AddBreakAddr(GetPC()-1)) {
159 - yyerror("break outside loop"); YYERROR;
161 + ADD_BREAK(GetPC() - 1);
163 | CONTINUE stmtend blank {
164 ADD_OP(OP_BRANCH); ADD_BR_OFF(0);
165 - if (AddContinueAddr(GetPC()-1)) {
166 - yyerror("continue outside loop"); YYERROR;
168 + ADD_CONTINUE(GetPC() - 1);
170 | RETURN expr stmtend blank {
171 ADD_OP(OP_RETURN);
172 @@ -775,15 +791,15 @@ numexpropt: blank {
175 while: WHILE blank {
176 - $$ = GetPC(); StartLoopAddrList();
177 + $$ = GetPC(); START_LOOP();
180 do: DO blank {
181 - $$ = GetPC(); StartLoopAddrList();
182 + $$ = GetPC(); START_LOOP();
185 for: FOR blank {
186 - StartLoopAddrList(); $$ = GetPC();
187 + START_LOOP(); $$ = GetPC();
190 else: ELSE blank {