annotate mc-macro.c @ 705:0554b7f985ee parse-mode

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