Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 144 lines (109 sloc) 3.351 kB
5bb360e @tewk Cardinal restart
tewk authored
1 =head1 TITLE
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
2
5bb360e @tewk Cardinal restart
tewk authored
3 cardinal.pir - A cardinal compiler.
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
4
5bb360e @tewk Cardinal restart
tewk authored
5 =head2 Description
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
6
5bb360e @tewk Cardinal restart
tewk authored
7 This is the base file for the cardinal compiler.
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
8
5bb360e @tewk Cardinal restart
tewk authored
9 This file includes the parsing and grammar rules from
10 the src/ directory, loads the relevant PGE libraries,
11 and registers the compiler under the name 'cardinal'.
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
12
5bb360e @tewk Cardinal restart
tewk authored
13 =head2 Functions
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
14
5bb360e @tewk Cardinal restart
tewk authored
15 =over 4
06b8a84 @tewk [Cardinal] refactor to follow Perl6 AST/OST example
tewk authored
16
5bb360e @tewk Cardinal restart
tewk authored
17 =item onload()
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
18
5bb360e @tewk Cardinal restart
tewk authored
19 Creates the cardinal compiler using a C<PCT::HLLCompiler>
20 object.
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
21
5bb360e @tewk Cardinal restart
tewk authored
22 =cut
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
23
5183792 @kjs [cardinal]
kjs authored
24
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
25 .HLL 'cardinal'
99735ad @Whiteknight [languages] updating all languages except Tcl and Perl6 to use ".name…
Whiteknight authored
26 .namespace []
5183792 @kjs [cardinal]
kjs authored
27
c27492c @tene [cardinal]
tene authored
28 .include 'src/gen_builtins.pir'
29
5183792 @kjs [cardinal]
kjs authored
30 .sub 'onload' :anon :load :init
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
31 load_bytecode 'PCT.pbc'
32 .local pmc parrotns, cardinalns, exports
33 parrotns = get_root_namespace ['parrot']
34 cardinalns = get_hll_namespace
107cc3f @tene Add foreign-load function to load libraries from a foreign language.
tene authored
35 exports = split ' ', 'PAST PCT PGE'
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
36 parrotns.'export_to'(cardinalns, exports)
5183792 @kjs [cardinal]
kjs authored
37 .end
38
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
39 .include 'src/gen_grammar.pir'
40 .include 'src/parser/quote_expression.pir'
41 .include 'src/gen_actions.pir'
ecd9ee5 @tene [cardinal]: Un-break regexes from the NameSpace updates from a while …
tene authored
42 .namespace [ 'cardinal';'Compiler' ]
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
43
3356e23 @damianknopp [cardinal] Adding initial support for Range, Time, Math, GC, and Kern…
damianknopp authored
44 #no caridinal_group found on my machine
45 #.loadlib 'cardinal_group'
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
46
5bb360e @tewk Cardinal restart
tewk authored
47 .sub 'onload' :anon :load :init
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
48 .local pmc cardinalmeta, compilerclass, compiler
c27492c @tene [cardinal]
tene authored
49 cardinalmeta = get_hll_global ['CardinalObject'], '!CARDINALMETA'
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
50 compilerclass = cardinalmeta.'new_class'('cardinal::Compiler', 'parent'=>'PCT::HLLCompiler')
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
51
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
52 compiler = compilerclass.'new'()
53 compiler.'language'('cardinal')
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
54 $P0 = get_hll_namespace ['cardinal';'Grammar']
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
55 compiler.'parsegrammar'($P0)
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
56 $P0 = get_hll_namespace ['cardinal';'Grammar';'Actions']
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
57 compiler.'parseactions'($P0)
5183792 @kjs [cardinal]
kjs authored
58
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
59 compiler.'commandline_banner'("Cardinal - Ruby for the Parrot VM\n\n")
60 compiler.'commandline_prompt'('crb(main):001:0>')
65e2272 @kjs [cardinal] add 'and' and 'or' operators.
kjs authored
61
5183792 @kjs [cardinal]
kjs authored
62 ## create a list of END blocks to be run
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
63 $P0 = new 'CardinalArray'
5183792 @kjs [cardinal]
kjs authored
64 set_hll_global ['cardinal'], '@?END_BLOCKS', $P0
dedd006 @tene Variable assignment works in cardinal.
tene authored
65
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
66 $P0 = new 'CardinalArray'
dedd006 @tene Variable assignment works in cardinal.
tene authored
67 set_hll_global ['cardinal';'Grammar';'Actions'], '@?BLOCK', $P0
b8e8ee8 @tene [cardinal]
tene authored
68
0fe97c1 @tene Merge hllmagic branch into trunk.
tene authored
69 $P1 = get_hll_global ['PAST';'Compiler'], '%valflags'
b8e8ee8 @tene [cardinal]
tene authored
70 $P1['CardinalString'] = 'e'
362250e @tewk [Cardinal] Closer to support for classes, blocking on .HLL bug
tewk authored
71 .end
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
72
5bb360e @tewk Cardinal restart
tewk authored
73 =item main(args :slurpy) :main
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
74
5bb360e @tewk Cardinal restart
tewk authored
75 Start compilation by passing any command line C<args>
76 to the cardinal compiler.
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
77
5bb360e @tewk Cardinal restart
tewk authored
78 =cut
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
79
5bb360e @tewk Cardinal restart
tewk authored
80 .sub 'main' :main
5bd60ec @tene [cardinal]
tene authored
81 .param pmc args_str
4cfaaf2 @tewk Cleanup and refactor for class support
tewk authored
82
5bd60ec @tene [cardinal]
tene authored
83 ## create ARGS global.
84 .local pmc args, iter
85 args = new 'CardinalArray'
86 iter = new 'Iterator', args_str
b0affa6 @tene [cardinal]
tene authored
87 $P0 = shift iter
5bd60ec @tene [cardinal]
tene authored
88 args_loop:
89 unless iter goto args_end
90 $P0 = shift iter
91 push args, $P0
92 goto args_loop
93 args_end:
94 set_hll_global 'ARGS', args
5183792 @kjs [cardinal]
kjs authored
95
3e448bd @tene [cardinal]
tene authored
96 $P0 = compreg 'cardinal'
97 $P1 = $P0.'command_line'(args_str)
98
5183792 @kjs [cardinal]
kjs authored
99 .include 'iterator.pasm'
100 $P0 = get_hll_global ['cardinal'], '@?END_BLOCKS'
101 iter = new 'Iterator', $P0
102 iter = .ITERATE_FROM_END
103 iter_loop:
104 unless iter goto iter_end
105 $P0 = pop iter
106 $P0()
107 goto iter_loop
108 iter_end:
4cfaaf2 @tewk Cleanup and refactor for class support
tewk authored
109 .end
110
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
111 .sub 'fetch-library' :method
112 .param pmc request
113 .local pmc name, retval, library, inc_hash
114 name = request['name']
115 $S0 = join '/', name
116 retval = 'require'($S0, 'module'=>1)
117 if null retval goto fail
118 library = new 'Hash'
119 library['name'] = name
120 inc_hash = get_hll_global '%INC'
121 $S0 = inc_hash[$S0]
122 library['filename'] = $S0
123 $P1 = new 'Hash'
124 $P0 = get_hll_namespace name
125 $P1['ALL'] = $P0
126 $P1['DEFAULT'] = $P0
127 library['symbols'] = $P1
128 .return (library)
129 fail:
130 .return (retval)
131 .end
132
133
5bb360e @tewk Cardinal restart
tewk authored
134 =back
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
135
136 =cut
9af6817 @paultcochrane [cardinal] Added emacs/vim coda as per coding standards
paultcochrane authored
137
138 # Local Variables:
139 # mode: pir
140 # fill-column: 100
141 # End:
a5fb08e @coke [codingstd]
coke authored
142 # vim: expandtab shiftwidth=4 ft=pir:
5bb360e @tewk Cardinal restart
tewk authored
143
Something went wrong with that request. Please try again.