Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor HLLCompiler overload into a cheat file.
  • Loading branch information
pmichaud committed Oct 16, 2009
1 parent 88773ed commit e335cf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 42 deletions.
2 changes: 2 additions & 0 deletions build/Makefile.in
Expand Up @@ -57,6 +57,8 @@ P6REGEX_SOURCES = \
src/gen/p6regex-actions.pir \
src/cheats/PGE.pir \
src/cheats/p6regex-grammar.pir \
src/cheats/hll-compiler.pir \
src/cheats/regex-cursor-protoregex.pir \
src/PAST/Regex.pir \
src/PAST/Compiler-Regex.pir \
src/Regex/constants.pir \
Expand Down
60 changes: 18 additions & 42 deletions src/Regex/P6Regex.pir
Expand Up @@ -9,20 +9,37 @@ Regex::P6Regex - Parser/compiler for Perl 6 regexes

=cut

.include 'src/cheats/hll-compiler.pir'

# these will eventually move to Regex.pir
.include 'src/PAST/Regex.pir'
.include 'src/PAST/Compiler-Regex.pir'
.include 'src/Regex/Cursor.pir'
.include 'src/Regex/Cursor-builtins.pir'
.include 'src/Regex/Match.pir'
.include 'src/Regex/Dumper.pir'
.include 'src/cheats/regex-cursor-protoregex.pir'

.include 'src/gen/p6regex-grammar.pir'
.include 'src/gen/p6regex-actions.pir'
.include 'src/cheats/PGE.pir'
.include 'src/cheats/p6regex-grammar.pir'

.namespace ['Regex';'P6Regex';'Compiler']

.sub '' :anon :load :init
load_bytecode 'PCT.pbc'
.local pmc p6meta, p6regex
p6meta = get_hll_global 'P6metaclass'
p6regex = p6meta.'new_class'('Regex::P6Regex::Compiler', 'parent'=>'PCT::HLLCompiler')
p6regex = p6meta.'new_class'('Regex::P6Regex::Compiler', 'parent'=>'HLL::Compiler')
p6regex.'language'('Regex::P6Regex')
$P0 = get_hll_namespace ['Regex';'P6Regex';'Grammar']
p6regex.'parsegrammar'($P0)
$P0 = get_hll_namespace ['Regex';'P6Regex';'Actions']
p6regex.'parseactions'($P0)
.end
.sub 'main' :main
.param pmc args_str
Expand All @@ -32,47 +49,6 @@ Regex::P6Regex - Parser/compiler for Perl 6 regexes
.end
# we have to overload PCT::HLLCompiler's parse method to support P6Regex grammars

.sub 'parse' :method
.param pmc source
.param pmc options :slurpy :named

.local pmc parsegrammar, parseactions, match
parsegrammar = get_hll_global ['Regex';'P6Regex'], 'Grammar'
$I0 = isa parsegrammar, ['Regex';'Cursor']
unless $I0 goto parse_old

parseactions = get_hll_global ['Regex';'P6Regex'], 'Actions'
match = parsegrammar.'parse'(source, 'from'=>0, 'action'=>parseactions)
unless match goto err_parsefail
.return (match)

err_parsefail:
self.'panic'('Unable to parse source')
.return (match)

parse_old:
$P0 = get_hll_global ['PCT'], 'HLLCompiler'
$P1 = find_method $P0, 'parse'
.tailcall self.$P1(source, options :flat :named)
.end


# these will eventually move to Regex.pir
.include 'src/PAST/Regex.pir'
.include 'src/PAST/Compiler-Regex.pir'
.include 'src/Regex/Cursor.pir'
.include 'src/Regex/Cursor-builtins.pir'
.include 'src/Regex/Match.pir'
.include 'src/Regex/Dumper.pir'
.include 'src/cheats/regex-cursor-protoregex.pir'

.include 'src/gen/p6regex-grammar.pir'
.include 'src/gen/p6regex-actions.pir'
.include 'src/cheats/PGE.pir'
.include 'src/cheats/p6regex-grammar.pir'

=cut
# Local Variables:
Expand Down

0 comments on commit e335cf9

Please sign in to comment.