This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
/
wmlsi.pir
93 lines (81 loc) · 1.76 KB
/
wmlsi.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
# Copyright (C) 2006-2009, Parrot Foundation.
# $Id$
=head1 WMLScript Interpreter
=head2 Synopsis
parrot-wmlsi file.wmlsc function [params ...]
=head2 Description
B<wmlsi> translates a WMLScript bytecode file to Parrot PBC and calls
C<function(params, ...)>.
=head2 See Also
parrot-wmlsd
=cut
.HLL 'wmlscript'
.sub 'main' :main
.param pmc argv
load_language 'wmlscript'
.local int argc
.local string progname
.local string filename
.local string entryname
.local string content
argc = elements argv
if argc < 3 goto USAGE
progname = shift argv
filename = shift argv
entryname = shift argv
content = load_script(filename)
unless content goto L1
.local pmc loader
.local pmc script
new loader, 'WmlsBytecode'
push_eh _handler
script = loader.'load'(content)
script['filename'] = filename
.local string gen_pir
gen_pir = script.'translate'()
.local pmc pir_comp
.local pmc pbc_out
pir_comp = compreg 'PIR'
pbc_out = pir_comp(gen_pir)
$P0 = pbc_out[0] # __onload
$P0()
.local pmc params
new params, 'ResizablePMCArray'
L2:
unless argv goto L3
$S0 = shift argv
new $P0, 'WmlsString'
$P0 = $S0
push params, $P0
goto L2
L3:
.local pmc entry
$S0 = filename
$S0 .= ':'
$S0 .= entryname
entry = get_hll_global $S0
unless null entry goto L4
print $S0
print " not found.\n"
end
L4:
entry(params :flat)
pop_eh
L1:
end
USAGE:
printerr "Usage: parrot wmlsi.pbc filename entry\n"
exit -1
_handler:
.local pmc e
.local string msg
.get_results (e)
msg = e
say msg
end
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: