remove currentDesktop from server request but allow -do macros on new Untitled
[nedit-bw.git] / global-AccumulatorData.patch
blob65a09eef50913f10c344ddcff2efe547dfc0d678
1 ---
3 source/interpret.c | 52 +++++++++++++++++++++++-----------------------------
4 source/interpret.h | 4 ++--
5 source/parse.y | 16 +++++-----------
6 3 files changed, 30 insertions(+), 42 deletions(-)
8 diff --quilt old/source/interpret.h new/source/interpret.h
9 --- old/source/interpret.h
10 +++ new/source/interpret.h
11 @@ -153,7 +153,8 @@ int ArrayCopy(DataValue *dstArray, DataV
13 /* Routines for creating a program, (accumulated beginning with
14 BeginCreatingProgram and returned via FinishCreatingProgram) */
15 -void BeginCreatingProgram(const char *name, AccumulatorData *acc);
16 +AccumulatorData *BeginCreatingProgram(const char *name);
17 +Program *FinishCreatingProgram(AccumulatorData *old);
18 int AddOp(int op, char **msg);
19 int AddSym(Symbol *sym, char **msg);
20 int AddImmediate(int immed, char **msg);
21 @@ -166,7 +167,6 @@ Symbol *InstallStringConstSymbol(const c
22 Symbol *LookupSymbol(const char *name);
23 Symbol *InstallSymbol(const char *name, enum symTypes type, DataValue value);
24 Symbol *InstallMultiAssignExpr(void);
25 -Program *FinishCreatingProgram(AccumulatorData *acc);
26 Inst *SwapCode(Inst *start, Inst *boundary, Inst *end);
27 int StartLoopAddrList(char **msg);
28 int AddBreakAddr(Inst *addr, char **msg);
29 diff --quilt old/source/parse.y new/source/parse.y
30 --- old/source/parse.y
31 +++ new/source/parse.y
32 @@ -101,8 +101,6 @@ static int scanString(void);
34 static char *ErrMsg;
35 static char *InPtr;
36 -extern Inst *LoopStack[]; /* addresses of break, cont stmts */
37 -extern Inst **LoopStackPtr; /* to fill at the end of a loop */
39 static int AllowDefine;
41 @@ -208,7 +206,6 @@ definekw: DEFINE {
44 definesym: SYMBOL {
45 - $$.acc = XtNew(AccumulatorData);
46 /* we can't really be sure, that we not overwrite any
47 ** wrong symbol
49 @@ -225,13 +222,12 @@ definesym: SYMBOL {
50 yyerror("try to override built-in subroutine"); YYERROR;
52 $$.sym = PromoteToGlobal($1);
53 - BeginCreatingProgram($$.sym->name, $$.acc);
54 + $$.acc = BeginCreatingProgram($$.sym->name);
57 define: definekw blank definesym blank blockwb {
58 ADD_OP(OP_RETURN_NO_VAL);
59 Program *prog = FinishCreatingProgram($3.acc);
60 - XtFree((char *)$3.acc);
61 $3.sym->type = MACRO_FUNCTION_SYM;
62 $3.sym->value.tag = NO_TAG;
63 $3.sym->value.val.prog = prog;
64 @@ -853,7 +849,7 @@ Program *ParseMacro(char *expr, char **m
65 const char *name)
67 Program *prog;
68 - AccumulatorData *acc = XtNew(AccumulatorData);
69 + AccumulatorData *old;
71 #if YYDEBUG
72 int oldyydebug = yydebug;
73 @@ -863,7 +859,7 @@ Program *ParseMacro(char *expr, char **m
74 if (!name)
75 name = "--unknown--";
77 - BeginCreatingProgram(name, acc);
78 + old = BeginCreatingProgram(name);
80 /* whether we allow the "define" keyword */
81 AllowDefine = allowDefine;
82 @@ -877,8 +873,7 @@ Program *ParseMacro(char *expr, char **m
83 if (yyparse()) {
84 *msg = ErrMsg;
85 *stoppedAt = InPtr;
86 - FreeProgram(FinishCreatingProgram(acc));
87 - XtFree((char *)acc);
88 + FreeProgram(FinishCreatingProgram(old));
90 #if YYDEBUG
91 yydebug = oldyydebug;
92 @@ -888,8 +883,7 @@ Program *ParseMacro(char *expr, char **m
95 /* get the newly created program */
96 - prog = FinishCreatingProgram(acc);
97 - XtFree((char *)acc);
98 + prog = FinishCreatingProgram(old);
100 /* parse succeeded */
101 *msg = "";
102 diff --quilt old/source/interpret.c new/source/interpret.c
103 --- old/source/interpret.c
104 +++ new/source/interpret.c
105 @@ -165,13 +165,13 @@ static const char *StackUnderflowMsg = "
106 static const char *StringToNumberMsg = "string '%s' could not be converted to number";
108 /* Temporary global data for use while accumulating programs */
109 -static Symbol *LocalSymList = NULL; /* symbols local to the program */
110 -static Inst Prog[PROGRAM_SIZE]; /* the program */
111 -static Inst *ProgP; /* next free spot for code gen. */
112 -static Inst *LoopStack[LOOP_STACK_SIZE]; /* addresses of break, cont stmts */
113 -static Inst **LoopStackPtr = LoopStack; /* to fill at the end of a loop */
115 -static const char *ProgramName = "";
116 +static AccumulatorData *Accumulator;
117 +#define Prog (Accumulator->prog)
118 +#define ProgP (Accumulator->progP)
119 +#define LoopStack (Accumulator->loopStack)
120 +#define LoopStackPtr (Accumulator->loopStackPtr)
121 +#define LocalSymList (Accumulator->localSymList)
122 +#define ProgramName (Accumulator->name)
124 /* Global data for the interpreter */
125 static RestartData *Interpreter;
126 @@ -263,20 +263,17 @@ void InitMacroGlobals(void)
127 ** Start collecting instructions for a program. Clears the program
128 ** and the symbol table.
130 -void BeginCreatingProgram(const char *name, AccumulatorData *acc)
131 +AccumulatorData *BeginCreatingProgram(const char *name)
133 - /* save state */
134 - acc->localSymList = LocalSymList;
135 - memcpy(acc->prog, Prog, sizeof(*Prog) * PROGRAM_SIZE);
136 - acc->progP = ProgP;
137 - memcpy(acc->loopStack, LoopStack, sizeof(*LoopStack) * LOOP_STACK_SIZE);
138 - acc->loopStackPtr = LoopStackPtr;
139 - acc->name = ProgramName;
140 + AccumulatorData *old = Accumulator;
141 + Accumulator = XtNew(AccumulatorData);
143 LocalSymList = NULL;
144 ProgP = Prog;
145 LoopStackPtr = LoopStack;
146 ProgramName = name;
148 + return old;
152 @@ -284,7 +281,7 @@ void BeginCreatingProgram(const char *na
153 ** symbol table) as a package that ExecuteMacro can execute. This
154 ** program must be freed with FreeProgram.
156 -Program *FinishCreatingProgram(AccumulatorData *acc)
157 +Program *FinishCreatingProgram(AccumulatorData *old)
159 Program *newProg;
160 int progLen, fpOffset = 0;
161 @@ -292,9 +289,9 @@ Program *FinishCreatingProgram(Accumulat
163 newProg = XtNew(Program);
164 newProg->name = XtMalloc(strlen(ProgramName) + 1); /* +1 for '\0' */
165 - progLen = ((char *)ProgP) - ((char *)Prog);
166 - newProg->code = (Inst *)XtMalloc(progLen);
167 - memcpy(newProg->code, Prog, progLen);
168 + progLen = ProgP - Prog;
169 + newProg->code = (Inst *)XtCalloc(progLen, sizeof(Inst));
170 + memcpy(newProg->code, Prog, progLen * sizeof(Inst));
171 newProg->localSymList = LocalSymList;
172 strcpy(newProg->name, ProgramName);
173 newProg->refcount = 1;
174 @@ -306,13 +303,8 @@ Program *FinishCreatingProgram(Accumulat
176 DISASM(newProg->name, newProg->code, ProgP - Prog);
178 - /* restore state */
179 - LocalSymList = acc->localSymList;
180 - memcpy(Prog, acc->prog, sizeof(*Prog) * PROGRAM_SIZE);
181 - ProgP = acc->progP;
182 - memcpy(LoopStack, acc->loopStack, sizeof(*LoopStack) * LOOP_STACK_SIZE);
183 - LoopStackPtr = acc->loopStackPtr;
184 - ProgramName = acc->name;
185 + XtFree((char *)Accumulator);
186 + Accumulator = old;
188 return newProg;
190 @@ -930,9 +922,11 @@ Symbol *LookupSymbol(const char *name)
191 hash = hashName(name);
193 /* search in local symbols */
194 - s = lookupSymbol(LocalSymList, name, hash);
195 - if (NULL != s)
196 - return s;
197 + if (Accumulator) {
198 + s = lookupSymbol(LocalSymList, name, hash);
199 + if (NULL != s)
200 + return s;
203 /* search in global symbols */
204 s = lookupSymbol(GlobalSymTab[hash & GLOBAL_SYMTAB_MASK], name, hash);