Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 153 lines (117 sloc) 3.505 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'
0222330 @fperrad fix after ops massacre
fperrad authored
26 .loadlib 'io_ops'
27 .loadlib 'sys_ops'
28 .loadlib 'trans_ops'
29 .loadlib 'obscure_ops'
99735ad @Whiteknight [languages] updating all languages except Tcl and Perl6 to use ".name…
Whiteknight authored
30 .namespace []
5183792 @kjs [cardinal]
kjs authored
31
c27492c @tene [cardinal]
tene authored
32 .include 'src/gen_builtins.pir'
33
5183792 @kjs [cardinal]
kjs authored
34 .sub 'onload' :anon :load :init
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
35 load_bytecode 'PCT.pbc'
36 .local pmc parrotns, cardinalns, exports
37 parrotns = get_root_namespace ['parrot']
38 cardinalns = get_hll_namespace
107cc3f @tene Add foreign-load function to load libraries from a foreign language.
tene authored
39 exports = split ' ', 'PAST PCT PGE'
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
40 parrotns.'export_to'(cardinalns, exports)
5183792 @kjs [cardinal]
kjs authored
41 .end
42
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
43 .include 'src/gen_grammar.pir'
44 .include 'src/parser/quote_expression.pir'
45 .include 'src/gen_actions.pir'
ecd9ee5 @tene [cardinal]: Un-break regexes from the NameSpace updates from a while …
tene authored
46 .namespace [ 'cardinal';'Compiler' ]
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
47
3356e23 @damianknopp [cardinal] Adding initial support for Range, Time, Math, GC, and Kern…
damianknopp authored
48 #no caridinal_group found on my machine
49 #.loadlib 'cardinal_group'
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
50
5bb360e @tewk Cardinal restart
tewk authored
51 .sub 'onload' :anon :load :init
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
52 .local pmc cardinalmeta, compilerclass, compiler
c27492c @tene [cardinal]
tene authored
53 cardinalmeta = get_hll_global ['CardinalObject'], '!CARDINALMETA'
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
54 compilerclass = cardinalmeta.'new_class'('cardinal::Compiler', 'parent'=>'PCT::HLLCompiler')
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
55
550139a @joeri Respect $, when joining, and set $, when cardinal starts
joeri authored
56 $P2 = new 'CardinalString'
57 $P2 = ""
58 set_hll_global '$,', $P2
59
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
60 compiler = compilerclass.'new'()
61 compiler.'language'('cardinal')
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
62 $P0 = get_hll_namespace ['cardinal';'Grammar']
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
63 compiler.'parsegrammar'($P0)
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
64 $P0 = get_hll_namespace ['cardinal';'Grammar';'Actions']
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
65 compiler.'parseactions'($P0)
5183792 @kjs [cardinal]
kjs authored
66
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
67 compiler.'commandline_banner'("Cardinal - Ruby for the Parrot VM\n\n")
ad36bd0 @tadzik Add a space in the REPL prompt to improve readability
tadzik authored
68 compiler.'commandline_prompt'('crb(main):001:0> ')
65e2272 @kjs [cardinal] add 'and' and 'or' operators.
kjs authored
69
5183792 @kjs [cardinal]
kjs authored
70 ## create a list of END blocks to be run
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
71 $P0 = new 'CardinalArray'
5183792 @kjs [cardinal]
kjs authored
72 set_hll_global ['cardinal'], '@?END_BLOCKS', $P0
dedd006 @tene Variable assignment works in cardinal.
tene authored
73
d2d3e9f @tene Partially erge pct_hll branch into trunk.
tene authored
74 $P0 = new 'CardinalArray'
dedd006 @tene Variable assignment works in cardinal.
tene authored
75 set_hll_global ['cardinal';'Grammar';'Actions'], '@?BLOCK', $P0
b8e8ee8 @tene [cardinal]
tene authored
76
0fe97c1 @tene Merge hllmagic branch into trunk.
tene authored
77 $P1 = get_hll_global ['PAST';'Compiler'], '%valflags'
b8e8ee8 @tene [cardinal]
tene authored
78 $P1['CardinalString'] = 'e'
362250e @tewk [Cardinal] Closer to support for classes, blocking on .HLL bug
tewk authored
79 .end
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
80
5bb360e @tewk Cardinal restart
tewk authored
81 =item main(args :slurpy) :main
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
82
5bb360e @tewk Cardinal restart
tewk authored
83 Start compilation by passing any command line C<args>
84 to the cardinal compiler.
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
85
5bb360e @tewk Cardinal restart
tewk authored
86 =cut
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
87
5bb360e @tewk Cardinal restart
tewk authored
88 .sub 'main' :main
5bd60ec @tene [cardinal]
tene authored
89 .param pmc args_str
4cfaaf2 @tewk Cleanup and refactor for class support
tewk authored
90
5bd60ec @tene [cardinal]
tene authored
91 ## create ARGS global.
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
92 .local pmc args, it
5bd60ec @tene [cardinal]
tene authored
93 args = new 'CardinalArray'
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
94 it = iter args_str
95 $P0 = shift it
5bd60ec @tene [cardinal]
tene authored
96 args_loop:
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
97 unless it goto args_end
98 $P0 = shift it
5bd60ec @tene [cardinal]
tene authored
99 push args, $P0
100 goto args_loop
101 args_end:
102 set_hll_global 'ARGS', args
5183792 @kjs [cardinal]
kjs authored
103
3e448bd @tene [cardinal]
tene authored
104 $P0 = compreg 'cardinal'
105 $P1 = $P0.'command_line'(args_str)
106
5183792 @kjs [cardinal]
kjs authored
107 .include 'iterator.pasm'
108 $P0 = get_hll_global ['cardinal'], '@?END_BLOCKS'
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
109 it = iter $P0
110 it = .ITERATE_FROM_END
5183792 @kjs [cardinal]
kjs authored
111 iter_loop:
ff8ddf9 @joeri Use iter opcode instead of new 'Iterator'
joeri authored
112 unless it goto iter_end
113 $P0 = pop it
5183792 @kjs [cardinal]
kjs authored
114 $P0()
115 goto iter_loop
116 iter_end:
4cfaaf2 @tewk Cleanup and refactor for class support
tewk authored
117 .end
118
e3d7404 @tene Track changes in HLL library loading API.
tene authored
119 .sub 'load_library' :method
120 .param pmc name
121 .param pmc request :named :slurpy
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
122 .local pmc name, retval, library, inc_hash
123 $S0 = join '/', name
124 retval = 'require'($S0, 'module'=>1)
125 if null retval goto fail
126 library = new 'Hash'
127 library['name'] = name
128 inc_hash = get_hll_global '%INC'
129 $S0 = inc_hash[$S0]
130 library['filename'] = $S0
131 $P1 = new 'Hash'
132 $P0 = get_hll_namespace name
aecc5ad @tene Also set the namespace to be returned to a calling language.
tene authored
133 library['namespace'] = $P0
08f0f9f @tene Add a fetch-library method to the compiler for inter-language library…
tene authored
134 $P1['ALL'] = $P0
135 $P1['DEFAULT'] = $P0
136 library['symbols'] = $P1
137 .return (library)
138 fail:
139 .return (retval)
140 .end
141
142
5bb360e @tewk Cardinal restart
tewk authored
143 =back
272b0b9 @tewk languages/cardinal Initial checkin
tewk authored
144
145 =cut
9af6817 @paultcochrane [cardinal] Added emacs/vim coda as per coding standards
paultcochrane authored
146
147 # Local Variables:
148 # mode: pir
149 # fill-column: 100
150 # End:
a5fb08e @coke [codingstd]
coke authored
151 # vim: expandtab shiftwidth=4 ft=pir:
5bb360e @tewk Cardinal restart
tewk authored
152
Something went wrong with that request. Please try again.