annotate mc-macro.c @ 607:e055df7c1082

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