annotate mc-macro.c @ 604:ff033b46cac5

*** empty log message ***
author kono
date Mon, 30 Jan 2006 13:42:12 +0900
parents df04bc5fd5fe
children e055df7c1082
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
1 /* Micro-C Preprocessor Part */ /* $Id$ */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
2
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
3 #include <stdio.h>
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
4 #include "mc.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
5 #include "mc-parse.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
6 #include "mc-macro.h"
456
b8f95294eb77 inline continue... if test passed.
kono
parents: 455
diff changeset
7 #include "mc-codegen.h"
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
8 #include "mc-code.h"
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
9
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
10 extern struct {int fd,ln;char *name0;int inc;FILE *fcb;} *filep,filestack[FILES];
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
11
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
12 int in_macro_if = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
13 char *chinput;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
14
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
15 static int mconcat=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
16
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
17 static void macro_define0();
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
18 static int macro_args(char **pchptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
19 static int macro_function(int macrop,char **pchptr,NMTBL *nptr,int history);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
20 static void local_define(char *macro,char *value);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
21 static int macro_eval(int macrop,char *body0,int history);
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
22 static char * mappend0(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
561
de0b0380c461 comments
kono
parents: 560
diff changeset
25 /*
de0b0380c461 comments
kono
parents: 560
diff changeset
26
de0b0380c461 comments
kono
parents: 560
diff changeset
27 macro_expansion(NMTBL *nptrm)
de0b0380c461 comments
kono
parents: 560
diff changeset
28 innput macro term (and chptr for arguments)
de0b0380c461 comments
kono
parents: 560
diff changeset
29 result put into cheap, and chptr is set.
de0b0380c461 comments
kono
parents: 560
diff changeset
30 current ch and chptr are pushed into chptr stack.
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
31
561
de0b0380c461 comments
kono
parents: 560
diff changeset
32 ## concatenation requires repeated replace.
de0b0380c461 comments
kono
parents: 560
diff changeset
33
de0b0380c461 comments
kono
parents: 560
diff changeset
34 In macro_function and macro_eavl,
de0b0380c461 comments
kono
parents: 560
diff changeset
35 expand result is put into macrop local variable.
de0b0380c461 comments
kono
parents: 560
diff changeset
36 list2("replaced string",next)
de0b0380c461 comments
kono
parents: 560
diff changeset
37 to generate result, mappend/reverse0 is necessary.
de0b0380c461 comments
kono
parents: 560
diff changeset
38
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
39 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
40
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
41 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
42 macro_expansion(NMTBL *nptrm)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
43 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
44 int i = mode;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
45 int macrop = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
46 int slfree = lfree;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
47 int c;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
48 char *macropp,*s,*t;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
49 struct cheap scheap;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
50 mode = STAT;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
51
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
52 save_cheap(&scheap,cheap);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
53
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
54 if (nptrm->sc == FMACRO) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
55 macrop=macro_function(macrop,&chptr,nptrm,0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
56 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
57 macrop=macro_eval(macrop,(char *)car(nptrm->dsp),0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
58 }
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;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
61 // append result override, working cheap, but it's OK.
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
62 mappend0(reverse0(macrop),&macropp);
564
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
63 // cheap->ptr[-1] ='\n'; // makes some tokenize happy
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
64 // ## macro_result needs \n at end
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
65 cheap->ptr[-1] = 0; // makes some tokenize happy
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
66 t = cheap->ptr-2;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
67 cheap->ptr[0] =0;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
68 cheap = increment_cheap(cheap,&macropp);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
69 while (mconcat) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
70 // ## re-eval macro
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
71 // if (lsrc) printf("## before %s",macropp);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
72 mconcat = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
73 macrop = 0;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
74 // remove \s**##\s*
561
de0b0380c461 comments
kono
parents: 560
diff changeset
75 // it is difficult to remove previous space on the fly,
de0b0380c461 comments
kono
parents: 560
diff changeset
76 // so multi path loop is required
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
77 for(s=t=macropp;*s;) {
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
78 if ((c=*s++)=='#'&&*s=='#') {
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
79 if (t>s-3) t=s-2; else t--;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
80 while(*t<=' '&&t>macropp) t--; t++;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
81 for(s++;*s && *s<=' ';) s++;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
82 continue;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
83 }
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
84 *t++=c;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
85 }
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
86 *t++=0;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
87 // evaluate generated result again
564
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
88 if (lsrc) {
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
89 printf("### %s\n",macropp);
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
90 if (t[-2]!='\n') putchar('\n');
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
91 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
92 macrop=macro_eval(macrop,macropp,0);
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
93 cheap = reset_cheap(&scheap);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
94 macropp = cheap->ptr;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
95 // will not override evaled list
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
96 mappend0(reverse0(macrop),&macropp);
564
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
97 // cheap->ptr[-1] ='\n';
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
98 cheap->ptr[-1] =0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
99 cheap->ptr[0] =0;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
100 cheap = increment_cheap(cheap,&macropp);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
101 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
102 cheap = reset_cheap(&scheap);
561
de0b0380c461 comments
kono
parents: 560
diff changeset
103 // genrated macro will be overwrited by cheap, but it's OK, again
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
104 mconcat = 0;
447
818505dd6e1f TYPEOF fix. Hash function opt. Array in decl_data.
kono
parents: 364
diff changeset
105 set_lfree(slfree);
564
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
106 if (lsrc && !asmf && nptrm->sc==FMACRO) {
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
107 gen_comment(macropp);
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
108 if (t[-2]!='\n') putchar('\n');
25f431685d80 *** empty log message ***
kono
parents: 561
diff changeset
109 }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
110 // push previous chptr, and change it to the generate macro
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
111 chptrsave = glist2((int)chptr,chptrsave);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
112 chsave = glist2(ch,chsave);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
113 chptr = macropp;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
114 ch = *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
115 mode = i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
116 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
117
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
118 /* file inclusion */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
119
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
120 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
121 file name concatenation
561
de0b0380c461 comments
kono
parents: 560
diff changeset
122 on cheap
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
123 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
124
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
125 static char *
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
126 expand_file_name(char *path,char *name)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
127 {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
128 char *p = cheap->ptr;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
129 if (! *path) return name;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
130 while(( *cheap->ptr = *path++ )) cheap = increment_cheap(cheap,&p);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
131 if (cheap->ptr[-1]!='/') {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
132 *cheap->ptr = '/'; cheap = increment_cheap(cheap,&p);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
133 }
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
134 while(( *cheap->ptr = *name++ )) cheap = increment_cheap(cheap,&p);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
135 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
136 cheap = increment_cheap(cheap,&p);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
137 return p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
138 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
139
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
140 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
141 get file name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
142 <name> => name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
143 current_file_name_dir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
144 libdir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
145 "name" => name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
146 current_file_name_dir / name
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
147 include_path / name
561
de0b0380c461 comments
kono
parents: 560
diff changeset
148 (no difference?)
de0b0380c461 comments
kono
parents: 560
diff changeset
149 next flag ignores the first occurence.
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
150 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
151
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
152 static int
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
153 nameeq(char *p, char *q)
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
154 {
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
155 if (!p)
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
156 return 0;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
157 while(*p)
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
158 if(*p++ != *q++) return 0;
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
159 return (*q==0);
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
160 }
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
161
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
162 static FILE *
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
163 getfname(int next)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
164 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
165 int i,end='"',err=0;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
166 char *s,*p,**pp,*name,*prev=0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
167 FILE *fp;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
168 struct cheap scheap;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
169 name = cheap->ptr;
327
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 if(skipspc()=='"') { end = '"';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
173 } else if (ch=='<') { end = '>';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
174 } else { error(INCERR); err=1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
175 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
176 for(i=0;(getch()!=end && ch!='\n');) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
177 *cheap->ptr = ch;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
178 cheap = increment_cheap(cheap,&name);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
179 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
180 if(ch=='\n') error(INCERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
181 if (err) return filep->fcb;
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
182 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
183 cheap = increment_cheap(cheap,&name);
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
184 save_cheap(&scheap,cheap);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
185 fp = fopen(name,"r") ;
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
186 if (next && fp) { fclose(fp); fp=0; next=0; prev=name; }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
187 if (fp) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
188 p = name;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
189 } else {
556
ef225b589888 s-dandy fix
kono
parents: 553
diff changeset
190 // no deferenced on "" and <>?
ef225b589888 s-dandy fix
kono
parents: 553
diff changeset
191 for(pp=include_path; *pp;pp++) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
192 p = expand_file_name(*pp,name);
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
193 if(prev && nameeq(p,prev)) continue;
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
194 if ((fp = fopen(p,"r"))) {
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
195 if (next) {
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
196 fclose(fp); fp=0; next=0; prev=p;
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
197 continue;
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
198 } else
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
199 break ;
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
200 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
201 }
556
ef225b589888 s-dandy fix
kono
parents: 553
diff changeset
202 if (!fp /* && (end=='>'||filep->inc=='>') */ ) { // <> case only
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
203 for(pp=l_include_path; *pp;pp++) {
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
204 p = expand_file_name(*pp,name);
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
205 if(prev && nameeq(p,prev)) continue;
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
206 if ((fp = fopen(p,"r"))) {
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
207 if (next) {
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
208 fclose(fp); fp=0; next=0; prev=p;
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
209 continue;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
210 } else
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
211 break ;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
212 }
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
213 }
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
214 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
215 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
216 if(!fp) { error(FILERR); return filep->fcb; }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
217 // we have so search current directory of the included file
de0b0380c461 comments
kono
parents: 560
diff changeset
218 // keep track the name
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
219 copy_current_file_dir(s=p);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
220 // File name determined. Dispose extra copies.
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
221 cheap = reset_cheap(&scheap);
561
de0b0380c461 comments
kono
parents: 560
diff changeset
222 // Generated name needs copy.
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
223 if (p!=name) {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
224 name = cheap->ptr;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
225 while((*cheap->ptr = *s++)) cheap = increment_cheap(cheap,&name);
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
226 *cheap->ptr = 0;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
227 cheap = increment_cheap(cheap,&name);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
228 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
229 (filep+1)->inc = end;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
230 (filep+1)->name0 = name;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
231 return ( (filep+1)->fcb = fp );
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
232 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
233
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
234 /* line input and conversion */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
235
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
236 static int macro_if_depth ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
237 static int macro_if_current ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
238 static int macro_if_skip ;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
239
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
240 /* there may extra non-terminate comment after #if/#else directive */
364
c29eebf3eaf4 local label and indirect goto.
kono
parents: 363
diff changeset
241 /* #endif / * hoge */
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
242 /* */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
243 /* */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
244
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
245 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
246 skip_rest_of_line()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
247 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
248 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
249 do {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
250 while(ch!='\n'&&ch!='\r') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
251 if (!in_comment) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
252 if (ch=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
253 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
254 if (ch=='/') in_comment=2;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
255 else if (ch=='*') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
256 in_comment=1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
257 } else continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
258 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
259 } else if (ch=='*') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
260 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
261 if (ch=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
262 in_comment=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
263 return macro_if_skip?0:1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
264 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
265 else continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
266 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
267 getch();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
268 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
269 if (in_comment==1) { getline(); getch(); }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
270 } while(in_comment==1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
271 in_comment=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
272 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
273 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
274
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
275 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
276 getline from chptr or chinput (for internal source)
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
277 with macro processing
561
de0b0380c461 comments
kono
parents: 560
diff changeset
278 generate comment
de0b0380c461 comments
kono
parents: 560
diff changeset
279 generate ST_COMMENT parse tree, in inline mode
de0b0380c461 comments
kono
parents: 560
diff changeset
280 In getch, if chptr is empty, pop chptr stack, if stack is empy
de0b0380c461 comments
kono
parents: 560
diff changeset
281 read from fp.
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
282 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
283
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
284 static int next_eof;
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
285 struct cheap *st_cheap, *cheap1;
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
286 // ST_COMMENT may interfere with other inrement_cheap, so we use
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
287 // another cheap area.
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
288
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
289 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
290 getline(void)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
291 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
292 int i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
293 int c;
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
294 char num[10];
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
295
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
296 if (next_eof) {
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
297 next_eof=0;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
298 error(EOFERR);
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
299 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
300 do {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
301 if (chinput) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
302 if (! *chinput) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
303 chinput=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
304 continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
305 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
306 chptr=linebuf;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
307 i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
308 while((*chptr++=c=*chinput++)&&(c!='\n')) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
309 if (++i > LBUFSIZE-2) error(LNERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
310 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
311 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
312 lineno++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
313 glineno++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
314 chptr=linebuf;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
315 i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
316 while ((*chptr++ = c = getc(filep->fcb)) != '\n') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
317 if (++i > LBUFSIZE-2) error(LNERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
318 if (c==EOF) {
343
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
319 next_eof=1;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
320 --chptr;
11f8f2e6bb72 fix eof and multi-file, mc-parse else-if switch
kono
parents: 327
diff changeset
321 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
322 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
323 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
324 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
325 *chptr = '\0';
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
326 if (lsrc && !asmf && !macro_if_skip && linebuf[0]) {
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
327 gen_comment(linebuf);
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
328 if (inmode) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
329 // inline mode
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
330 int i=0;
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
331 int c;
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
332 char *p;
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
333 // should be done in some init
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
334 if (!st_cheap) {
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
335 st_cheap = cheap1 = new_cheap();
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
336 }
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
337
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
338 p = st_cheap->ptr;
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
339 sprintf(num,"%d: ",lineno);
509
e58848f6ebc1 inline continue...
kono
parents: 469
diff changeset
340 parse = list3(ST_COMMENT,parse,(int)p);
e58848f6ebc1 inline continue...
kono
parents: 469
diff changeset
341 // should contain file name
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
342 c = 0;
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
343 while((*st_cheap->ptr = num[c++]))
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
344 st_cheap = increment_cheap(st_cheap,&p);
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
345 while((c = *st_cheap->ptr = linebuf[i++])) {
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
346 st_cheap = increment_cheap(st_cheap,&p);
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
347 if (c=='\n') {
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
348 *st_cheap->ptr = 0;
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
349 st_cheap = increment_cheap(st_cheap,&p);
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
350 p = st_cheap->ptr;
509
e58848f6ebc1 inline continue...
kono
parents: 469
diff changeset
351 // parse = list3(ST_COMMENT,parse,(int)p);
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
352 sprintf(num,"%d: ",lineno);
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
353 c = 0;
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
354 while((*cheap->ptr = num[c++]))
560
d6ff45d719a5 string sharing
kono
parents: 556
diff changeset
355 st_cheap = increment_cheap(st_cheap,&p);
455
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
356 }
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
357 }
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
358 }
563a5d29ec5e inline continue...
kono
parents: 447
diff changeset
359 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
360 if (*(chptr = linebuf) == '#' && !in_comment && !in_quote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
361 if (macro_processing()) return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
362 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
363 } while(!in_quote && (macro_if_skip || linebuf[0] == '#'));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
364 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
365
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
366 /* preprocessor directive */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
367
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
368 /* line continuation \\ */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
369
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
370 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
371 check_macro_eof()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
372 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
373 int c;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
374 // can't be in macro expansion
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
375 for(c=0;c<LBUFSIZE-3&&chptr[c];c++);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
376 if (c>0&&chptr[c-1]=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
377 return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
378 } else if (c>0&&chptr[c-1]=='\n') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
379 if (c>0&&chptr[c-2]=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
380 return;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
381 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
382 c--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
383 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
384 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
385 chptr[c] = ';';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
386 chptr[c+1] = '\n';
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
387 chptr[c+2] = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
388 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
389
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
390 /* #if hoge case */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
391
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
392 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
393 macro_if()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
394 {
599
df04bc5fd5fe *** empty log message ***
kono
parents: 591
diff changeset
395 int i,stype=type; // expr destroy type
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
396 ch= *chptr;
599
df04bc5fd5fe *** empty log message ***
kono
parents: 591
diff changeset
397 in_macro_if = 1; // makes undefined symbol==list2(CONST,0)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
398 check_macro_eof();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
399 getsym(0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
400 /* i=cexpr(expr(1)); #if allow undefined symbols.. */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
401 i=expr(1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
402 in_macro_if = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
403 if (car(i)==CONST) i=cadr(i);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
404 else i=0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
405 if (ch) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
406 if (chptr[-1]==ch) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
407 /* we are fall into getch(), which lost the last ch */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
408 /* chptr[-1]==ch check is fanatic, but ... */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
409 chptr--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
410 } else error(-1);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
411 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
412 macro_if_depth = macro_if_current;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
413 macro_if_skip = !i;
591
0497fa2e2414 *** empty log message ***
kono
parents: 569
diff changeset
414 type=stype;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
415 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
416
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
417 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
418 macro_processing()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
419 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
420 int i;
569
1fcad06b264a gcc4 (ia32)
kono
parents: 564
diff changeset
421 int c=0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
422 int mode_save;
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
423 int next;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
424
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
425 ++chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
426 while (*chptr==' '||*chptr=='\t') ++chptr;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
427 switch(chptr[0]*chptr[1]) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
428 case 'i'*'f':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
429 if ((macroeq("ifdef") || macroeq("ifndef"))) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
430 c = (chptr[-4]=='n');
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
431 macro_if_current++;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
432 if (!macro_if_skip) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
433 // try getsym in IFDEF mode to avoid symbol define
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
434 mode_save = mode; mode = IFDEF;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
435 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
436 i = getsym(0);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
437 mode = mode_save;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
438 macro_if_depth = macro_if_current;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
439 macro_if_skip = (!i)^c;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
440 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
441 return 0;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
442 } else if (macroeq("if")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
443 macro_if_current++;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
444 if (!macro_if_skip) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
445 macro_if();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
446 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
447 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
448 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
449 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
450 case 'e'*'l':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
451 if (macroeq("elif")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
452 if (macro_if_current==0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
453 error(MCERR); /* extra #else */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
454 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
455 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
456 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
457 if (!macro_if_skip || macro_if_skip==2) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
458 macro_if_skip=2;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
459 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
460 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
461 macro_if();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
462 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
463 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
464 } else if (macroeq("else")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
465 if (macro_if_current==0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
466 error(MCERR); /* extra #else */
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
467 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
468 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
469 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
470 if (macro_if_skip==2) ;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
471 else if (macro_if_skip) macro_if_skip=0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
472 else macro_if_skip=1;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
473 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
474 return skip_rest_of_line();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
475 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
476 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
477 case 'e'*'n':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
478 if (macroeq("endif")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
479 if (macro_if_current == macro_if_depth) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
480 macro_if_skip = 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
481 macro_if_depth = --macro_if_current;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
482 } else {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
483 if (macro_if_current<=0) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
484 error(MCERR); /* extra #if */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
485 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
486 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
487 macro_if_current--;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
488 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
489 return skip_rest_of_line();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
490 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
491 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
492 if (macro_if_skip) return 0;
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
493 switch(chptr[0]) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
494 case 'd':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
495 if (macroeq("define")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
496 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
497 macro_define0();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
498 *(chptr = linebuf) = '\0';
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
499 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
500 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
501 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
502 case 'u':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
503 if (macroeq("undef")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
504 i=mode;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
505 mode=IFDEF;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
506 ch= *chptr;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
507 if (getsym(0)) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
508 // make it EMPTY
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
509 if (nptr->sc == MACRO) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
510 nptr->sc = EMPTY;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
511 } else if (nptr->sc == FMACRO) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
512 nptr->sc = EMPTY;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
513 /* we cannot reclaim it's arg */
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
514 } else error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
515 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
516 mode=i;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
517 return 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
518 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
519 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
520 case 'i':
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
521 next = 1;
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
522 if (macroeq("include_next")|| (next=0, macroeq("include"))) {
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
523 if(filep+1 >= filestack + FILES) error(FILERR);
469
cf1c2c42b7c8 fix iassop
kono
parents: 456
diff changeset
524 if ( ((filep+1)->fcb=getfname(next)) == NULL) error(FILERR);
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
525 (filep+1)->ln=lineno;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
526 lineno=0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
527 ++filep;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
528 *(chptr = linebuf) = '\0';
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
529 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
530 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
531 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
532 #if ASM_CODE
561
de0b0380c461 comments
kono
parents: 560
diff changeset
533 // deprecated, use asm function
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
534 case 'a':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
535 if (c=='a'&&macroeq("asm")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
536 if (asmf) error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
537 asmf = 1;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
538 getline();
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
539 while (asmf) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
540 printf("%s",linebuf);
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
541 getline();
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
542 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
543 return 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
544 }
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
545 break;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
546 case 'e':
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
547 if (macroeq("endasm")) {
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
548 if (!asmf) error(MCERR);
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
549 asmf = 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
550 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
551 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
552 break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
553 #endif
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
554 case ' ': case '\t':
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
555 getline();
361
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
556 return 0;
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
557 }
93652cda75c7 minor speed up (macro/switch)
kono
parents: 359
diff changeset
558 error(MCERR);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
559 return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
560 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
561
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
562 extern int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
563 macroeq(char *s)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
564 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
565 char *p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
566
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
567 for (p = chptr; *s;) if (*s++ != *p++) return 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
568 chptr = p;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
569 return 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
570 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
571
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
572 /* macro interpreter */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
573
561
de0b0380c461 comments
kono
parents: 560
diff changeset
574 /* generate macro define */
de0b0380c461 comments
kono
parents: 560
diff changeset
575
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
576 extern void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
577 macro_define(char *macro)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
578 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
579 char *chptr_save;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
580 int chsave;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
581
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
582 chptr_save = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
583 chsave = ch;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
584 chptr = macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
585 ch= *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
586 macro_define0();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
587 chptr = chptr_save;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
588 ch = chsave;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
589 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
590
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
591 /* macro define from chptr */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
592
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
593 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
594 macro_define0()
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
595 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
596 int i,args,c;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
597 char **body;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
598
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
599 i=mode;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
600 mode=MDECL;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
601 // ch= *chptr; ??
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
602 // fprintf(stderr,"macro def: ch %c *chptr %c\n",ch,*chptr);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
603 getsym(0);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
604 // fprintf(stderr,"macro def: %s =>",name);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
605 if (nptr->sc != EMPTY) { /* override existing macro */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
606 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
607 args = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
608 if (ch=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
609 nptr->sc = FMACRO;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
610 args = macro_args(&chptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
611 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
612 nptr->sc = MACRO;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
613 nptr->ty = -1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
614 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
615 // equal is allowed for -Dhoge=aho option
534
0f24e1dba811 *** empty log message ***
kono
parents: 527
diff changeset
616 // if (ch=='=') chptr++;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
617 while((c=*chptr)==' '||c=='\t') chptr++;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
618 nptr->dsp = list2((int)cheap->ptr,args); /* macro body */
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
619 body = (char **)&car(nptr->dsp);
561
de0b0380c461 comments
kono
parents: 560
diff changeset
620
de0b0380c461 comments
kono
parents: 560
diff changeset
621 // now copy it to the body
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
622 while ((*cheap->ptr = c = *chptr++)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
623 && c != '\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
624 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
625 if (c=='/'&&chptr[0]=='/') {
351
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
626 cheap->ptr--;
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
627 *cheap->ptr = '\0';
000c509b663d name table reconfigure continue...
kono
parents: 350
diff changeset
628 while(*chptr++); break;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
629 } else if (c=='/'&&chptr[0]=='*') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
630 cheap->ptr--; chptr++;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
631 while((c = *chptr++)) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
632 if (c=='*'&&chptr[0]=='/') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
633 c = *chptr++; break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
634 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
635 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
636 if (!c) break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
637 } else if (c=='\\' && (*chptr=='\n'||*chptr==0)) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
638 chptr++;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
639 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
640 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
641 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
642 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
643 if (c=='\n') {
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
644 *cheap->ptr = '\0';
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
645 }
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
646 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
647 // fprintf(stderr,"%s\n",(char *)car(nptr->dsp));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
648 mode=i;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
649 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
650
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
651 // create function macro argument list
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
652 // return list2((char*)arg,next)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
653
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
654 static int
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
655 macro_args(char **pchptr)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
656 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
657 int c;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
658 int in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
659 int in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
660 int plevel = 0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
661 char **body;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
662 char *chptr = *pchptr;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
663 int args = list2((int)cheap->ptr,0);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
664 body = (char **)&car(args);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
665 for(;;) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
666 *cheap->ptr = c = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
667 cheap = increment_cheap(cheap,body);
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
668 if (c=='\\') {
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
669 if (*chptr=='\n') {
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
670 cheap->ptr--;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
671 getline();
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
672 chptr = *pchptr;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
673 continue;
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
674 }
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
675 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
676 if (!c) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
677 chptr--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
678 error(MCERR);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
679 *pchptr = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
680 return reverse0(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
681 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
682 if (in_quote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
683 if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
684 if (*chptr != '\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
685 *cheap->ptr = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
686 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
687 } else {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
688 getline();
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
689 chptr = *pchptr;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
690 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
691 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
692 in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
693 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
694 } else if (in_wquote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
695 if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
696 if (*chptr !='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
697 *cheap->ptr = *chptr++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
698 cheap = increment_cheap(cheap,body);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
699 } else {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
700 *cheap->ptr = '\n';
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
701 getline();
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
702 chptr = *pchptr;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
703 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
704 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
705 in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
706 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
707 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
708 in_wquote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
709 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
710 in_quote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
711 } if (plevel==0) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
712 if (c==',') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
713 cheap->ptr[-1] = 0;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
714 args = list2((int)cheap->ptr,args);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
715 body = (char **)&car(args);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
716 } else if (c==')') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
717 cheap->ptr[-1] = 0;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
718 break;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
719 } else if (c=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
720 plevel++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
721 } else if (c=='\\') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
722 if (*chptr=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
723 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
724 getline();
539
00da98433e63 macro arg continuation
kono
parents: 534
diff changeset
725 chptr = *pchptr;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
726 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
727 // } else if (c==' '||c=='\t') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
728 // cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
729 } else if (c=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
730 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
731 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
732 chptr = *pchptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
733 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
734 } else if (c==')') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
735 plevel--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
736 } else if (c=='(') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
737 plevel++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
738 } else if (c=='\n') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
739 cheap->ptr--;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
740 getline();
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
741 chptr = *pchptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
742 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
743 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
744 *pchptr = chptr;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
745 return reverse0(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
746 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
747
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
748 /* output macro expansion result into macrobuf (macropp) */
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
749
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
750 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
751 macro_function(int macrop,char **pchptr,NMTBL *nptr,int history)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
752 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
753 int args,sargs,values,evalues;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
754 char *macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
755
561
de0b0380c461 comments
kono
parents: 560
diff changeset
756 // make argument list
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
757 sargs = args = cadr(nptr->dsp);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
758 values = macro_args(pchptr);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
759 if (pchptr==&chptr) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
760 ch = *chptr++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
761 }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
762 // eval all argument list
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
763 evalues = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
764 while(values) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
765 evalues = list2(macro_eval(0,(char *)car(values),history),evalues);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
766 values = cadr(values);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
767 }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
768 // define all arguments locally
de0b0380c461 comments
kono
parents: 560
diff changeset
769 // #define arg0 arg0_value
de0b0380c461 comments
kono
parents: 560
diff changeset
770 // #define arg1 arg2_value ....
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
771 evalues = reverse0(evalues);
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
772 enter_scope();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
773 while(args) {
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
774 mappend0(reverse0(car(evalues)),&macro);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
775 local_define((char *)car(args),macro);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
776 args = cadr(args);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
777 evalues = cadr(evalues);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
778 }
561
de0b0380c461 comments
kono
parents: 560
diff changeset
779 // process body replacement
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
780 macro = (char *)car(nptr->dsp);
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
781 macrop = macro_eval(macrop,macro,list2((int)macro,history));
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
782 args = sargs;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
783 // unbind arguments
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
784 leave_scope();
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
785 return macrop;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
786 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
787
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
788 static void
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
789 local_define(char *macro,char *value)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
790 {
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
791 NMTBL *nptr0,*nlist;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
792 while(*macro==' '||*macro=='\t') macro++;
359
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
793 nptr0 = name_space_search(nlist=get_name(macro,0,DEF),MACRO);
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
794 nptr0 = make_local_scope(nlist,nptr0,MACRO);
7ab4434ad869 macro scope
kono
parents: 351
diff changeset
795 nptr0->nm = value;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
796 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
797
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
798 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
799 Evaluate macro string.
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
800 reuslt: list2("replaced string",next)
561
de0b0380c461 comments
kono
parents: 560
diff changeset
801 history is necessary to avoid recursion
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
802 */
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
803
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
804 static int
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
805 macro_eval(int macrop,char *body0,int history)
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
806 {
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
807 int c,len;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
808 int in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
809 int in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
810 char *macro;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
811 char *body = body0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
812 char **expand;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
813 NMTBL *nptrm;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
814 macrop = list2((int)cheap->ptr,macrop);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
815 expand = (char **)&car(macrop);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
816 for(; (c = *body++) ;) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
817 if (in_quote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
818 if (c=='\\') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
819 *cheap->ptr = c; c = *body++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
820 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
821 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
822 in_quote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
823 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
824 } else if (in_wquote) {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
825 if (c=='\\') {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
826 *cheap->ptr = c; c = *body++;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
827 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
828 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
829 in_wquote = 0;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
830 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
831 } else if (c=='"') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
832 in_wquote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
833 } else if (c=='\'') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
834 in_quote = 1;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
835 } else if (c=='#' && *body=='#') {
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
836 mconcat = 1;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
837 // name concatenation. flag only. remove and re-evaluate
540
fe37f32b552b include_next, macro_function eat 1 char.
kono
parents: 539
diff changeset
838 // in the top level. (and skip space)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
839 } else if (alpha(c)) {
561
de0b0380c461 comments
kono
parents: 560
diff changeset
840 // find a name
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
841 body--; // ungetc
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
842 nptrm = get_name(body,&len,NONDEF);
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
843 if (!nptrm) {
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
844 while((*cheap->ptr = *body++) && len--)
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
845 cheap = increment_cheap(cheap,expand);
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
846 body--;
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
847 continue;
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
848 }
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
849 body += len;
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
850 c = *body;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
851 nptrm = name_space_search(nptrm,MACRO);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
852 macro = (char *)car(nptrm->dsp);
561
de0b0380c461 comments
kono
parents: 560
diff changeset
853 // if (check_recurse(macro,history)) goto skip;
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
854 switch(nptrm->sc) {
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
855 case FMACRO:
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
856 if (c==' '||c=='\t') {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
857 while (c==' '||c=='\t') c=*body++;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
858 body--;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
859 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
860 if(c!='(') error(MCERR);
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
861 *cheap->ptr = 0;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
862 cheap = increment_cheap(cheap,expand);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
863 body++;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
864 macrop = macro_function(macrop,&body,nptrm,
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
865 list2((int)macro,history));
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
866 macrop = list2((int)cheap->ptr,macrop);
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
867 expand = (char **)&(car(macrop));
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
868 break;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
869 case MACRO:
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
870 if (neqname(nptrm->nm,macro)) {
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
871 if (macro[0]==0) continue;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
872 *cheap->ptr = 0;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
873 cheap = increment_cheap(cheap,expand);
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
874 macrop=macro_eval(macrop,macro,list2((int)macro,history));
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
875 macrop = list2((int)cheap->ptr,macrop);
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
876 expand = (char **)&(car(macrop));
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
877 break;
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
878 }
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
879 default:
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
880 macro = nptrm->nm;
561
de0b0380c461 comments
kono
parents: 560
diff changeset
881 // skip:
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
882 case LMACRO:
349
b74b580c10f6 name table debug continue...
kono
parents: 348
diff changeset
883 while((*cheap->ptr = *macro++)/* && len-- */)
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
884 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
885 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
886 continue;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
887 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
888 *cheap->ptr = c;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
889 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
890 }
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
891 *cheap->ptr = 0;
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
892 cheap = increment_cheap(cheap,expand);
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
893 return macrop;
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
894 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
895
363
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
896 /*
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
897 cancat list2("string",next) into cheap.
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
898 result overwrited by next cheap allocation
f3f2b7906d50 label extension
kono
parents: 361
diff changeset
899 */
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
900
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
901 static char *
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
902 mappend0(int lists,char **result)
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
903 {
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
904 char *p;
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
905 *result = cheap->ptr;
348
e77b3a7002ad name table reconfigure compiled. debug start.
kono
parents: 347
diff changeset
906 for(;lists;lists = cadr(lists)) {
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
907 p = (char *)car(lists);
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
908 for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) {
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
909 // in_quote + \n case ? should be \n.
350
43099915f4c2 name table reconfigure continue...
kono
parents: 349
diff changeset
910 if (p[-1]=='\n') cheap->ptr[0]=' ';
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
911 }
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
912 }
347
cef4d8eb9a26 name table reconfigure continue...
kono
parents: 346
diff changeset
913 cheap = increment_cheap(cheap,0);
346
969089695850 name reconfigure.... continue...
kono
parents: 343
diff changeset
914 return *result;
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
915 }
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
916
553
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
917 // do not replace \n
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
918 extern char *
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
919 mappend(int lists,char **result)
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
920 {
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
921 char *p;
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
922 *result = cheap->ptr;
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
923 for(;lists;lists = cadr(lists)) {
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
924 p = (char *)car(lists);
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
925 for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) {
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
926 // in_quote + \n case ? should be \n.
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
927 // if (p[-1]=='\n') cheap->ptr[0]=' ';
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
928 }
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
929 }
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
930 cheap = increment_cheap(cheap,0);
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
931 return *result;
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
932 }
293f827ccfb2 Linux kernel source compiled.
kono
parents: 540
diff changeset
933
327
da2e3f2d127d macro/codegen reorganization
kono
parents:
diff changeset
934 /* end */