Skip to content

HTTPS clone URL

Subversion checkout URL

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