Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 149 lines (113 sloc) 3.423 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 ".namespa...
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 bac...
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 Kernel ...
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 lo...
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 lo...
tene authored
50 compilerclass = cardinalmeta.'new_class'('cardinal::Compiler', 'parent'=>'PCT::HLLCompiler')
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
51
550139a @joeri Respect $, when joining, and set $, when cardinal starts
joeri authored
52 $P2 = new 'CardinalString'
53 $P2 = ""
54 set_hll_global '$,', $P2
55
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library lo...
tene authored
56 compiler = compilerclass.'new'()
57 compiler.'language'('cardinal')
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
58 $P0 = get_hll_namespace ['cardinal';'Grammar']
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library lo...
tene authored
59 compiler.'parsegrammar'($P0)
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
60 $P0 = get_hll_namespace ['cardinal';'Grammar';'Actions']
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library lo...
tene authored
61 compiler.'parseactions'($P0)
5183792 @kjs [cardinal]
kjs authored
62
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library lo...
tene authored
63 compiler.'commandline_banner'("Cardinal - Ruby for the Parrot VM\n\n")
64 compiler.'commandline_prompt'('crb(main):001:0>')
65e2272 @kjs [cardinal] add 'and' and 'or' operators.
kjs authored
65
5183792 @kjs [cardinal]
kjs authored
66 ## create a list of END blocks to be run
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
67 $P0 = new 'CardinalArray'
5183792 @kjs [cardinal]
kjs authored
68 set_hll_global ['cardinal'], '@?END_BLOCKS', $P0
dedd006 @tene Variable assignment works in cardinal.
tene authored
69
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
70 $P0 = new 'CardinalArray'
dedd006 @tene Variable assignment works in cardinal.
tene authored
71 set_hll_global ['cardinal';'Grammar';'Actions'], '@?BLOCK', $P0
b8e8ee8 @tene [cardinal]
tene authored
72
0fe97c1 @tene Merge hllmagic branch into trunk.
tene authored
73 $P1 = get_hll_global ['PAST';'Compiler'], '%valflags'
b8e8ee8 @tene [cardinal]
tene authored
74 $P1['CardinalString'] = 'e'
362250e @tewk [Cardinal] Closer to support for classes, blocking on .HLL bug
tewk authored
75 .end
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
76
5bb360e @tewk Cardinal restart
tewk authored
77 =item main(args :slurpy) :main
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
78
5bb360e @tewk Cardinal restart
tewk authored
79 Start compilation by passing any command line C<args>
80 to the cardinal compiler.
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
81
5bb360e @tewk Cardinal restart
tewk authored
82 =cut
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
83
5bb360e @tewk Cardinal restart
tewk authored
84 .sub 'main' :main
5bd60ec @tene [cardinal]
tene authored
85 .param pmc args_str
4cfaaf2 @tewk Cleanup and refactor for class support
tewk authored
86
5bd60ec @tene [cardinal]
tene authored
87 ## create ARGS global.
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
88 .local pmc args, it
5bd60ec @tene [cardinal]
tene authored
89 args = new 'CardinalArray'
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
90 it = iter args_str
91 $P0 = shift it
5bd60ec @tene [cardinal]
tene authored
92 args_loop:
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
93 unless it goto args_end
94 $P0 = shift it
5bd60ec @tene [cardinal]
tene authored
95 push args, $P0
96 goto args_loop
97 args_end:
98 set_hll_global 'ARGS', args
5183792 @kjs [cardinal]
kjs authored
99
3e448bd @tene [cardinal]
tene authored
100 $P0 = compreg 'cardinal'
101 $P1 = $P0.'command_line'(args_str)
102
5183792 @kjs [cardinal]
kjs authored
103 .include 'iterator.pasm'
104 $P0 = get_hll_global ['cardinal'], '@?END_BLOCKS'
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
105 it = iter $P0
106 it = .ITERATE_FROM_END
5183792 @kjs [cardinal]
kjs authored
107 iter_loop:
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
108 unless it goto iter_end
109 $P0 = pop it
5183792 @kjs [cardinal]
kjs authored
110 $P0()
111 goto iter_loop
112 iter_end:
4cfaaf2 @tewk Cleanup and refactor for class support
tewk authored
113 .end
114
e3d7404 @tene Track changes in HLL library loading API.
tene authored
115 .sub 'load_library' :method
116 .param pmc name
117 .param pmc request :named :slurpy
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library lo...
tene authored
118 .local pmc name, retval, library, inc_hash
119 $S0 = join '/', name
120 retval = 'require'($S0, 'module'=>1)
121 if null retval goto fail
122 library = new 'Hash'
123 library['name'] = name
124 inc_hash = get_hll_global '%INC'
125 $S0 = inc_hash[$S0]
126 library['filename'] = $S0
127 $P1 = new 'Hash'
128 $P0 = get_hll_namespace name
aecc5ad @tene Also set the namespace to be returned to a calling language.
tene authored
129 library['namespace'] = $P0
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library lo...
tene authored
130 $P1['ALL'] = $P0
131 $P1['DEFAULT'] = $P0
132 library['symbols'] = $P1
133 .return (library)
134 fail:
135 .return (retval)
136 .end
137
138
5bb360e @tewk Cardinal restart
tewk authored
139 =back
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
140
141 =cut
9af6817 @paultcochrane [cardinal] Added emacs/vim coda as per coding standards
paultcochrane authored
142
143 # Local Variables:
144 # mode: pir
145 # fill-column: 100
146 # End:
a5fb08e @coke [codingstd]
coke authored
147 # vim: expandtab shiftwidth=4 ft=pir:
5bb360e @tewk Cardinal restart
tewk authored
148
Something went wrong with that request. Please try again.