Mercurial > repos > rhope
comparison backendutils.rhope @ 184:c6ba9fe45910
Strip _c from filenames of current compiler
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 27 Jul 2011 21:28:43 -0700 |
parents | backendutils_c.rhope@ed322ae64738 |
children |
comparison
equal
deleted
inserted
replaced
183:24c6f8767190 | 184:c6ba9fe45910 |
---|---|
1 | |
2 Escape Rhope Name[name,p:out] | |
3 { | |
4 escaped <- [name]Replace[p, | |
5 ("UN_","AT_","SP_","CN_","QN_","PL_","MN_","TM_","DV_","LT_","GT_","LP_","RP_","NT_","EQ_","PR_", | |
6 "DP_","TB_","CM_","PD_","NL_","LC_","RC_", "LS_", "RS_", "HS_", "BS_", "CR_", "SC_", "AM_", "PI_", "PC_", "CT_", "BT_", "TD_")] | |
7 | |
8 [("char","int","short","long","float","double","void","struct")]Find[=[escaped, ?]] | |
9 { | |
10 out <- ["ID_"]Append[escaped] | |
11 }{ | |
12 out <- Val[escaped] | |
13 } | |
14 } | |
15 | |
16 Blueprint Make Op Res | |
17 { | |
18 Func | |
19 Val | |
20 } | |
21 | |
22 Make Op Res[func,val:out] | |
23 { | |
24 out <- [[Build[Make Op Res()]]Func <<[func]]Val <<[val] | |
25 } | |
26 | |
27 Make Op Mod[func,val:out func,out val] | |
28 { | |
29 nval <- [val]Make Op[func] | |
30 If[[Blueprint Of[nval]]=[Make Op Res()]] | |
31 { | |
32 out func <- Func >>[nval] | |
33 out val <- Val >>[nval] | |
34 }{ | |
35 out func <- func | |
36 out val <- Val[nval] | |
37 } | |
38 } | |
39 | |
40 Blueprint AddRef | |
41 { | |
42 Value | |
43 } | |
44 | |
45 AddRef[value:out] | |
46 { | |
47 out <- [Build[AddRef()]]Value <<[value] | |
48 } | |
49 | |
50 Make Op@AddRef[addref,func:out] | |
51 { | |
52 out <- [func]Make AddRef Op[[addref]Value >>] | |
53 } | |
54 | |
55 Strip Addref@AddRef[op:out] | |
56 { | |
57 out <- [[op]Value >>]Strip Addref | |
58 } | |
59 | |
60 =@AddRef[a,b(AddRef):out] | |
61 { | |
62 out <- [[a]Value >>]==[[b]Value >>] | |
63 } | |
64 | |
65 Make Op@String[string,func:out] | |
66 { | |
67 out <- [func]Resolve[string] | |
68 } | |
69 | |
70 Strip Addref@String[op:out] | |
71 { | |
72 out <- op | |
73 } | |
74 | |
75 Get Type@String[op,func:out] | |
76 { | |
77 out <- [func]Get Var Type[op] | |
78 } | |
79 | |
80 Make Op@String Cat[string,func:out] | |
81 { | |
82 out <- [func]Resolve[string] | |
83 } | |
84 | |
85 Strip Addref@String Cat[op:out] | |
86 { | |
87 out <- op | |
88 } | |
89 | |
90 Get Type@String Cat[op,func:out] | |
91 { | |
92 out <- [func]Get Var Type[op] | |
93 } | |
94 | |
95 Make Op@String Slice[string,func:out] | |
96 { | |
97 out <- [func]Resolve[string] | |
98 } | |
99 | |
100 Strip Addref@String Slice[op:out] | |
101 { | |
102 out <- op | |
103 } | |
104 | |
105 Get Type@String Slice[op,func:out] | |
106 { | |
107 out <- [func]Get Var Type[op] | |
108 } | |
109 | |
110 Blueprint Output | |
111 { | |
112 Name | |
113 } | |
114 | |
115 Output[name:out] | |
116 { | |
117 out <- [Build[Output()]]Name <<[name] | |
118 } | |
119 | |
120 Make Op@Output[op,func:out] | |
121 { | |
122 out <- [func]Resolve Output[[op]Name >>] | |
123 } | |
124 | |
125 Strip Addref@Output[op:out] | |
126 { | |
127 out <- op | |
128 } | |
129 | |
130 =@Output[a,b(Output):out] | |
131 { | |
132 out <- [[a]Name >>]=[[b]Name >>] | |
133 } | |
134 | |
135 | |
136 Blueprint Constant | |
137 { | |
138 Value | |
139 Need Addref | |
140 } | |
141 | |
142 Constant[var:out] | |
143 { | |
144 out <- [[Build[Constant()]]Value <<[var]]Need Addref <<[Yes] | |
145 } | |
146 | |
147 Make Op@Constant[const,func:out] | |
148 { | |
149 out <- [func]Lookup Constant[[const]Value >>, [const]Need Addref >>] | |
150 } | |
151 | |
152 Get Type@Constant[const,func:out] | |
153 { | |
154 out <- [func]Get Constant Type[const] | |
155 } | |
156 | |
157 Strip Addref@Constant[op:out] | |
158 { | |
159 out <- [op]Need Addref <<[No] | |
160 } | |
161 | |
162 =@Constant[a,b(Constant):out] | |
163 { | |
164 out <- [[a]Value >>]=[[b]Value >>] | |
165 } | |
166 | |
167 Blueprint Result | |
168 { | |
169 Output Num | |
170 } | |
171 | |
172 Result[num:out] | |
173 { | |
174 out <- [Build[Result()]]Output Num <<[num] | |
175 } | |
176 | |
177 Make Op@Result[result,func:out] | |
178 { | |
179 out <- [func]Result Reference[[result]Output Num>>] | |
180 } | |
181 | |
182 Strip Addref@Result[op:out] | |
183 { | |
184 out <- op | |
185 } | |
186 | |
187 =@Result[a,b(Result):out] | |
188 { | |
189 out <- [[a]Output Num >>]=[[b]Output Num >>] | |
190 } | |
191 | |
192 Blueprint Global Get | |
193 { | |
194 Store | |
195 Var | |
196 } | |
197 | |
198 Global Get[store,var:out] | |
199 { | |
200 out <- [[Build[Global Get()]]Store <<[store]]Var <<[var] | |
201 } | |
202 | |
203 Make Op@Global Get[get,func:out] | |
204 { | |
205 out <- [func]Global Reference[[get]Store >>, [get]Var >>] | |
206 } | |
207 | |
208 Strip Addref@Global Get[get:out] | |
209 { | |
210 out <- get | |
211 } | |
212 | |
213 =@Global Get[a,b(Global Get):out] | |
214 { | |
215 ,out <- If[[[a]Store >>]=[[b]Store >>]] | |
216 { | |
217 out <- [[a]Var >>]=[[b]Var >>] | |
218 } | |
219 } | |
220 | |
221 Blueprint Check Result | |
222 { | |
223 Output Num | |
224 } | |
225 | |
226 Check Result[num:out] | |
227 { | |
228 out <- [Build[Check Result()]]Output Num <<[num] | |
229 } | |
230 | |
231 Make Op@Check Result[result,func:out] | |
232 { | |
233 out <- [func]Checked Result Reference[[result]Output Num>>] | |
234 } | |
235 | |
236 Strip Addref@Check Result[op:out] | |
237 { | |
238 out <- op | |
239 } | |
240 | |
241 Make Condition[op:out] | |
242 { | |
243 If[[Blueprint Of[op]]=[OrValue()]] | |
244 { | |
245 out <- OrCond[Make Condition[[op]Left >>], Make Condition[[op]Right >>]] | |
246 }{ | |
247 out <- op | |
248 } | |
249 } | |
250 | |
251 =@Check Result[a,b(Check Result):out] | |
252 { | |
253 out <- [[a]Output Num >>]=[[b]Output Num >>] | |
254 } | |
255 | |
256 Blueprint OrValue | |
257 { | |
258 Left | |
259 Right | |
260 } | |
261 | |
262 OrValue[left,right:out] | |
263 { | |
264 If[[left]==[right]] | |
265 { | |
266 out <- left | |
267 }{ | |
268 out <- [[Build[OrValue()]]Left <<[left]]Right <<[right] | |
269 } | |
270 } | |
271 | |
272 Make Op@OrValue[orval,func:out] | |
273 { | |
274 out <- [func]If Null Else[[orval]Left >>, [orval]Right >>] | |
275 } | |
276 | |
277 Strip Addref@OrValue[op:out] | |
278 { | |
279 out <- [[op]Left <<[ [[op]Left >>]Strip Addref ]]Right <<[ [[op]Right >>]Strip Addref ] | |
280 } | |
281 | |
282 =@OrValue[a,b(OrValue):out] | |
283 { | |
284 ,out <- If[[[a]Left >>]==[[b]Left >>]] | |
285 { | |
286 out <- [[a]Right >>]==[[b]Right >>] | |
287 } | |
288 } | |
289 | |
290 Blueprint Cast | |
291 { | |
292 Value | |
293 Type | |
294 } | |
295 | |
296 Cast[val,type:out] | |
297 { | |
298 out <- [[Build[Cast()]]Value <<[val]]Type <<[type] | |
299 } | |
300 | |
301 Make Op@Cast[cast,func:out] | |
302 { | |
303 out <- [func]Cast Value[[cast]Value >>, [cast]Type >>] | |
304 } | |
305 | |
306 Strip Addref@Cast[op:out] | |
307 { | |
308 out <- [op]Value <<[[[op]Value >>]Strip Addref] | |
309 } | |
310 | |
311 =@Cast[a,b(Cast):out] | |
312 { | |
313 ,out <- If[[[a]Value >>] == [[b]Value >>]] | |
314 { | |
315 out <- [[a]Type >>]=[[b]Type >>] | |
316 } | |
317 } | |
318 | |
319 Blueprint NotCond | |
320 { | |
321 Condition | |
322 } | |
323 | |
324 NotCond[cond:out] | |
325 { | |
326 If[[Blueprint Of[cond]]=[NotCond()]] | |
327 { | |
328 out <- [cond]Condition >> | |
329 }{ | |
330 out <- [Build[NotCond()]]Condition <<[[cond]Strip Addref] | |
331 } | |
332 } | |
333 | |
334 Make Op@NotCond[cond,func:out] | |
335 { | |
336 out <- ["!"]Append[[[cond]Condition >>]Make Op[func]] | |
337 } | |
338 | |
339 Strip Addref@NotCond[op:out] | |
340 { | |
341 out <- op | |
342 } | |
343 | |
344 =@NotCond[a,b(NotCond):out] | |
345 { | |
346 out <- [[a]Condition >>]==[[b]Condition >>] | |
347 } | |
348 | |
349 Blueprint OrCond | |
350 { | |
351 Condition1 | |
352 Condition2 | |
353 } | |
354 | |
355 OrCond[cond1,cond2:out] | |
356 { | |
357 If[[cond1]==[cond2]] | |
358 { | |
359 out <- cond1 | |
360 }{ | |
361 out <- [[Build[OrCond()]]Condition1 <<[[cond1]Strip Addref]]Condition2 <<[[cond2]Strip Addref] | |
362 } | |
363 } | |
364 | |
365 Make Op@OrCond[cond,func:out] | |
366 { | |
367 out <- ["("]Append[[[ [[cond]Condition1 >>]Make Op[func] ]Append[" || "]]Append[[ [[cond]Condition2 >>]Make Op[func] ]Append[")"]]] | |
368 } | |
369 | |
370 Strip Addref@OrCond[op:out] | |
371 { | |
372 out <- op | |
373 } | |
374 | |
375 =@OrCond[a,b(OrCond):out] | |
376 { | |
377 ,out <- If[[[a]Condition1 >>] == [[b]Condition1 >>]] | |
378 { | |
379 out <- [[a]Condition2 >>] == [[b]Condition2 >>] | |
380 } | |
381 } | |
382 | |
383 Blueprint AndCond | |
384 { | |
385 Condition1 | |
386 Condition2 | |
387 } | |
388 | |
389 AndCond[cond1,cond2:out] | |
390 { | |
391 If[[cond1]==[cond2]] | |
392 { | |
393 out <- cond1 | |
394 }{ | |
395 out <- [[Build[AndCond()]]Condition1 <<[[cond1]Strip Addref]]Condition2 <<[[cond2]Strip Addref] | |
396 } | |
397 } | |
398 | |
399 Make Op@AndCond[cond,func:out] | |
400 { | |
401 out <- ["("]Append[[[ [[cond]Condition1 >>]Make Op[func] ]Append[" && "]]Append[[ [[cond]Condition2 >>]Make Op[func] ]Append[")"]]] | |
402 } | |
403 | |
404 Strip Addref@AndCond[op:out] | |
405 { | |
406 out <- op | |
407 } | |
408 | |
409 =@AndCond[a,b(AndCond):out] | |
410 { | |
411 ,out <- If[[[a]Condition1 >>] == [[b]Condition1 >>]] | |
412 { | |
413 out <- [[a]Condition2 >>] == [[b]Condition2 >>] | |
414 } | |
415 } | |
416 | |
417 Blueprint Field Ref | |
418 { | |
419 Variable | |
420 Field | |
421 } | |
422 | |
423 Field Ref[var,field:out] | |
424 { | |
425 out <- [[Build[Field Ref()]]Variable <<[var]]Field <<[field] | |
426 } | |
427 | |
428 Get Type@Field Ref[ref,func:out] | |
429 { | |
430 out <- [func]Get Field Type[[[ref]Variable >>]Get Type[func], [ref]Field >>] | |
431 } | |
432 | |
433 Make Op@Field Ref[ref,func:out] | |
434 { | |
435 out <- [func]Field Result[[ref]Variable >>,[ref]Field >>] | |
436 } | |
437 | |
438 Strip Addref@Field Ref[op:out] | |
439 { | |
440 out <- op | |
441 } | |
442 | |
443 =@Field Ref[a,b(Field Ref):out] | |
444 { | |
445 ,out <- If[[[a]Variable >>]==[[b]Variable >>]] | |
446 { | |
447 out <- [[a]Field >>]=[[b]Field >>] | |
448 } | |
449 } | |
450 | |
451 Blueprint Type Instance | |
452 { | |
453 Name | |
454 Params | |
455 Variant | |
456 Mutable? | |
457 } | |
458 | |
459 Type Instance[raw name:out] | |
460 { | |
461 If[[raw name]=[""]] | |
462 { | |
463 name <- "Any Type" | |
464 }{ | |
465 name <- raw name | |
466 } | |
467 out <- [[[[Build[Type Instance()]]Name <<[name]]Params <<[()]]Variant <<["Boxed"]]Mutable? <<[No] | |
468 } | |
469 | |
470 Set Variant@Type Instance[type,variant:out,invalid] | |
471 { | |
472 [("Boxed","Naked","Pointer","Raw Pointer")]Find[=[variant,?]] | |
473 { | |
474 out <- [type]Variant <<[variant] | |
475 }{ | |
476 invalid <- type | |
477 } | |
478 } | |
479 | |
480 =@Type Instance[type,compare:out] | |
481 { | |
482 If[[Blueprint Of[compare]] = [Type Instance()]] | |
483 { | |
484 //TODO: Compare parameters | |
485 ,out <- If[[[type]Name >>] = [[compare]Name >>]] | |
486 { out <- [[type]Variant >>] = [[compare]Variant >>] } | |
487 }{ | |
488 out <- [[type]Name >>] = [compare] | |
489 } | |
490 } | |
491 | |
492 String@Type Instance[type:out] | |
493 { | |
494 typestr <- [[[[type]Name >> | |
495 ]Append["("] | |
496 ]Append[ [[type]Params >>]Join[", "] ] | |
497 ]Append[")"] | |
498 If[[type]Mutable? >>] | |
499 { | |
500 out <- [[ [["("]Append[typestr]]Append[", "] ]Append[[type]Variant >>]]Append[", Mutable)"] | |
501 }{ | |
502 If[[[type]Variant >>] = ["Boxed"]] | |
503 { | |
504 out <- Val[typestr] | |
505 }{ | |
506 out <- [[ [["("]Append[typestr]]Append[", "] ]Append[[type]Variant >>]]Append[", Mutable)"] | |
507 } | |
508 } | |
509 } | |
510 | |
511 Blueprint Worker Literal | |
512 { | |
513 Name | |
514 Args | |
515 } | |
516 | |
517 Worker Literal[name:out] | |
518 { | |
519 out <- [[Build[Worker Literal()]]Name <<[name]]Args <<[()] | |
520 } | |
521 | |
522 Set Input@Worker Literal[worker,argnum,val:out] | |
523 { | |
524 out <- [worker]Args <<[ [[worker]Args >>]Set[argnum, val] ] | |
525 } | |
526 |