annotate mc-macro.c @ 534:0f24e1dba811

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