import a bulk of new patches
[nedit-bw.git] / FP-redux.patch
blobe48e0d00ff3a494c9c786fbc2874cac1c3fb5753
1 ---
3 source/interpret.c | 120 ++++++++++++++++++++++++++++-------------------------
4 1 file changed, 64 insertions(+), 56 deletions(-)
6 diff --quilt old/source/interpret.c new/source/interpret.c
7 --- old/source/interpret.c
8 +++ new/source/interpret.c
9 @@ -189,31 +189,39 @@ static int (*OpFns[])() = {
12 /* Stack-> symN-sym0(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... */
13 -#define FP_ARG_COUNT_INDEX (-1)
14 -#define FP_FUNCTION_NAME (-2) /* !! */
15 -#define FP_SYMBOL_TABLE (-3) /* !! */
16 -#define FP_LOOP_CNT (-4)
17 -#define FP_OLD_LOOP_PTR (-5)
18 -#define FP_OLD_FP_INDEX (-6)
19 -#define FP_RET_PC_INDEX (-7)
20 -#define FP_PROG_INDEX (-8)
21 -#define FP_ARG_ARRAY_INDEX (-9)
23 -#define FP_TO_ARGS_DIST (0 - FP_ARG_ARRAY_INDEX) /* should be 0 - (above index) */
25 -#define FP_GET_ITEM(xFrameP,xIndex) (*(xFrameP + xIndex))
26 -#define FP_GET_ARG_ARRAY(xFrameP) (FP_GET_ITEM(xFrameP, FP_ARG_ARRAY_INDEX))
27 -#define FP_GET_ARG_COUNT(xFrameP) (FP_GET_ITEM(xFrameP, FP_ARG_COUNT_INDEX).val.n)
28 -#define FP_GET_OLD_FP(xFrameP) ((FP_GET_ITEM(xFrameP, FP_OLD_FP_INDEX)).val.dataval)
29 -#define FP_GET_RET_PC(xFrameP) ((FP_GET_ITEM(xFrameP, FP_RET_PC_INDEX)).val.inst)
30 -#define FP_GET_PROG(xFrameP) ((FP_GET_ITEM(xFrameP, FP_PROG_INDEX)).val.prog)
31 -#define FP_GET_FUNCTION_NAME(xFrameP) ((FP_GET_ITEM(xFrameP, FP_FUNCTION_NAME)).val.str)
32 -#define FP_ARG_START_INDEX(xFrameP) (-(FP_GET_ARG_COUNT(xFrameP) + FP_TO_ARGS_DIST))
33 -#define FP_GET_ARG_N(xFrameP,xN) (FP_GET_ITEM(xFrameP, xN + FP_ARG_START_INDEX(xFrameP)))
34 -#define FP_GET_SYM_TAB(xFrameP) (FP_GET_ITEM(xFrameP, FP_SYMBOL_TABLE).val.sym)
35 -#define LocalSymList FP_GET_SYM_TAB(Interpreter->frameP)
36 -#define FP_GET_OLD_LOOP_PTR(xFrameP) (FP_GET_ITEM(xFrameP, FP_OLD_LOOP_PTR).val.instp)
37 -#define FP_GET_LOOP_CNT(xFrameP) (FP_GET_ITEM(xFrameP, FP_LOOP_CNT).val.n)
38 +enum {
39 + FP_BASE = 0, /* first element of current frame, not used */
40 + FP_ARG_COUNT, /* nArgs */
41 + FP_NAME, /* function name */
42 + FP_LOCAL_SYMS, /* local symbol list */
43 + FP_LOOP_CNT, /* loop counter */
44 + FP_OLD_LP, /* old loop pointer */
45 + FP_OLD_FP, /* old frame pointer */
46 + FP_RET_PC, /* return PC */
47 + FP_PROG, /* the program */
48 + FP_ARG_ARRAY, /* argument array */
49 + FP_LAST_ARG /* last arg, i.e. argN, used for FP_DIST_TO_ARGS */
50 +};
51 +#define FP_DIST_TO_ARGS (FP_LAST_ARG - 1)
53 +#define FP_GET(xFrameP, xIndex) (*((xFrameP) - (xIndex)))
55 +/* arguments */
56 +#define FP_ARG1_INDEX(xFrameP) (FP_GET_ARG_COUNT(xFrameP) + FP_DIST_TO_ARGS)
57 +/* zero based */
58 +#define FP_GET_ARG_N(xFrameP, xN) (FP_GET(xFrameP, FP_ARG1_INDEX(xFrameP) - (xN)))
60 +#define FP_GET_ARG_ARRAY(xFrameP) (FP_GET(xFrameP, FP_ARG_ARRAY))
61 +#define FP_GET_PROG(xFrameP) (FP_GET(xFrameP, FP_PROG).val.prog)
62 +#define FP_GET_RET_PC(xFrameP) (FP_GET(xFrameP, FP_RET_PC).val.inst)
63 +#define FP_GET_OLD_FP(xFrameP) (FP_GET(xFrameP, FP_OLD_FP).val.dataval)
64 +#define FP_GET_OLD_LP(xFrameP) (FP_GET(xFrameP, FP_OLD_LP).val.instp)
65 +#define FP_GET_LOOP_CNT(xFrameP) (FP_GET(xFrameP, FP_LOOP_CNT).val.n)
66 +#define FP_GET_LOCAL_SYMS(xFrameP) (FP_GET(xFrameP, FP_LOCAL_SYMS).val.sym)
67 +#define FP_GET_NAME(xFrameP) (FP_GET(xFrameP, FP_NAME).val.str)
68 +#define FP_GET_ARG_COUNT(xFrameP) (FP_GET(xFrameP, FP_ARG_COUNT).val.n)
70 +#define LocalSymList FP_GET_LOCAL_SYMS(Interpreter->frameP)
71 #define LoopStackCnt FP_GET_LOOP_CNT(Interpreter->frameP)
74 @@ -548,12 +556,12 @@ static int setupNestedFrame(RestartData
75 int nArgs = FP_GET_ARG_COUNT(context->frameP);
76 DataValue *args = &FP_GET_ARG_N(context->frameP, 0);
77 DataValue argArray = FP_GET_ARG_ARRAY(context->frameP);
78 - Symbol *symList = FP_GET_SYM_TAB(context->frameP);
79 + Symbol *symList = FP_GET_LOCAL_SYMS(context->frameP);
81 ret = setupFrame(context, prog, nArgs, args, argArray, prog->name);
83 if (ret == STAT_OK) {
84 - FP_GET_SYM_TAB(context->frameP) = symList;
85 + FP_GET_LOCAL_SYMS(context->frameP) = symList;
88 return STAT_OK;
89 @@ -566,7 +574,7 @@ static void rewindFrame(RestartData *con
90 DataValue *newFrameP = FP_GET_OLD_FP(context->frameP);
91 Inst *newPC = FP_GET_RET_PC(context->frameP);
92 Program *prog = FP_GET_PROG(context->frameP);
93 - Symbol *symList = FP_GET_SYM_TAB(context->frameP);
94 + Symbol *symList = FP_GET_LOCAL_SYMS(context->frameP);
95 int isNestedFrame = prog->nested;
97 /* pop remaining vars on the stack and free any array iterators */
98 @@ -579,10 +587,10 @@ static void rewindFrame(RestartData *con
101 /* pop past arguments */
102 - context->stackP -= (FP_TO_ARGS_DIST + nArgs);
103 + context->stackP -= (FP_DIST_TO_ARGS + nArgs);
105 /* restore loop stack pointer */
106 - context->loopStackPtr = FP_GET_OLD_LOOP_PTR(context->frameP);
107 + context->loopStackPtr = FP_GET_OLD_LP(context->frameP);
109 context->frameP = newFrameP;
111 @@ -595,7 +603,7 @@ static void rewindFrame(RestartData *con
113 else {
114 /* copy the local symlist back to this frame */
115 - FP_GET_SYM_TAB(context->frameP) = symList;
116 + FP_GET_LOCAL_SYMS(context->frameP) = symList;
120 @@ -1514,7 +1522,7 @@ static int pushSymVal(void)
122 else if (argNum == MACRO_NAME_ARG_VAR) {
123 symVal.tag = STRING_TAG;
124 - symVal.val.str = FP_GET_FUNCTION_NAME(FrameP);
125 + symVal.val.str = FP_GET_NAME(FrameP);
127 else {
128 symVal = FP_GET_ARG_N(FrameP, argNum);
129 @@ -3028,7 +3036,7 @@ static int returnValOrNone(int valOnStac
130 static DataValue noValue = {NO_TAG, {0}};
132 DISASM_RT();
133 - STACKDUMP(StackP - FrameP + FP_GET_ARG_COUNT(FrameP) + FP_TO_ARGS_DIST, 3);
134 + STACKDUMP(StackP - FrameP + FP_GET_ARG_COUNT(FrameP) + FP_DIST_TO_ARGS, 3);
136 /* return value is on the stack */
137 if (valOnStack) {
138 @@ -4424,7 +4432,7 @@ static char *stackDumpStr(RestartData *c
139 nFrames = 0;
140 do {
141 nFrames++;
142 - len = len + FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.len + 1;
143 + len = len + FP_GET_NAME(nfp).len + 1;
144 pc = FP_GET_RET_PC(nfp);
145 nfp = FP_GET_OLD_FP(nfp);
146 } while (pc);
147 @@ -4462,7 +4470,7 @@ static char *stackDumpStr(RestartData *c
148 while (thisFrameWidth++ < frameWidth)
149 *np++ = ' ';
150 *np++ = ' ';
151 - op = FP_GET_ITEM(nfp, FP_FUNCTION_NAME).val.str.rep;
152 + op = FP_GET_NAME(nfp).rep;
153 while (*op)
154 *np++ = *op++;
155 pc = FP_GET_RET_PC(nfp);
156 @@ -5034,14 +5042,14 @@ static void stackdumpframe(DataValue *ar
157 Inst *retPC = FP_GET_RET_PC(fp);
158 DataValue *oldFP = retPC ? FP_GET_OLD_FP(fp) : NULL;
159 DataValue *arg1 = &FP_GET_ARG_N(fp, 0);
160 - DataValue *argc = &FP_GET_ITEM(fp, FP_ARG_COUNT_INDEX);
161 - DataValue *fnNm = &FP_GET_ITEM(fp, FP_FUNCTION_NAME);
162 - DataValue *prFP = &FP_GET_ITEM(fp, FP_PROG_INDEX);
163 - DataValue *ofFP = &FP_GET_ITEM(fp, FP_OLD_FP_INDEX);
164 - DataValue *rpFP = &FP_GET_ITEM(fp, FP_RET_PC_INDEX);
165 - DataValue *lsFP = &FP_GET_ITEM(fp, FP_SYMBOL_TABLE);
166 - DataValue *lcFP = &FP_GET_ITEM(fp, FP_LOOP_CNT);
167 - DataValue *olFP = &FP_GET_ITEM(fp, FP_OLD_LOOP_PTR);
168 + DataValue *argc = &FP_GET(fp, FP_ARG_COUNT);
169 + DataValue *fnNm = &FP_GET(fp, FP_NAME);
170 + DataValue *prFP = &FP_GET(fp, FP_PROG);
171 + DataValue *ofFP = &FP_GET(fp, FP_OLD_FP);
172 + DataValue *rpFP = &FP_GET(fp, FP_RET_PC);
173 + DataValue *lsFP = &FP_GET(fp, FP_LOCAL_SYMS);
174 + DataValue *lcFP = &FP_GET(fp, FP_LOOP_CNT);
175 + DataValue *olFP = &FP_GET(fp, FP_OLD_LP);
176 DataValue *dv;
177 DataValue *endDv = (arg1 > outpt) ? arg1 : outpt;
178 int nArgs = FP_GET_ARG_COUNT(fp);
179 @@ -5067,27 +5075,27 @@ static void stackdumpframe(DataValue *ar
181 char *pos = "";
182 char buffer[sizeof(STACK_DUMP_ARG_PREFIX) + TYPE_INT_STR_SIZE(int)];
183 - int offset = dv - fp;
184 + int offset = fp - dv;
185 const char *leadIn = (dv >= arrow) ? ">>>>>" :
186 (dv == arg1) ? "---->" :
187 (dv == argc) ? "====>" : "";
188 printd("%5.5s%10p%c", leadIn, dv, topMark);
189 switch (offset) {
190 - case FP_ARG_COUNT_INDEX: pos = "NArgs"; break; /* num. arguments */
191 - case FP_FUNCTION_NAME: pos = "FnName"; break;
192 - case FP_SYMBOL_TABLE: pos = "FnSyms"; break;
193 - case FP_LOOP_CNT: pos = "LoopCnt";break;
194 - case FP_OLD_LOOP_PTR: pos = "OldLP"; break;
195 - case FP_OLD_FP_INDEX: pos = "OldFP"; break;
196 - case FP_RET_PC_INDEX: pos = "RetPC"; break;
197 - case FP_PROG_INDEX: pos = "Prog"; break;
198 - case FP_ARG_ARRAY_INDEX: pos = "args[]"; break; /* argument array */
199 + case FP_ARG_COUNT: pos = "NArgs"; break; /* num. arguments */
200 + case FP_NAME: pos = "FnName"; break;
201 + case FP_LOCAL_SYMS: pos = "FnSyms"; break;
202 + case FP_LOOP_CNT: pos = "LoopCnt"; break;
203 + case FP_OLD_LP: pos = "OldLP"; break;
204 + case FP_OLD_FP: pos = "OldFP"; break;
205 + case FP_RET_PC: pos = "RetPC"; break;
206 + case FP_PROG: pos = "Prog"; break;
207 + case FP_ARG_ARRAY: pos = "args[]"; break; /* argument array */
208 default:
209 - if (offset < -FP_TO_ARGS_DIST &&
210 - offset >= -FP_TO_ARGS_DIST - nArgs)
211 + if (offset > FP_DIST_TO_ARGS &&
212 + offset <= FP_DIST_TO_ARGS + nArgs)
214 sprintf(pos = buffer, STACK_DUMP_ARG_PREFIX "%d",
215 - offset + FP_TO_ARGS_DIST + nArgs + 1);
216 + FP_DIST_TO_ARGS + nArgs + 1 - offset);
218 break;