annotate mc-macro.c @ 715:83e18db76c96

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