/
driver.pir
565 lines (530 loc) · 12.7 KB
/
driver.pir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# THIS IS A GENERATED FILE! DO NOT EDIT!
# Compiled with Winxed 1.8.1
# Source file: winxed_installed.winxed
# Begin generated code
.sub initial_load_bytecode :anon :load :init
load_bytecode 'Getopt/Obj.pbc'
.end
# end libs
.namespace [ 'WinxedDriverOptions' ]
.sub 'WinxedDriverOptions' :method
.param pmc __ARG_1
root_new $P1, ['parrot';'ResizablePMCArray']
assign $P1, 12
root_new $P3, ['parrot';'ResizablePMCArray']
assign $P3, 2
$P3[0] = 'c'
$P3[1] = 'Compile to pir'
$P1[0] = $P3
root_new $P4, ['parrot';'ResizablePMCArray']
assign $P4, 2
$P4[0] = 'e=s'
$P4[1] = 'Evaluate'
$P1[1] = $P4
root_new $P5, ['parrot';'ResizablePMCArray']
assign $P5, 2
$P5[0] = 'o=s'
$P5[1] = 'Object name'
$P1[2] = $P5
root_new $P6, ['parrot';'ResizablePMCArray']
assign $P6, 2
$P6[0] = 'target=s'
$P6[1] = 'Set target type'
$P1[3] = $P6
root_new $P7, ['parrot';'ResizablePMCArray']
assign $P7, 2
$P7[0] = 'L=s'
$P7[1] = 'Add to parrot library search path'
$P1[4] = $P7
root_new $P8, ['parrot';'ResizablePMCArray']
assign $P8, 2
$P8[0] = 'I=s'
$P8[1] = 'Add to parrot include search path'
$P1[5] = $P8
root_new $P9, ['parrot';'ResizablePMCArray']
assign $P9, 2
$P9[0] = 'X=s'
$P9[1] = 'Add to parrot dynext search path'
$P1[6] = $P9
root_new $P10, ['parrot';'ResizablePMCArray']
assign $P10, 2
$P10[0] = 'debug'
$P10[1] = 'Set debug mode'
$P1[7] = $P10
root_new $P11, ['parrot';'ResizablePMCArray']
assign $P11, 2
$P11[0] = 'nowarn'
$P11[1] = 'No warnings'
$P1[8] = $P11
root_new $P12, ['parrot';'ResizablePMCArray']
assign $P12, 2
$P12[0] = 'noan'
$P12[1] = 'No code annotations'
$P1[9] = $P12
root_new $P13, ['parrot';'ResizablePMCArray']
assign $P13, 2
$P13[0] = 'help'
$P13[1] = 'Show this help'
$P1[10] = $P13
root_new $P14, ['parrot';'ResizablePMCArray']
assign $P14, 2
$P14[0] = 'version'
$P14[1] = 'Show version and exit'
$P1[11] = $P14
setattribute self, 'options', $P1
if_null $P1, __label_2
iter $P15, $P1
set $P15, 0
__label_1: # for iteration
unless $P15 goto __label_2
shift $P2, $P15
$P3 = $P2[0]
self.'push_string'($P3)
goto __label_1
__label_2: # endfor
self.'notOptStop'(1)
$P4 = __ARG_1.'shift'()
setattribute self, 'name', $P4
$P4 = self.'get_options'(__ARG_1)
setattribute self, 'opts', $P4
.end # WinxedDriverOptions
.sub 'getbool' :method
.param string __ARG_1
getattribute $P2, self, 'opts'
$P1 = $P2[__ARG_1]
isnull $I1, $P1
not $I1
.return($I1)
.end # getbool
.sub 'getstring' :method
.param string __ARG_1
getattribute $P2, self, 'opts'
$P1 = $P2[__ARG_1]
null $S1
if_null $P1, __label_1
set $S1, $P1
__label_1: # endif
.return($S1)
.end # getstring
.sub 'showhelp' :method
getattribute $P2, self, 'name'
print 'Usage: '
print $P2
say ' [options] [program] [args]'
say ' Available options:'
null $I1
null $I2
null $P1
getattribute $P2, self, 'options'
if_null $P2, __label_2
iter $P3, $P2
set $P3, 0
__label_1: # for iteration
unless $P3 goto __label_2
shift $P1, $P3
$P4 = $P1[0]
set $S2, $P4
length $I3, $S2
add $I2, $I3, 4
le $I2, $I1, __label_3
set $I1, $I2
__label_3: # endif
goto __label_1
__label_2: # endfor
getattribute $P2, self, 'options'
if_null $P2, __label_5
iter $P5, $P2
set $P5, 0
__label_4: # for iteration
unless $P5 goto __label_5
shift $P1, $P5
$S1 = $P1[0]
length $I3, $S1
le $I3, 1, __label_6
substr $S2, $S1, 1, 1
eq $S2, '=', __label_6
concat $S3, '--', $S1
set $S1, $S3
goto __label_7
__label_6: # else
concat $S4, '-', $S1
set $S1, $S4
__label_7: # endif
length $I3, $S1
sub $I2, $I1, $I3
repeat $S2, ' ', $I2
$P2 = $P1[1]
print ' '
print $S1
print $S2
print '-> '
say $P2
goto __label_4
__label_5: # endfor
.end # showhelp
.sub Winxed_class_init :anon :load :init
newclass $P0, [ 'WinxedDriverOptions' ]
get_class $P1, [ 'Getopt'; 'Obj' ]
addparent $P0, $P1
addattribute $P0, 'name'
addattribute $P0, 'options'
addattribute $P0, 'opts'
.end
.namespace [ ]
.sub 'path_option' :subid('WSubId_2')
.param pmc __ARG_1
.param string __ARG_2
.param int __ARG_3
$P3 = __ARG_1.'getstring'(__ARG_2)
null $S1
if_null $P3, __label_1
set $S1, $P3
__label_1:
if_null $S1, __label_2
getinterp $P3
$P1 = $P3[9]
$P2 = $P1[__ARG_3]
$P2.'push'($S1)
__label_2: # endif
.end # path_option
.sub 'extname' :subid('WSubId_3') :anon
.param string __ARG_1
.param string __ARG_2
null $S1
length $I1, __ARG_1
le $I1, 7, __label_1
substr $S2, __ARG_1, -7
ne $S2, '.winxed', __label_1
sub $I2, $I1, 7
substr $S3, __ARG_1, 0, $I2
concat $S4, $S3, __ARG_2
set $S1, $S4
goto __label_2
__label_1: # else
concat $S5, __ARG_1, __ARG_2
set $S1, $S5
__label_2: # endif
.return($S1)
.end # extname
.sub 'getcompiler' :subid('WSubId_1') :anon
null $P1
new $P2, 'ExceptionHandler'
set_label $P2, __label_1
push_eh $P2
load_language 'winxed'
compreg $P1, 'winxed'
pop_eh
goto __label_2
__label_1:
.get_results($P3)
finalize $P3
pop_eh
__label_2:
unless_null $P1, __label_3
die "winxed: Cannot load language"
__label_3: # endif
.return($P1)
.end # getcompiler
.sub 'process_args' :subid('WSubId_4') :anon
.param pmc __ARG_1
.const 'Sub' WSubId_1 = "WSubId_1"
.const 'Sub' WSubId_2 = "WSubId_2"
.const 'Sub' WSubId_3 = "WSubId_3"
new $P13, [ 'WinxedDriverOptions' ]
$P13.'WinxedDriverOptions'(__ARG_1)
set $P1, $P13
$P13 = $P1.'getbool'('version')
if_null $P13, __label_1
unless $P13 goto __label_1
$P2 = WSubId_1()
$P13 = $P2.'version_string'()
say $P13
exit 0
__label_1: # endif
$P13 = $P1.'getbool'('help')
set $I1, $P13
$P13 = $P1.'getbool'('c')
set $I2, $P13
$P13 = $P1.'getstring'('target')
null $S1
if_null $P13, __label_2
set $S1, $P13
__label_2:
$P13 = $P1.'getstring'('e')
null $S2
if_null $P13, __label_3
set $S2, $P13
__label_3:
$P13 = $P1.'getstring'('o')
null $S3
if_null $P13, __label_4
set $S3, $P13
__label_4:
$P13 = $P1.'getbool'('debug')
set $I3, $P13
$P13 = $P1.'getbool'('nowarn')
set $I4, $P13
$P13 = $P1.'getbool'('noan')
set $I5, $P13
unless $I1 goto __label_5
$P1.'showhelp'()
exit 0
__label_5: # endif
WSubId_2($P1, 'L', 1)
WSubId_2($P1, 'I', 0)
WSubId_2($P1, 'X', 2)
root_new $P3, ['parrot';'Hash']
$P3["debug"] = $I3
$P3["noan"] = $I5
$P3["nowarn"] = $I4
unless $I2 goto __label_6
if_null $S1, __label_8
die "options -c and --target can't be used together"
__label_8: # endif
$P3["target"] = "pir"
goto __label_7
__label_6: # else
unless_null $S1, __label_9
set $S1, ''
__label_9: # endif
if $S1 == '' goto __label_12
if $S1 == 'run' goto __label_13
if $S1 == 'pir' goto __label_14
if $S1 == 'include' goto __label_15
goto __label_10
__label_12: # case
__label_13: # case
goto __label_11 # break
__label_14: # case
__label_15: # case
set $I2, 1
$P3["target"] = $S1
goto __label_11 # break
__label_10: # default
concat $S8, "Invalid target '", $S1
concat $S8, $S8, "'"
die $S8
__label_11: # switch end
__label_7: # endif
if_null $S3, __label_16
if $I2 goto __label_16
die '-o without -c or --target is not supported yet'
__label_16: # endif
$P4 = WSubId_1()
null $P5
null $S4
new $P13, 'ExceptionHandler'
set_label $P13, __label_17
$P13.'handle_types'(567)
push_eh $P13
unless_null $S2, __label_19
elements $I7, __ARG_1
ge $I7, 1, __label_21
say "ERROR: No program specified"
$P1.'showhelp'()
exit 1
__label_21: # endif
$S5 = __ARG_1[0]
unless $I2 goto __label_22
unless_null $S3, __label_22
$P13 = WSubId_3($S5, '.pir')
set $S4, $P13
__label_22: # endif
$P5 = $P4.'compile_from_file'($S5, $P3 :flat :named)
goto __label_20
__label_19: # else
null $P6
null $P7
unless $I2 goto __label_23
unless_null $S4, __label_24
set $S4, $S3
__label_24: # endif
if_null $S4, __label_25
eq $S4, "-", __label_25
root_new $P7, ['parrot';'FileHandle']
$P7.'open'($S4,'w')
set $P6, $P7
goto __label_26
__label_25: # else
getstdout $P6
__label_26: # endif
$P3['output'] = $P6
__label_23: # endif
concat $S6, 'function main[main](argv){', $S2
concat $S6, $S6, ';}'
$P5 = $P4.'compile'($S6, $P3 :flat :named)
unless $I2 goto __label_27
if_null $P7, __label_29
$P7.'close'()
__label_29: # endif
exit 0
goto __label_28
__label_27: # else
__ARG_1.'unshift'('__EVAL__')
__label_28: # endif
__label_20: # endif
pop_eh
goto __label_18
__label_17:
.get_results($P8)
finalize $P8
pop_eh
$P9 = $P8["payload"]
if_null $P9, __label_30
getattribute $P13, $P9, 'filename'
getattribute $P14, $P9, 'line'
getattribute $P15, $P9, 'message'
getstderr $P0
print $P0, $P13
print $P0, ':'
print $P0, $P14
print $P0, ': '
print $P0, $P15
print $P0, "\n"
goto __label_31
__label_30: # else
$P16 = $P8["message"]
getstderr $P0
print $P0, $P16
print $P0, "\n"
__label_31: # endif
exit 1
__label_18:
unless $I2 goto __label_32
unless_null $S4, __label_33
set $S4, $S3
__label_33: # endif
isnull $I6, $S4
not $I6
unless $I6 goto __label_34
isne $I6, $S4, "-"
__label_34:
unless $I6 goto __label_36
root_new $P10, ['parrot';'FileHandle']
$P10.'open'($S4,'w')
goto __label_35
__label_36:
getstdout $P13
set $P10, $P13
__label_35:
$P10.'print'($P5)
unless $I6 goto __label_37
$P10.'close'()
__label_37: # endif
exit 0
__label_32: # endif
null $P11
new $P13, 'ExceptionHandler'
set_label $P13, __label_38
push_eh $P13
$P15 = $P5.'subs_by_tag'("load")
if_null $P15, __label_41
iter $P17, $P15
set $P17, 0
__label_40: # for iteration
unless $P17 goto __label_41
shift $P12, $P17
$P12()
goto __label_40
__label_41: # endfor
$P5.'mark_initialized'("load")
$P11 = $P5.'main_sub'()
pop_eh
goto __label_39
__label_38:
.get_results($P14)
finalize $P14
pop_eh
getstderr $P0
print $P0, "Cannot find main sub"
print $P0, "\n"
__label_39:
.return($P11)
.end # process_args
.sub '__PARROT_ENTRY_WINXED_main' :main
.param pmc __ARG_1
.const 'Sub' WSubId_4 = "WSubId_4"
.const 'Sub' WSubId_5 = "WSubId_5"
$P1 = WSubId_4(__ARG_1)
null $I1
new $P4, 'ExceptionHandler'
set_label $P4, __label_1
$P4.'handle_types_except'(65543)
push_eh $P4
$P2 = $P1(__ARG_1)
if_null $P2, __label_3
set $I1, $P2
__label_3: # endif
pop_eh
goto __label_2
__label_1:
.get_results($P3)
finalize $P3
pop_eh
WSubId_5($P3)
__label_2:
exit $I1
.end # __PARROT_ENTRY_WINXED_main
.sub 'fail' :subid('WSubId_5') :anon
.param pmc __ARG_1
getstderr $P1
getattribute $P3, __ARG_1, 'message'
null $S1
if_null $P3, __label_1
set $S1, $P3
__label_1:
isnull $I3, $S1
if $I3 goto __label_3
iseq $I3, $S1, ""
__label_3:
unless $I3 goto __label_2
set $S1, "No exception handler and no message"
__label_2: # endif
root_new $P3, ['parrot';'ResizablePMCArray']
assign $P3, 1
$P3[0] = $S1
sprintf $S5, "%s\n", $P3
$P1.'print'($S5)
set $S2, ""
$P2 = __ARG_1.'backtrace_strings'()
elements $I3, $P2
sub $I1, $I3, 1
__label_6: # for condition
lt $I1, 0, __label_5
$S3 = $P2[$I1]
split $P3, "\n", $S3
if_null $P3, __label_8
iter $P4, $P3
set $P4, 0
__label_7: # for iteration
unless $P4 goto __label_8
shift $S4, $P4
index $I3, $S4, "__PARROT_ENTRY"
lt $I3, 0, __label_9
goto __label_7 # continue
__label_9: # endif
root_new $P3, ['parrot';'ResizablePMCArray']
assign $P3, 2
$P3[0] = $S2
$P3[1] = $S4
sprintf $S5, "%s%s", $P3
$P1.'print'($S5)
set $S2, "\n"
goto __label_7
__label_8: # endfor
set $S2, "\nthrown from\n"
__label_4: # for iteration
dec $I1
goto __label_6
__label_5: # for end
getattribute $P3, __ARG_1, 'exit_code'
set $I2, $P3
unless $I2 goto __label_11
set $I3, $I2
goto __label_10
__label_11:
set $I3, 1
__label_10:
exit $I3
.end # fail
# End generated code