annotate mc-macro.c @ 361:93652cda75c7

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