Skip to content

Commit

Permalink
[Pheme] refactor with the opcode load_language
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Nov 22, 2009
1 parent 46bfd58 commit c6bdf19
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 56 deletions.
76 changes: 76 additions & 0 deletions lib/PhemeCompiler.pir
@@ -0,0 +1,76 @@
# $Id$

=head1 TITLE

PhemeCompiler.pir - A Pheme compiler.

=head2 Description

This is the base file for the Pheme compiler.

This file includes the parsing and grammar rules from
the src/ directory, loads the relevant PGE libraries,
and registers the compiler under the name 'Pheme'.

=head2 Functions

=over 4

=item onload()

Creates the Pheme compiler using a C<PCT::HLLCompiler>
object.

=cut

.HLL 'pheme'

.sub '' :anon :load
load_bytecode 'PCT.pbc'
load_bytecode 'TGE.pbc'

.local pmc parrotns, hllns, exports
parrotns = get_root_namespace ['parrot']
hllns = get_hll_namespace
exports = split ' ', 'PAST PCT PGE TGE'
parrotns.'export_to'(hllns, exports)
.end

.include 'lib/PhemeObjects.pir'
.include 'lib/PhemeSymbols.pir'
.include 'lib/pheme_grammar_gen.pir'
.include 'lib/ASTGrammar.pir'

.namespace [ 'Pheme';'Compiler' ]

.sub '__onload' :load
load_bytecode 'PCT.pbc'
load_bytecode 'PGE/Text.pbc'

.local pmc p6meta
p6meta = get_root_global ['parrot'], 'P6metaclass'

$P0 = p6meta.'new_class'('Match','parent'=>'parrot;PGE::Match')
$P0 = p6meta.'new_class'('Grammar','parent'=>'Match')
$P0 = p6meta.'new_class'('Pheme::PGE::Grammar','parent'=>'Grammar')

$P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = $P0.'new'()

$P1.'language'('pheme')
$P0 = get_hll_namespace ['Pheme';'Grammar']
$P1.'parsegrammar'($P0)
$P0 = get_hll_namespace ['Pheme';'AST';'Grammar']
$P1.'astgrammar'( $P0)
.end

=back

=cut

# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:

58 changes: 4 additions & 54 deletions pheme.pir
Expand Up @@ -6,65 +6,12 @@ pheme.pir - A Pheme compiler.

=head2 Description

This is the base file for the Pheme compiler.

This file includes the parsing and grammar rules from
the lib/ directory, loads the relevant PGE libraries,
and registers the compiler under the name 'Pheme'.
This is the entry point for the Pheme compiler.

=head2 Functions

=over 4

=item __onload()

Loads the PGE libraries needed for running the parser,
and registers the Pheme compiler using a C<HLLCompiler>
object.

=cut

.HLL 'pheme'

.sub '' :anon :load :init
load_bytecode 'PCT.pbc'
load_bytecode 'TGE.pbc'

.local pmc parrotns, hllns, exports
parrotns = get_root_namespace ['parrot']
hllns = get_hll_namespace
exports = split ' ', 'PAST PCT PGE TGE'
parrotns.'export_to'(hllns, exports)
.end

.include 'lib/PhemeObjects.pir'
.include 'lib/PhemeSymbols.pir'
.include 'lib/pheme_grammar_gen.pir'
.include 'lib/ASTGrammar.pir'

.namespace [ 'Pheme';'Compiler' ]

.sub '__onload' :load :init
load_bytecode 'PCT.pbc'
load_bytecode 'PGE/Text.pbc'

.local pmc p6meta
p6meta = get_root_global ['parrot'], 'P6metaclass'

$P0 = p6meta.'new_class'('Match','parent'=>'parrot;PGE::Match')
$P0 = p6meta.'new_class'('Grammar','parent'=>'Match')
$P0 = p6meta.'new_class'('Pheme::PGE::Grammar','parent'=>'Grammar')

$P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = $P0.'new'()

$P1.'language'('pheme')
$P0 = get_hll_namespace ['Pheme';'Grammar']
$P1.'parsegrammar'($P0)
$P0 = get_hll_namespace ['Pheme';'AST';'Grammar']
$P1.'astgrammar'( $P0)
.end

=item main(args :slurpy) :main

Start compilation by passing any command line C<args> to the Pheme compiler.
Expand All @@ -74,6 +21,8 @@ Start compilation by passing any command line C<args> to the Pheme compiler.
.sub 'main' :anon :main
.param pmc args

load_language 'pheme'

$P0 = compreg 'pheme'

.include 'except_severity.pasm'
Expand Down Expand Up @@ -102,3 +51,4 @@ Start compilation by passing any command line C<args> to the Pheme compiler.
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:

8 changes: 6 additions & 2 deletions setup.pir
Expand Up @@ -46,13 +46,14 @@ No Configure step, no Makefile generated.

$P3 = new 'Hash'
$P4 = split "\n", <<'SOURCES'
pheme.pir
lib/PhemeCompiler.pir
lib/pheme_grammar_gen.pir
lib/ASTGrammar.pir
lib/PhemeObjects.pir
lib/PhemeSymbols.pir
SOURCES
$P3['pheme.pbc'] = $P4
$P3['pheme/pheme.pbc'] = $P4
$P3['pheme.pbc'] = 'pheme.pir'
$P0['pbc_pir'] = $P3

$P5 = new 'Hash'
Expand All @@ -65,6 +66,9 @@ SOURCES
$P0['prove_exec'] = $S0
$P0['prove_files'] = 't/*.t t/phemer/*.t'

# install
$P0['inst_lang'] = 'pheme/pheme.pbc'

.tailcall setup(args :flat, $P0 :flat :named)
.end

Expand Down

0 comments on commit c6bdf19

Please sign in to comment.