annotate mc-macro.c @ 364:c29eebf3eaf4 local-label-indirect-goto

local label and indirect goto.
author kono
date Tue, 06 Jul 2004 17:55:40 +0900
parents f3f2b7906d50
children 818505dd6e1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1 /* Micro-C Preprocessor Part */ /* $Id$ */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
2
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
3 #include <stdio.h>
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
4 #include "mc.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
5 #include "mc-parse.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
6 #include "mc-macro.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
7 #include "mc-code.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
8
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
9 extern struct {int fd,ln;char *name0;int inc;FILE *fcb;} *filep,filestack[FILES];
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
10
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
11 int in_macro_if = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
12 char *chinput;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
13
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
14 static int mconcat=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
15
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
16 static void macro_define0();
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
17 static int macro_args(char **pchptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
18 static int macro_function(int macrop,char **pchptr,NMTBL *nptr,int history);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
19 static void local_define(char *macro,char *value);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
20 static int macro_eval(int macrop,char *body0,int history);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
21 static char * mappend(int lists,char **result);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
22 static int macro_processing();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
23
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
24 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
25 gen_source(char *s)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
26 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
27 printf("%s",s);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
28 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
29
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
30 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
31 replace macro term into cheap.
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
32 ## concatenation requires repeated replace.
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
33 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
34
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
35 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
36 macro_expansion(NMTBL *nptrm)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
37 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
38 int i = mode;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
39 int macrop = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
40 int slfree = lfree;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
41 char *macropp;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
42 struct cheap scheap;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
43 mode = STAT;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
44
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
45 save_cheap(&scheap,cheap);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
46
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
47 if (nptrm->sc == FMACRO) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
48 macrop=macro_function(macrop,&chptr,nptrm,0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
49 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
50 macrop=macro_eval(macrop,(char *)car(nptrm->dsp),0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
51 }
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
52 cheap = reset_cheap(&scheap);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
53 macropp = cheap->ptr;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
54 // we can reset cheap, no page wrap in this case
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
55 mappend(reverse0(macrop),&macropp);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
56 cheap->ptr[-1] ='\n';
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
57 cheap->ptr[0] =0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
58 while (mconcat) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
59 // ## re-eval macro
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
60 printf("## %s",macropp);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
61 mconcat = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
62 macrop = 0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
63 macrop=macro_eval(macrop,macropp,0);
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
64 cheap = reset_cheap(&scheap);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
65 macropp = cheap->ptr;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
66 // will not override evaled list
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
67 mappend(reverse0(macrop),&macropp);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
68 cheap->ptr[-1] ='\n';
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
69 cheap->ptr[0] =0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
70 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
71 cheap = reset_cheap(&scheap);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
72 mconcat = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
73 lfree = slfree;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
74 if (lsrc && !asmf && nptrm->sc==FMACRO) gen_comment(macropp);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
75 chptrsave = glist2((int)chptr,chptrsave);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
76 chsave = glist2(ch,chsave);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
77 chptr = macropp;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
78 ch = *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
79 mode = i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
80 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
81
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
82 /* file inclusion */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
83
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
84 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
85 file name concatenation
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
86 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
87
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
88 static char *
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
89 expand_file_name(char *path,char *name)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
90 {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
91 char *p = cheap->ptr;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
92 if (! *path) return name;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
93 while(( *cheap->ptr = *path++ )) cheap = increment_cheap(cheap,&p);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
94 if (cheap->ptr[-1]!='/') {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
95 *cheap->ptr = '/'; cheap = increment_cheap(cheap,&p);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
96 }
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
97 while(( *cheap->ptr = *name++ )) cheap = increment_cheap(cheap,&p);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
98 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
99 cheap = increment_cheap(cheap,&p);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
100 return p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
101 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
102
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
103 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
104 get file name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
105 <name> => name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
106 current_file_name_dir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
107 libdir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
108 "name" => name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
109 current_file_name_dir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
110 include_path / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
111 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
112
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
113 static FILE *
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
114 getfname(void)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
115 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
116 int i,end='"',err=0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
117 char *s,*p,**pp,*name;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
118 FILE *fp;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
119 struct cheap scheap;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
120 name = cheap->ptr;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
121
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
122 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
123 if(skipspc()=='"') { end = '"';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
124 } else if (ch=='<') { end = '>';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
125 } else { error(INCERR); err=1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
126 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
127 for(i=0;(getch()!=end && ch!='\n');) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
128 *cheap->ptr = ch;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
129 cheap = increment_cheap(cheap,&name);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
130 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
131 if(ch=='\n') error(INCERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
132 if (err) return filep->fcb;
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
133 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
134 cheap = increment_cheap(cheap,&name);
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
135 save_cheap(&scheap,cheap);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
136 fp = fopen(name,"r") ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
137 if (fp) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
138 p = name;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
139 } else {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
140 for(pp=(end=='>'||filep->inc=='>') ?l_include_path:include_path;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
141 *pp;pp++) {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
142 p = expand_file_name(*pp,name);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
143 if ((fp = fopen(p,"r"))) break ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
144 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
145 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
146 if(!fp) { error(FILERR); return filep->fcb; }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
147 copy_current_file_dir(s=p);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
148 // File name determined. Dispose extra copies.
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
149 cheap = reset_cheap(&scheap);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
150 if (p!=name) {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
151 name = cheap->ptr;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
152 while((*cheap->ptr = *s++)) cheap = increment_cheap(cheap,&name);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
153 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
154 cheap = increment_cheap(cheap,&name);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
155 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
156 (filep+1)->inc = end;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
157 (filep+1)->name0 = name;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
158 return ( (filep+1)->fcb = fp );
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
159 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
160
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
161 /* line input and conversion */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
162
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
163 static int macro_if_depth ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
164 static int macro_if_current ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
165 static int macro_if_skip ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
166
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
167 /* there may extra non-terminate comment after #if/#else directive */
364
c29eebf3eaf4 local label and indirect goto.
kono
parents: 363
diff changeset
168 /* #endif / * hoge */
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
169 /* */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
170 /* */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
171
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
172 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
173 skip_rest_of_line()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
174 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
175 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
176 do {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
177 while(ch!='\n'&&ch!='\r') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
178 if (!in_comment) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
179 if (ch=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
180 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
181 if (ch=='/') in_comment=2;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
182 else if (ch=='*') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
183 in_comment=1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
184 } else continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
185 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
186 } else if (ch=='*') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
187 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
188 if (ch=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
189 in_comment=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
190 return macro_if_skip?0:1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
191 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
192 else continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
193 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
194 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
195 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
196 if (in_comment==1) { getline(); getch(); }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
197 } while(in_comment==1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
198 in_comment=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
199 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
200 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
201
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
202 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
203 getline from chptr or chinput (for internal source)
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
204 with macro processing
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
205 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
206
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
207 static int next_eof;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
208
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
209 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
210 getline(void)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
211 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
212 int i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
213 int c;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
214
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
215 if (next_eof) {
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
216 next_eof=0;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
217 error(EOFERR);
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
218 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
219 do {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
220 if (chinput) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
221 if (! *chinput) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
222 chinput=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
223 continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
224 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
225 chptr=linebuf;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
226 i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
227 while((*chptr++=c=*chinput++)&&(c!='\n')) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
228 if (++i > LBUFSIZE-2) error(LNERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
229 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
230 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
231 lineno++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
232 glineno++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
233 chptr=linebuf;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
234 i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
235 while ((*chptr++ = c = getc(filep->fcb)) != '\n') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
236 if (++i > LBUFSIZE-2) error(LNERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
237 if (c==EOF) {
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
238 next_eof=1;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
239 --chptr;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
240 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
241 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
242 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
243 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
244 *chptr = '\0';
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
245 if (lsrc && !asmf && !macro_if_skip && linebuf[0]) gen_comment(linebuf);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
246 if (*(chptr = linebuf) == '#' && !in_comment && !in_quote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
247 if (macro_processing()) return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
248 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
249 } while(!in_quote && (macro_if_skip || linebuf[0] == '#'));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
250 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
251
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
252 /* preprocessor directive */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
253
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
254 /* line continuation \\ */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
255
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
256 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
257 check_macro_eof()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
258 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
259 int c;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
260 // can't be in macro expansion
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
261 for(c=0;c<LBUFSIZE-3&&chptr[c];c++);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
262 if (c>0&&chptr[c-1]=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
263 return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
264 } else if (c>0&&chptr[c-1]=='\n') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
265 if (c>0&&chptr[c-2]=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
266 return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
267 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
268 c--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
269 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
270 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
271 chptr[c] = ';';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
272 chptr[c+1] = '\n';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
273 chptr[c+2] = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
274 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
275
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
276 /* #if hoge case */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
277
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
278 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
279 macro_if()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
280 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
281 int i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
282 ch= *chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
283 in_macro_if = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
284 check_macro_eof();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
285 getsym(0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
286 /* i=cexpr(expr(1)); #if allow undefined symbols.. */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
287 i=expr(1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
288 in_macro_if = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
289 if (car(i)==CONST) i=cadr(i);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
290 else i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
291 if (ch) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
292 if (chptr[-1]==ch) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
293 /* we are fall into getch(), which lost the last ch */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
294 /* chptr[-1]==ch check is fanatic, but ... */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
295 chptr--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
296 } else error(-1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
297 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
298 macro_if_depth = macro_if_current;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
299 macro_if_skip = !i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
300 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
301
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
302 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
303 macro_processing()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
304 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
305 int i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
306 int c;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
307 int mode_save;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
308
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
309 ++chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
310 while (*chptr==' '||*chptr=='\t') ++chptr;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
311 switch(chptr[0]*chptr[1]) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
312 case 'i'*'f':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
313 if ((macroeq("ifdef") || macroeq("ifndef"))) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
314 c = (chptr[-4]=='n');
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
315 macro_if_current++;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
316 if (!macro_if_skip) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
317 mode_save = mode; mode = IFDEF;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
318 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
319 i = getsym(0);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
320 mode = mode_save;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
321 macro_if_depth = macro_if_current;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
322 macro_if_skip = (!i)^c;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
323 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
324 return 0;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
325 } else if (macroeq("if")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
326 macro_if_current++;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
327 if (!macro_if_skip) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
328 macro_if();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
329 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
330 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
331 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
332 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
333 case 'e'*'l':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
334 if (macroeq("elif")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
335 if (macro_if_current==0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
336 error(MCERR); /* extra #else */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
337 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
338 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
339 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
340 if (!macro_if_skip || macro_if_skip==2) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
341 macro_if_skip=2;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
342 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
343 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
344 macro_if();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
345 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
346 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
347 } else if (macroeq("else")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
348 if (macro_if_current==0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
349 error(MCERR); /* extra #else */
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
350 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
351 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
352 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
353 if (macro_if_skip==2) ;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
354 else if (macro_if_skip) macro_if_skip=0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
355 else macro_if_skip=1;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
356 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
357 return skip_rest_of_line();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
358 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
359 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
360 case 'e'*'n':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
361 if (macroeq("endif")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
362 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
363 macro_if_skip = 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
364 macro_if_depth = --macro_if_current;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
365 } else {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
366 if (macro_if_current<=0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
367 error(MCERR); /* extra #if */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
368 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
369 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
370 macro_if_current--;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
371 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
372 return skip_rest_of_line();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
373 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
374 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
375 if (macro_if_skip) return 0;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
376 switch(chptr[0]) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
377 case 'd':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
378 if (macroeq("define")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
379 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
380 macro_define0();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
381 *(chptr = linebuf) = '\0';
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
382 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
383 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
384 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
385 case 'u':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
386 if (macroeq("undef")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
387 i=mode;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
388 mode=IFDEF;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
389 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
390 if (getsym(0)) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
391 if (nptr->sc == MACRO) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
392 nptr->sc = EMPTY;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
393 } else if (nptr->sc == FMACRO) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
394 nptr->sc = EMPTY;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
395 /* we cannot reclaim it's arg */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
396 } else error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
397 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
398 mode=i;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
399 return 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
400 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
401 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
402 case 'i':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
403 if (macroeq("include")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
404 if(filep+1 >= filestack + FILES) error(FILERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
405 if ( ((filep+1)->fcb=getfname()) == NULL) error(FILERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
406 (filep+1)->ln=lineno;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
407 lineno=0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
408 ++filep;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
409 *(chptr = linebuf) = '\0';
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
410 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
411 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
412 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
413 #if ASM_CODE
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
414 case 'a':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
415 if (c=='a'&&macroeq("asm")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
416 if (asmf) error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
417 asmf = 1;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
418 getline();
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
419 while (asmf) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
420 gen_source(linebuf);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
421 getline();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
422 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
423 return 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
424 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
425 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
426 case 'e':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
427 if (macroeq("endasm")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
428 if (!asmf) error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
429 asmf = 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
430 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
431 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
432 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
433 #endif
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
434 case ' ': case '\t':
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
435 getline();
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
436 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
437 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
438 error(MCERR);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
439 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
440 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
441
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
442 extern int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
443 macroeq(char *s)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
444 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
445 char *p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
446
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
447 for (p = chptr; *s;) if (*s++ != *p++) return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
448 chptr = p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
449 return 1;
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 /* macro interpreter */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
453
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
454 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
455 macro_define(char *macro)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
456 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
457 char *chptr_save;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
458 int chsave;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
459
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
460 chptr_save = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
461 chsave = ch;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
462 chptr = macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
463 ch= *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
464 macro_define0();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
465 chptr = chptr_save;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
466 ch = chsave;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
467 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
468
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
469 /* macro define from chptr */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
470
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
471 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
472 macro_define0()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
473 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
474 int i,args,c;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
475 char **body;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
476
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
477 i=mode;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
478 mode=MDECL;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
479 // ch= *chptr; ??
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
480 // fprintf(stderr,"macro def: ch %c *chptr %c\n",ch,*chptr);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
481 getsym(0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
482 // fprintf(stderr,"macro def: %s =>",name);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
483 if (nptr->sc != EMPTY) { /* override existing macro */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
484 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
485 args = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
486 if (ch=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
487 nptr->sc = FMACRO;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
488 args = macro_args(&chptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
489 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
490 nptr->sc = MACRO;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
491 nptr->ty = -1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
492 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
493 // equal is allowed for -Dhoge=aho option
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
494 if (ch=='=') chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
495 while((c=*chptr)==' '||c=='\t') chptr++;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
496 nptr->dsp = list2((int)cheap->ptr,args); /* macro body */
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
497 body = (char **)&car(nptr->dsp);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
498 while ((*cheap->ptr = c = *chptr++)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
499 && c != '\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
500 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
501 if (c=='/'&&chptr[0]=='/') {
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
502 cheap->ptr--;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
503 *cheap->ptr = '\0';
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
504 while(*chptr++); break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
505 } else if (c=='/'&&chptr[0]=='*') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
506 cheap->ptr--; chptr++;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
507 while((c = *chptr++)) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
508 if (c=='*'&&chptr[0]=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
509 c = *chptr++; break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
510 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
511 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
512 if (!c) break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
513 } else if (c=='\\' && (*chptr=='\n'||*chptr==0)) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
514 chptr++;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
515 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
516 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
517 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
518 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
519 if (c=='\n') {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
520 *cheap->ptr = '\0';
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
521 }
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
522 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
523 // fprintf(stderr,"%s\n",(char *)car(nptr->dsp));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
524 mode=i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
525 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
526
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
527 // create function macro argument list
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
528 // return list2((char*)arg,next)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
529
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
530 static int
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
531 macro_args(char **pchptr)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
532 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
533 int c;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
534 int in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
535 int in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
536 int plevel = 0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
537 char **body;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
538 char *chptr = *pchptr;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
539 int args = list2((int)cheap->ptr,0);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
540 body = (char **)&car(args);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
541 for(;;) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
542 *cheap->ptr = c = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
543 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
544 if (!c) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
545 chptr--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
546 error(MCERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
547 *pchptr = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
548 return reverse0(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
549 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
550 if (in_quote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
551 if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
552 if (*chptr != '\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
553 *cheap->ptr = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
554 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
555 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
556 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
557 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
558 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
559 in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
560 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
561 } else if (in_wquote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
562 if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
563 if (*chptr !='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
564 *cheap->ptr = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
565 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
566 } else {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
567 *cheap->ptr = '\n';
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
568 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
569 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
570 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
571 in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
572 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
573 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
574 in_wquote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
575 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
576 in_quote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
577 } if (plevel==0) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
578 if (c==',') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
579 cheap->ptr[-1] = 0;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
580 args = list2((int)cheap->ptr,args);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
581 body = (char **)&car(args);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
582 } else if (c==')') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
583 cheap->ptr[-1] = 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
584 break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
585 } else if (c=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
586 plevel++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
587 } else if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
588 if (*chptr=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
589 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
590 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
591 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
592 // } else if (c==' '||c=='\t') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
593 // cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
594 } else if (c=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
595 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
596 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
597 chptr = *pchptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
598 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
599 } else if (c==')') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
600 plevel--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
601 } else if (c=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
602 plevel++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
603 } else if (c=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
604 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
605 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
606 chptr = *pchptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
607 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
608 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
609 *pchptr = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
610 return reverse0(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
611 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
612
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
613 /* output macro expansion result into macrobuf (macropp) */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
614
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
615 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
616 macro_function(int macrop,char **pchptr,NMTBL *nptr,int history)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
617 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
618 int args,sargs,values,evalues;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
619 char *macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
620
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
621 sargs = args = cadr(nptr->dsp);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
622 values = macro_args(pchptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
623 if (pchptr==&chptr) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
624 ch = *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
625 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
626 evalues = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
627 while(values) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
628 evalues = list2(macro_eval(0,(char *)car(values),history),evalues);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
629 values = cadr(values);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
630 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
631 evalues = reverse0(evalues);
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
632 enter_scope();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
633 while(args) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
634 mappend(reverse0(car(evalues)),&macro);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
635 local_define((char *)car(args),macro);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
636 args = cadr(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
637 evalues = cadr(evalues);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
638 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
639 macro = (char *)car(nptr->dsp);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
640 macrop = macro_eval(macrop,macro,list2((int)macro,history));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
641 args = sargs;
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
642 leave_scope();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
643 return macrop;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
644 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
645
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
646 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
647 local_define(char *macro,char *value)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
648 {
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
649 NMTBL *nptr0,*nlist;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
650 while(*macro==' '||*macro=='\t') macro++;
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
651 nptr0 = name_space_search(nlist=get_name(macro,0,DEF),MACRO);
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
652 nptr0 = make_local_scope(nlist,nptr0,MACRO);
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
653 nptr0->nm = value;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
654 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
655
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
656 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
657 Evaluate macro string.
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
658 reuslt: list2("replaced string",next)
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
659 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
660
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
661 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
662 macro_eval(int macrop,char *body0,int history)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
663 {
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
664 int c,len;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
665 int in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
666 int in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
667 char *macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
668 char *body = body0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
669 char **expand;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
670 NMTBL *nptrm;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
671 macrop = list2((int)cheap->ptr,macrop);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
672 expand = (char **)&car(macrop);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
673 for(; (c = *body++) ;) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
674 if (in_quote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
675 if (c=='\\') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
676 *cheap->ptr = c; c = *body++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
677 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
678 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
679 in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
680 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
681 } else if (in_wquote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
682 if (c=='\\') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
683 *cheap->ptr = c; c = *body++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
684 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
685 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
686 in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
687 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
688 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
689 in_wquote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
690 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
691 in_quote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
692 } else if (c=='#' && *body=='#') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
693 // name concatenation. skip ## and re-eval macro line.
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
694 mconcat = 1; body++; continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
695 } else if (alpha(c)) {
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
696 body--; // ungetc
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
697 nptrm = get_name(body,&len,NONDEF);
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
698 if (!nptrm) {
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
699 while((*cheap->ptr = *body++) && len--)
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
700 cheap = increment_cheap(cheap,expand);
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
701 body--;
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
702 continue;
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
703 }
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
704 body += len;
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
705 c = *body;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
706 nptrm = name_space_search(nptrm,MACRO);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
707 macro = (char *)car(nptrm->dsp);
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
708 switch(nptrm->sc) {
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
709 case FMACRO:
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
710 if (c==' '||c=='\t') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
711 while (c==' '||c=='\t') c=*body++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
712 body--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
713 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
714 if(c!='(') error(MCERR);
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
715 *cheap->ptr = 0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
716 cheap = increment_cheap(cheap,expand);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
717 body++;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
718 macrop = macro_function(macrop,&body,nptrm,
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
719 list2((int)macro,history));
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
720 macrop = list2((int)cheap->ptr,macrop);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
721 expand = (char **)&(car(macrop));
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
722 break;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
723 case MACRO:
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
724 if (neqname(nptrm->nm,macro)) {
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
725 if (macro[0]==0) continue;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
726 *cheap->ptr = 0;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
727 cheap = increment_cheap(cheap,expand);
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
728 macrop=macro_eval(macrop,macro,list2((int)macro,history));
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
729 macrop = list2((int)cheap->ptr,macrop);
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
730 expand = (char **)&(car(macrop));
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
731 break;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
732 }
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
733 default:
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
734 macro = nptrm->nm;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
735 case LMACRO:
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
736 while((*cheap->ptr = *macro++)/* && len-- */)
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
737 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
738 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
739 continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
740 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
741 *cheap->ptr = c;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
742 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
743 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
744 *cheap->ptr = 0;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
745 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
746 return macrop;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
747 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
748
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
749 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
750 cancat list2("string",next) into cheap.
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
751 result overwrited by next cheap allocation
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
752 */
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
753
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
754 static char *
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
755 mappend(int lists,char **result)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
756 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
757 char *p;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
758 *result = cheap->ptr;
348
e77b3a7002ad name table reconfigure compiled. debug start.
kono
parents: 347
diff changeset
759 for(;lists;lists = cadr(lists)) {
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
760 p = (char *)car(lists);
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
761 for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
762 // in_quote + \n case ? should be \n.
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
763 if (p[-1]=='\n') cheap->ptr[0]=' ';
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
764 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
765 }
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
766 cheap = increment_cheap(cheap,0);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
767 return *result;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
768 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
769
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
770 /* end */