annotate mc-macro.c @ 647:fe23fe842b82

*** empty log message ***
author kono
date Fri, 17 Nov 2006 20:00:37 +0900
parents 4b4c6b1ea69a
children 234bc5f79a11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
607
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
1 /* Micro-C Preprocessor Part */
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
2
607
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
3 /************************************************************************
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
4 ** Copyright (C) 2006 Shinji Kono
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
5 ** 連絡先: 琉球大学情報工学科 河野 真治
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
6 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
7 **
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
8 ** このソースのいかなる複写,改変,修正も許諾します。ただし、
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
9 ** その際には、誰が貢献したを示すこの部分を残すこと。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
10 ** 再配布や雑誌の付録などの問い合わせも必要ありません。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
11 ** 営利利用も上記に反しない範囲で許可します。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
12 ** バイナリの配布の際にはversion messageを保存することを条件とします。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
13 ** このプログラムについては特に何の保証もしない、悪しからず。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
14 **
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
15 ** Everyone is permitted to do anything on this program
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
16 ** including copying, modifying, improving,
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
17 ** as long as you don't try to pretend that you wrote it.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
18 ** i.e., the above copyright notice has to appear in all copies.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
19 ** Binary distribution requires original version messages.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
20 ** You don't have to ask before copying, redistribution or publishing.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
21 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
22 ***********************************************************************/
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
23 #include <stdio.h>
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
24 #include "mc.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
25 #include "mc-parse.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
26 #include "mc-macro.h"
456
b8f95294eb77 inline continue... if test passed.
kono
parents: 455
diff changeset
27 #include "mc-codegen.h"
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
28 #include "mc-code.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
29
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
30 extern struct {int fd,ln;char *name0;int inc;FILE *fcb;} *filep,filestack[FILES];
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
31
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
32 int in_macro_if = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
33 char *chinput;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
34
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
35 static int mconcat=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
36
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
37 static void macro_define0();
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
38 static int macro_args(char **pchptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
39 static int macro_function(int macrop,char **pchptr,NMTBL *nptr,int history);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
40 static void local_define(char *macro,char *value);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
41 static int macro_eval(int macrop,char *body0,int history);
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
42 static char * mappend0(int lists,char **result);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
43 static int macro_processing();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
44
561
de0b0380c461 comments
kono
parents: 560
diff changeset
45 /*
de0b0380c461 comments
kono
parents: 560
diff changeset
46
de0b0380c461 comments
kono
parents: 560
diff changeset
47 macro_expansion(NMTBL *nptrm)
de0b0380c461 comments
kono
parents: 560
diff changeset
48 innput macro term (and chptr for arguments)
de0b0380c461 comments
kono
parents: 560
diff changeset
49 result put into cheap, and chptr is set.
de0b0380c461 comments
kono
parents: 560
diff changeset
50 current ch and chptr are pushed into chptr stack.
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
51
561
de0b0380c461 comments
kono
parents: 560
diff changeset
52 ## concatenation requires repeated replace.
de0b0380c461 comments
kono
parents: 560
diff changeset
53
de0b0380c461 comments
kono
parents: 560
diff changeset
54 In macro_function and macro_eavl,
de0b0380c461 comments
kono
parents: 560
diff changeset
55 expand result is put into macrop local variable.
de0b0380c461 comments
kono
parents: 560
diff changeset
56 list2("replaced string",next)
de0b0380c461 comments
kono
parents: 560
diff changeset
57 to generate result, mappend/reverse0 is necessary.
de0b0380c461 comments
kono
parents: 560
diff changeset
58
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
59 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
60
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
61 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
62 macro_expansion(NMTBL *nptrm)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
63 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
64 int i = mode;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
65 int macrop = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
66 int slfree = lfree;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
67 int c;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
68 char *macropp,*s,*t;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
69 struct cheap scheap;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
70 mode = STAT;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
71
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
72 save_cheap(&scheap,cheap);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
73
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
74 // call macro evaluation interpreter
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
75 if (nptrm->sc == FMACRO) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
76 macrop=macro_function(macrop,&chptr,nptrm,0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
77 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
78 macrop=macro_eval(macrop,(char *)car(nptrm->dsp),0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
79 }
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
80
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
81 // copy output from resulted listed string
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
82
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
83 cheap = reset_cheap(&scheap);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
84 macropp = cheap->ptr;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
85 // append result override, working cheap, but it's OK.
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
86 mappend0(reverse0(macrop),&macropp);
564
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
87 // cheap->ptr[-1] ='\n'; // makes some tokenize happy
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
88 // ## macro_result needs \n at end
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
89 cheap->ptr[-1] = 0; // makes some tokenize happy
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
90 t = cheap->ptr-2;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
91 cheap->ptr[0] =0;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
92 cheap = increment_cheap(cheap,&macropp);
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
93
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
94 // if we have ## (concatenation),
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
95 // remove \s**##\s*
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
96 // it is difficult to remove former space on the fly,
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
97 // so multi path loop is required
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
98
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
99 while (mconcat) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
100 // ## re-eval macro
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
101 // if (lsrc) printf("## before %s",macropp);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
102 mconcat = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
103 macrop = 0;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
104 for(s=t=macropp;*s;) {
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
105 if ((c=*s++)=='#'&&*s=='#') {
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
106 if (t>s-3) t=s-2; else t--;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
107 while(*t<=' '&&t>macropp) t--; t++;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
108 for(s++;*s && *s<=' ';) s++;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
109 continue;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
110 }
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
111 *t++=c;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
112 }
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
113 *t++=0;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
114 // evaluate generated result again
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
115 if (0 && lsrc) {
564
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
116 printf("### %s\n",macropp);
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
117 if (t[-2]!='\n') putchar('\n');
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
118 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
119 macrop=macro_eval(macrop,macropp,0);
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
120 cheap = reset_cheap(&scheap);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
121 macropp = cheap->ptr;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
122 // will not override evaled list
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
123 mappend0(reverse0(macrop),&macropp);
564
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
124 // cheap->ptr[-1] ='\n';
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
125 cheap->ptr[-1] =0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
126 cheap->ptr[0] =0;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
127 cheap = increment_cheap(cheap,&macropp);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
128 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
129 cheap = reset_cheap(&scheap);
561
de0b0380c461 comments
kono
parents: 560
diff changeset
130 // genrated macro will be overwrited by cheap, but it's OK, again
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
131 mconcat = 0;
447
818505dd6e1f TYPEOF fix. Hash function opt. Array in decl_data.
kono
parents: 364
diff changeset
132 set_lfree(slfree);
564
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
133 if (lsrc && !asmf && nptrm->sc==FMACRO) {
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
134 gen_comment(macropp);
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
135 if (t[-2]!='\n') putchar('\n');
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
136 }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
137 // push previous chptr, and change it to the generate macro
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
138 chptrsave = glist2((int)chptr,chptrsave); // push old one into the stack
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
139 chsave = glist2(ch,chsave);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
140 chptr = macropp;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
141 ch = *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
142 mode = i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
143 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
144
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
145 /* file inclusion */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
146
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
147 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
148 file name concatenation
561
de0b0380c461 comments
kono
parents: 560
diff changeset
149 on cheap
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
150 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
151
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
152 static char *
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
153 expand_file_name(char *path,char *name)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
154 {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
155 char *p = cheap->ptr;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
156 if (! *path) return name;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
157 while(( *cheap->ptr = *path++ )) cheap = increment_cheap(cheap,&p);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
158 if (cheap->ptr[-1]!='/') {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
159 *cheap->ptr = '/'; cheap = increment_cheap(cheap,&p);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
160 }
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
161 while(( *cheap->ptr = *name++ )) cheap = increment_cheap(cheap,&p);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
162 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
163 cheap = increment_cheap(cheap,&p);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
164 return p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
165 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
166
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
167 /*
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
168 internal string compare routine
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
169 nameeq in mc-parse.c relies on
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
170 global name variable
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
171 */
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
172
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
173 static int
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
174 nameeq(char *p, char *q)
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
175 {
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
176 if (!p)
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
177 return 0;
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
178 while(*p)
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
179 if(*p++ != *q++) return 0;
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
180 return (*q==0);
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
181 }
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
182
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
183 /*
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
184 file name expansion
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
185
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
186 Get file name from input stream.
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
187 Result is store in filep structure.
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
188 included file is put on the filep stack
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
189 return filep
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
190
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
191 filename is copied into cheap
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
192
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
193 possibly expanded by search path (including current
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
194 directory ).
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
195
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
196 get file name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
197 <name> => name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
198 current_file_name_dir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
199 libdir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
200 "name" => name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
201 current_file_name_dir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
202 include_path / name
561
de0b0380c461 comments
kono
parents: 560
diff changeset
203 (no difference?)
de0b0380c461 comments
kono
parents: 560
diff changeset
204 next flag ignores the first occurence.
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
205 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
206
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
207
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
208 static FILE *
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
209 getfname(int next)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
210 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
211 int i,end='"',err=0;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
212 char *s,*p,**pp,*name,*prev=0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
213 FILE *fp;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
214 struct cheap scheap;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
215 name = cheap->ptr;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
216
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
217 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
218 if(skipspc()=='"') { end = '"';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
219 } else if (ch=='<') { end = '>';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
220 } else { error(INCERR); err=1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
221 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
222 for(i=0;(getch()!=end && ch!='\n');) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
223 *cheap->ptr = ch;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
224 cheap = increment_cheap(cheap,&name);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
225 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
226 if(ch=='\n') error(INCERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
227 if (err) return filep->fcb;
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
228 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
229 cheap = increment_cheap(cheap,&name);
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
230 save_cheap(&scheap,cheap);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
231 fp = fopen(name,"r") ;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
232 if (next && fp) { fclose(fp); fp=0; next=0; prev=name; }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
233 if (fp) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
234 p = name;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
235 } else {
556
ef225b589888 s-dandy fix
kono
parents: 553
diff changeset
236 // no deferenced on "" and <>?
ef225b589888 s-dandy fix
kono
parents: 553
diff changeset
237 for(pp=include_path; *pp;pp++) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
238 p = expand_file_name(*pp,name);
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
239 if(prev && nameeq(p,prev)) continue;
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
240 if ((fp = fopen(p,"r"))) {
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
241 if (next) {
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
242 fclose(fp); fp=0; next=0; prev=p;
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
243 continue;
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
244 } else
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
245 break ;
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
246 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
247 }
556
ef225b589888 s-dandy fix
kono
parents: 553
diff changeset
248 if (!fp /* && (end=='>'||filep->inc=='>') */ ) { // <> case only
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
249 for(pp=l_include_path; *pp;pp++) {
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
250 p = expand_file_name(*pp,name);
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
251 if(prev && nameeq(p,prev)) continue;
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
252 if ((fp = fopen(p,"r"))) {
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
253 if (next) {
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
254 fclose(fp); fp=0; next=0; prev=p;
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
255 continue;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
256 } else
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
257 break ;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
258 }
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
259 }
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
260 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
261 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
262 if(!fp) { error(FILERR); return filep->fcb; }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
263 // we have so search current directory of the included file
de0b0380c461 comments
kono
parents: 560
diff changeset
264 // keep track the name
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
265 copy_current_file_dir(s=p);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
266 // File name determined. Dispose extra copies.
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
267 cheap = reset_cheap(&scheap);
561
de0b0380c461 comments
kono
parents: 560
diff changeset
268 // Generated name needs copy.
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
269 if (p!=name) {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
270 name = cheap->ptr;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
271 while((*cheap->ptr = *s++)) cheap = increment_cheap(cheap,&name);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
272 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
273 cheap = increment_cheap(cheap,&name);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
274 }
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
275 // should check filep over flow (sigh...)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
276 (filep+1)->inc = end;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
277 (filep+1)->name0 = name;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
278 return ( (filep+1)->fcb = fp );
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
279 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
280
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
281 /* line input and conversion */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
282
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
283 static int macro_if_depth ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
284 static int macro_if_current ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
285 static int macro_if_skip ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
286
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
287 /* there may extra non-terminate comment after #if/#else directive */
364
c29eebf3eaf4 local label and indirect goto.
kono
parents: 363
diff changeset
288 /* #endif / * hoge */
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
289 /* */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
290 /* */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
291
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
292 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
293 skip_rest_of_line()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
294 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
295 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
296 do {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
297 while(ch!='\n'&&ch!='\r') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
298 if (!in_comment) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
299 if (ch=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
300 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
301 if (ch=='/') in_comment=2;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
302 else if (ch=='*') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
303 in_comment=1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
304 } else continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
305 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
306 } else if (ch=='*') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
307 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
308 if (ch=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
309 in_comment=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
310 return macro_if_skip?0:1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
311 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
312 else continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
313 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
314 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
315 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
316 if (in_comment==1) { getline(); getch(); }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
317 } while(in_comment==1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
318 in_comment=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
319 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
320 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
321
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
322 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
323 getline from chptr or chinput (for internal source)
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
324 with macro processing
561
de0b0380c461 comments
kono
parents: 560
diff changeset
325 generate comment
de0b0380c461 comments
kono
parents: 560
diff changeset
326 generate ST_COMMENT parse tree, in inline mode
de0b0380c461 comments
kono
parents: 560
diff changeset
327 In getch, if chptr is empty, pop chptr stack, if stack is empy
de0b0380c461 comments
kono
parents: 560
diff changeset
328 read from fp.
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
329 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
330
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
331 static int next_eof;
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
332 struct cheap *st_cheap, *cheap1;
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
333 // ST_COMMENT may interfere with other inrement_cheap, so we use
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
334 // another cheap area.
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
335
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
336 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
337 getline(void)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
338 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
339 int i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
340 int c;
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
341 char num[10]; // for 32bit
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
342 char *p;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
343
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
344 if (next_eof) {
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
345 next_eof=0;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
346 error(EOFERR);
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
347 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
348 do {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
349 if (chinput) {
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
350 // some another input source ( init string )
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
351 if (! *chinput) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
352 chinput=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
353 continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
354 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
355 chptr=linebuf;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
356 i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
357 while((*chptr++=c=*chinput++)&&(c!='\n')) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
358 if (++i > LBUFSIZE-2) error(LNERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
359 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
360 } else {
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
361 // get the line from input stream
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
362 lineno++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
363 glineno++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
364 chptr=linebuf;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
365 i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
366 while ((*chptr++ = c = getc(filep->fcb)) != '\n') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
367 if (++i > LBUFSIZE-2) error(LNERR);
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
368 if (c=='\r') {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
369 c = getc(filep->fcb);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
370 if (c == '\n') {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
371 chptr[-1]='\n'; break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
372 } else {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
373 // single cr equal to nl
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
374 ungetc(c,filep->fcb);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
375 chptr[-1]=c='\n'; i--; break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
376 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
377 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
378 if (c==EOF) {
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
379 next_eof=1;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
380 --chptr;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
381 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
382 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
383 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
384 }
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
385
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
386 *chptr = '\0';
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
387 if (lsrc && !asmf && !macro_if_skip && linebuf[0]) {
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
388 gen_comment(linebuf); // #if ed line will not be commented
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
389 if (inmode) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
390 // inline mode
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
391
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
392 // generate inlined line in assembler output
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
393
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
394 int i=0;
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
395 int c;
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
396 // should be done in some init
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
397 if (!st_cheap) {
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
398 st_cheap = cheap1 = new_cheap();
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
399 }
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
400
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
401 p = st_cheap->ptr;
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
402 sprintf(num,"%d: ",lineno);
509
e58848f6ebc1 inline continue...
kono
parents: 469
diff changeset
403 parse = list3(ST_COMMENT,parse,(int)p);
e58848f6ebc1 inline continue...
kono
parents: 469
diff changeset
404 // should contain file name
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
405 c = 0;
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
406 while((*st_cheap->ptr = num[c++]))
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
407 st_cheap = increment_cheap(st_cheap,&p);
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
408 while((c = *st_cheap->ptr = linebuf[i++])) {
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
409 st_cheap = increment_cheap(st_cheap,&p);
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
410 if (c=='\n') {
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
411 *st_cheap->ptr = 0;
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
412 st_cheap = increment_cheap(st_cheap,&p);
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
413 p = st_cheap->ptr;
509
e58848f6ebc1 inline continue...
kono
parents: 469
diff changeset
414 // parse = list3(ST_COMMENT,parse,(int)p);
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
415 sprintf(num,"%d: ",lineno);
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
416 c = 0;
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
417 while((*cheap->ptr = num[c++]))
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
418 st_cheap = increment_cheap(st_cheap,&p);
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
419 }
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
420 }
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
421 }
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
422 }
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
423 p = chptr = linebuf; while(*p==' '||*p=='\t') p++;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
424 if (*p == '#' && !in_comment && !in_quote) {
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
425 // macro directive
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
426 chptr = p;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
427 if (macro_processing()) return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
428 }
647
fe23fe842b82 *** empty log message ***
kono
parents: 625
diff changeset
429 if (c==EOF) break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
430 } while(!in_quote && (macro_if_skip || linebuf[0] == '#'));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
431 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
432
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
433 /* preprocessor directive */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
434
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
435 /* line continuation \\ */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
436
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
437 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
438 check_macro_eof()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
439 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
440 int c;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
441 // can't be in macro expansion
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
442 for(c=0;c<LBUFSIZE-3&&chptr[c];c++);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
443 if (c>0&&chptr[c-1]=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
444 return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
445 } else if (c>0&&chptr[c-1]=='\n') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
446 if (c>0&&chptr[c-2]=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
447 return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
448 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
449 c--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
450 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
451 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
452 chptr[c] = ';';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
453 chptr[c+1] = '\n';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
454 chptr[c+2] = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
455 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
456
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
457 /* #if hoge case */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
458
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
459 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
460 macro_if()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
461 {
599
df04bc5fd5fe *** empty log message ***
kono
parents: 591
diff changeset
462 int i,stype=type; // expr destroy type
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
463 ch= *chptr;
599
df04bc5fd5fe *** empty log message ***
kono
parents: 591
diff changeset
464 in_macro_if = 1; // makes undefined symbol==list2(CONST,0)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
465 check_macro_eof();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
466 getsym(0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
467 /* i=cexpr(expr(1)); #if allow undefined symbols.. */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
468 i=expr(1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
469 in_macro_if = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
470 if (car(i)==CONST) i=cadr(i);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
471 else i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
472 if (ch) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
473 if (chptr[-1]==ch) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
474 /* we are fall into getch(), which lost the last ch */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
475 /* chptr[-1]==ch check is fanatic, but ... */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
476 chptr--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
477 } else error(-1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
478 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
479 macro_if_depth = macro_if_current;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
480 macro_if_skip = !i;
591
0497fa2e2414 *** empty log message ***
kono
parents: 569
diff changeset
481 type=stype;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
482 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
483
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
484 /*
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
485 Macro directive
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
486
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
487 implemented in simple hash
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
488
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
489 */
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
490
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
491 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
492 macro_processing()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
493 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
494 int i;
569
1fcad06b264a gcc4 (ia32)
kono
parents: 564
diff changeset
495 int c=0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
496 int mode_save;
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
497 int next;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
498
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
499 ++chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
500 while (*chptr==' '||*chptr=='\t') ++chptr;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
501 switch(chptr[0]*chptr[1]) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
502 case 'i'*'f':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
503 if ((macroeq("ifdef") || macroeq("ifndef"))) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
504 c = (chptr[-4]=='n');
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
505 macro_if_current++;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
506 if (!macro_if_skip) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
507 // try getsym in IFDEF mode to avoid symbol define
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
508 mode_save = mode; mode = IFDEF;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
509 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
510 i = getsym(0);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
511 mode = mode_save;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
512 macro_if_depth = macro_if_current;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
513 macro_if_skip = (!i)^c;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
514 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
515 return 0;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
516 } else if (macroeq("if")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
517 macro_if_current++;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
518 if (!macro_if_skip) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
519 macro_if();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
520 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
521 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
522 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
523 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
524 case 'e'*'l':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
525 if (macroeq("elif")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
526 if (macro_if_current==0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
527 error(MCERR); /* extra #else */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
528 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
529 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
530 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
531 if (!macro_if_skip || macro_if_skip==2) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
532 macro_if_skip=2;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
533 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
534 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
535 macro_if();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
536 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
537 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
538 } else if (macroeq("else")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
539 if (macro_if_current==0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
540 error(MCERR); /* extra #else */
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
541 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
542 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
543 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
544 if (macro_if_skip==2) ;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
545 else if (macro_if_skip) macro_if_skip=0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
546 else macro_if_skip=1;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
547 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
548 return skip_rest_of_line();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
549 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
550 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
551 case 'e'*'n':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
552 if (macroeq("endif")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
553 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
554 macro_if_skip = 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
555 macro_if_depth = --macro_if_current;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
556 } else {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
557 if (macro_if_current<=0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
558 error(MCERR); /* extra #if */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
559 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
560 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
561 macro_if_current--;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
562 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
563 return skip_rest_of_line();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
564 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
565 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
566 if (macro_if_skip) return 0;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
567 switch(chptr[0]) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
568 case 'd':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
569 if (macroeq("define")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
570 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
571 macro_define0();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
572 *(chptr = linebuf) = '\0';
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
573 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
574 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
575 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
576 case 'u':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
577 if (macroeq("undef")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
578 i=mode;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
579 mode=IFDEF;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
580 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
581 if (getsym(0)) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
582 // make it EMPTY
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
583 if (nptr->sc == MACRO) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
584 nptr->sc = EMPTY;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
585 } else if (nptr->sc == FMACRO) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
586 nptr->sc = EMPTY;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
587 /* we cannot reclaim it's arg */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
588 } else error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
589 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
590 mode=i;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
591 return 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
592 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
593 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
594 case 'i':
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
595 next = 1;
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
596 if (macroeq("include_next")|| (next=0, macroeq("include"))) {
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
597 if(filep+1 >= filestack + FILES) error(FILERR);
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
598 if ( ((filep+1)->fcb=getfname(next)) == NULL) error(FILERR);
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
599 (filep+1)->ln=lineno;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
600 lineno=0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
601 ++filep;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
602 *(chptr = linebuf) = '\0';
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
603 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
604 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
605 break;
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
606 case 'p':
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
607 if (macroeq("pragma")) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
608 getline();
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
609 return 0;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
610 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
611 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
612 #if ASM_CODE
561
de0b0380c461 comments
kono
parents: 560
diff changeset
613 // deprecated, use asm function
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
614 case 'a':
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
615 if (macroeq("asm")) {
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
616 if (asmf) error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
617 asmf = 1;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
618 getline();
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
619 while (asmf) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
620 printf("%s",linebuf);
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
621 getline();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
622 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
623 return 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
624 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
625 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
626 case 'e':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
627 if (macroeq("endasm")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
628 if (!asmf) error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
629 asmf = 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
630 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
631 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
632 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
633 #endif
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
634 case ' ': case '\t': case '\n': case 0:
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
635 getline();
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
636 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
637 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
638 error(MCERR);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
639 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
640 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
641
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
642 extern int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
643 macroeq(char *s)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
644 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
645 char *p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
646
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
647 for (p = chptr; *s;) if (*s++ != *p++) return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
648 chptr = p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
649 return 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
650 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
651
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
652 /* macro interpreter */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
653
561
de0b0380c461 comments
kono
parents: 560
diff changeset
654 /* generate macro define */
de0b0380c461 comments
kono
parents: 560
diff changeset
655
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
656 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
657 macro_define(char *macro)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
658 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
659 char *chptr_save;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
660 int chsave;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
661
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
662 chptr_save = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
663 chsave = ch;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
664 chptr = macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
665 ch= *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
666 macro_define0();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
667 chptr = chptr_save;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
668 ch = chsave;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
669 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
670
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
671 /* macro define from chptr
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
672
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
673 body will be copied and stored in nptr->dsp
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
674 list2( string, list of argments (if any))
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
675 We don't expand macro here, it just copied.
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
676
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
677 */
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
678
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
679 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
680 macro_define0()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
681 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
682 int i,args,c;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
683 char **body;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
684
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
685 i=mode;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
686 mode=MDECL;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
687 // ch= *chptr; ??
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
688 // fprintf(stderr,"macro def: ch %c *chptr %c\n",ch,*chptr);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
689 getsym(0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
690 // fprintf(stderr,"macro def: %s =>",name);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
691 if (nptr->sc != EMPTY) { /* override existing macro */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
692 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
693 args = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
694 if (ch=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
695 nptr->sc = FMACRO;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
696 args = macro_args(&chptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
697 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
698 nptr->sc = MACRO;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
699 nptr->ty = -1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
700 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
701 // equal is allowed for -Dhoge=aho option
534
0f24e1dba811 *** empty log message ***
kono
parents: 527
diff changeset
702 // if (ch=='=') chptr++;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
703 while((c=*chptr)==' '||c=='\t') chptr++;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
704 nptr->dsp = list2((int)cheap->ptr,args); /* macro body */
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
705 body = (char **)&car(nptr->dsp);
561
de0b0380c461 comments
kono
parents: 560
diff changeset
706
de0b0380c461 comments
kono
parents: 560
diff changeset
707 // now copy it to the body
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
708 while ((*cheap->ptr = c = *chptr++)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
709 && c != '\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
710 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
711 if (c=='/'&&chptr[0]=='/') {
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
712 cheap->ptr--;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
713 *cheap->ptr = '\0';
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
714 while(*chptr++); break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
715 } else if (c=='/'&&chptr[0]=='*') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
716 cheap->ptr--; chptr++;
614
e4e007f4026d fix #deifne /* line
kono
parents: 609
diff changeset
717 for(;;) {
e4e007f4026d fix #deifne /* line
kono
parents: 609
diff changeset
718 c = *chptr++;
e4e007f4026d fix #deifne /* line
kono
parents: 609
diff changeset
719 if (!c) {
e4e007f4026d fix #deifne /* line
kono
parents: 609
diff changeset
720 getline();
e4e007f4026d fix #deifne /* line
kono
parents: 609
diff changeset
721 continue;
e4e007f4026d fix #deifne /* line
kono
parents: 609
diff changeset
722 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
723 if (c=='*'&&chptr[0]=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
724 c = *chptr++; break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
725 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
726 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
727 if (!c) break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
728 } else if (c=='\\' && (*chptr=='\n'||*chptr==0)) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
729 chptr++;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
730 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
731 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
732 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
733 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
734 if (c=='\n') {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
735 *cheap->ptr = '\0';
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
736 }
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
737 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
738 // fprintf(stderr,"%s\n",(char *)car(nptr->dsp));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
739 mode=i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
740 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
741
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
742 // create function macro argument list
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
743 // return list2((char*)arg,next)
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
744 // it can be sepearted by \ or comments
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
745 // no expansion
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
746
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
747 static int
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
748 macro_args(char **pchptr)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
749 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
750 int c;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
751 int in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
752 int in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
753 int plevel = 0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
754 char **body;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
755 char *chptr = *pchptr;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
756 int args = list2((int)cheap->ptr,0);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
757 body = (char **)&car(args);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
758 for(;;) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
759 *cheap->ptr = c = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
760 cheap = increment_cheap(cheap,body);
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
761 if (c=='\\') {
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
762 if (*chptr=='\n') {
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
763 cheap->ptr--;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
764 getline();
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
765 chptr = *pchptr;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
766 continue;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
767 }
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
768 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
769 if (!c) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
770 chptr--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
771 error(MCERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
772 *pchptr = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
773 return reverse0(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
774 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
775 if (in_quote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
776 if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
777 if (*chptr != '\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
778 *cheap->ptr = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
779 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
780 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
781 getline();
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
782 chptr = *pchptr;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
783 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
784 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
785 in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
786 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
787 } else if (in_wquote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
788 if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
789 if (*chptr !='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
790 *cheap->ptr = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
791 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
792 } else {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
793 *cheap->ptr = '\n';
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
794 getline();
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
795 chptr = *pchptr;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
796 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
797 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
798 in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
799 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
800 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
801 in_wquote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
802 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
803 in_quote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
804 } if (plevel==0) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
805 if (c==',') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
806 cheap->ptr[-1] = 0;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
807 args = list2((int)cheap->ptr,args);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
808 body = (char **)&car(args);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
809 } else if (c==')') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
810 cheap->ptr[-1] = 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
811 break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
812 } else if (c=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
813 plevel++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
814 } else if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
815 if (*chptr=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
816 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
817 getline();
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
818 chptr = *pchptr;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
819 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
820 // } else if (c==' '||c=='\t') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
821 // cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
822 } else if (c=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
823 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
824 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
825 chptr = *pchptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
826 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
827 } else if (c==')') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
828 plevel--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
829 } else if (c=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
830 plevel++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
831 } else if (c=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
832 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
833 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
834 chptr = *pchptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
835 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
836 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
837 *pchptr = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
838 return reverse0(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
839 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
840
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
841 /* output macro expansion
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
842
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
843 This is a recursive interpreter.
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
844
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
845 result into macrobuf (macropp) */
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
846
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
847 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
848 macro_function(int macrop,char **pchptr,NMTBL *nptr,int history)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
849 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
850 int args,sargs,values,evalues;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
851 char *macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
852
561
de0b0380c461 comments
kono
parents: 560
diff changeset
853 // make argument list
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
854 sargs = args = cadr(nptr->dsp);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
855 values = macro_args(pchptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
856 if (pchptr==&chptr) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
857 ch = *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
858 }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
859 // eval all argument list
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
860 evalues = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
861 while(values) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
862 evalues = list2(macro_eval(0,(char *)car(values),history),evalues);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
863 values = cadr(values);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
864 }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
865 // define all arguments locally
de0b0380c461 comments
kono
parents: 560
diff changeset
866 // #define arg0 arg0_value
de0b0380c461 comments
kono
parents: 560
diff changeset
867 // #define arg1 arg2_value ....
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
868 evalues = reverse0(evalues);
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
869 enter_scope();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
870 while(args) {
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
871 mappend0(reverse0(car(evalues)),&macro);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
872 local_define((char *)car(args),macro);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
873 args = cadr(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
874 evalues = cadr(evalues);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
875 }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
876 // process body replacement
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
877 macro = (char *)car(nptr->dsp);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
878 macrop = macro_eval(macrop,macro,list2((int)macro,history));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
879 args = sargs;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
880 // unbind arguments
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
881 leave_scope();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
882 return macrop;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
883 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
884
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
885 /*
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
886 define name in the local scope
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
887 */
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
888
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
889 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
890 local_define(char *macro,char *value)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
891 {
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
892 NMTBL *nptr0,*nlist;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
893 while(*macro==' '||*macro=='\t') macro++;
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
894 nptr0 = name_space_search(nlist=get_name(macro,0,DEF),MACRO);
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
895 nptr0 = make_local_scope(nlist,nptr0,MACRO);
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
896 nptr0->nm = value;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
897 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
898
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
899 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
900 Evaluate macro string.
625
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
901
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
902 This is a recursive interpreter.
4b4c6b1ea69a *** empty log message ***
kono
parents: 623
diff changeset
903
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
904 reuslt: list2("replaced string",next)
561
de0b0380c461 comments
kono
parents: 560
diff changeset
905 history is necessary to avoid recursion
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
906 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
907
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
908 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
909 macro_eval(int macrop,char *body0,int history)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
910 {
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
911 int c,len;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
912 int in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
913 int in_wquote = 0;
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
914 int string_flag = 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
915 char *macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
916 char *body = body0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
917 char **expand;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
918 NMTBL *nptrm;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
919 macrop = list2((int)cheap->ptr,macrop);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
920 expand = (char **)&car(macrop);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
921 for(; (c = *body++) ;) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
922 if (in_quote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
923 if (c=='\\') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
924 *cheap->ptr = c; c = *body++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
925 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
926 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
927 in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
928 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
929 } else if (in_wquote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
930 if (c=='\\') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
931 *cheap->ptr = c; c = *body++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
932 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
933 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
934 in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
935 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
936 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
937 in_wquote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
938 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
939 in_quote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
940 } else if (c=='#' && *body=='#') {
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
941 mconcat = 1;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
942 // name concatenation. flag only. remove and re-evaluate
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
943 // in the top level. (and skip space)
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
944 } else if (!mconcat && c=='#' && alpha(*body)) {
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
945 // turn into string next macro literal
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
946 string_flag = 1;
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
947 *cheap->ptr = '"';
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
948 cheap = increment_cheap(cheap,expand);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
949 goto names;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
950 } else if (alpha(c)) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
951 // find a name
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
952 body--; // ungetc
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
953 names:
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
954 nptrm = get_name(body,&len,NONDEF);
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
955 if (!nptrm) {
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
956 while((*cheap->ptr = *body++) && len--)
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
957 cheap = increment_cheap(cheap,expand);
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
958 body--;
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
959 if (string_flag) {
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
960 string_flag = 0;
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
961 *cheap->ptr = '"';
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
962 cheap = increment_cheap(cheap,expand);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
963 }
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
964 continue;
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
965 }
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
966 body += len;
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
967 c = *body;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
968 nptrm = name_space_search(nptrm,MACRO);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
969 macro = (char *)car(nptrm->dsp);
561
de0b0380c461 comments
kono
parents: 560
diff changeset
970 // if (check_recurse(macro,history)) goto skip;
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
971 // string_falg = 0;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
972 switch(nptrm->sc) {
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
973 case FMACRO:
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
974 if (c==' '||c=='\t') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
975 while (c==' '||c=='\t') c=*body++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
976 body--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
977 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
978 if(c!='(') error(MCERR);
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
979 *cheap->ptr = 0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
980 cheap = increment_cheap(cheap,expand);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
981 body++;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
982 macrop = macro_function(macrop,&body,nptrm,
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
983 list2((int)macro,history));
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
984 macrop = list2((int)cheap->ptr,macrop);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
985 expand = (char **)&(car(macrop));
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
986 break;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
987 case MACRO:
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
988 if (neqname(nptrm->nm,macro)) {
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
989 if (macro[0]==0) {
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
990 if (string_flag) {
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
991 string_flag = 0;
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
992 *cheap->ptr = '"';
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
993 cheap = increment_cheap(cheap,expand);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
994 }
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
995 continue;
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
996 }
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
997 *cheap->ptr = 0;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
998 cheap = increment_cheap(cheap,expand);
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
999 macrop=macro_eval(macrop,macro,list2((int)macro,history));
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
1000 macrop = list2((int)cheap->ptr,macrop);
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
1001 expand = (char **)&(car(macrop));
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
1002 break;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
1003 }
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
1004 default:
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1005 macro = nptrm->nm;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
1006 // skip:
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
1007 case LMACRO:
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
1008 while((*cheap->ptr = *macro++)/* && len-- */)
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1009 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1010 }
623
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
1011 if (string_flag) {
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
1012 string_flag = 0;
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
1013 *cheap->ptr = '"';
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
1014 cheap = increment_cheap(cheap,expand);
4e08fbf6754b macro stringrise, switch unsginged mungle
kono
parents: 614
diff changeset
1015 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1016 continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1017 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1018 *cheap->ptr = c;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1019 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1020 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1021 *cheap->ptr = 0;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1022 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1023 return macrop;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1024 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1025
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
1026 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
1027 cancat list2("string",next) into cheap.
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
1028 result overwrited by next cheap allocation
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
1029 */
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1030
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1031 static char *
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1032 mappend0(int lists,char **result)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1033 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1034 char *p;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1035 *result = cheap->ptr;
348
e77b3a7002ad name table reconfigure compiled. debug start.
kono
parents: 347
diff changeset
1036 for(;lists;lists = cadr(lists)) {
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1037 p = (char *)car(lists);
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
1038 for(;(*cheap->ptr = *p++);cheap = increment_cheap(cheap,result)) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1039 // in_quote + \n case ? should be \n.
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
1040 if (p[-1]=='\n') cheap->ptr[0]=' ';
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1041 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1042 }
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
1043 cheap = increment_cheap(cheap,result);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
1044 return *result;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1045 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1046
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1047 // do not replace \n
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1048 extern char *
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1049 mappend(int lists,char **result)
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1050 {
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1051 char *p;
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1052 *result = cheap->ptr;
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1053 for(;lists;lists = cadr(lists)) {
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1054 p = (char *)car(lists);
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
1055 for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,result)) {
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1056 // in_quote + \n case ? should be \n.
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1057 // if (p[-1]=='\n') cheap->ptr[0]=' ';
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1058 }
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1059 }
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
1060 cheap = increment_cheap(cheap,result);
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1061 return *result;
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1062 }
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
1063
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1064 /* end */