annotate mc-macro.c @ 347:cef4d8eb9a26

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