Skip to content

Instantly share code, notes, and snippets.

@rakudo
Created September 11, 2009 15:29
Show Gist options
  • Save rakudo/185365 to your computer and use it in GitHub Desktop.
Save rakudo/185365 to your computer and use it in GitHub Desktop.
$ parrot_install/bin/parrot parrot_install/lib/1.5.0-devel/library/PGE/Perl6Grammar.pir --target=pir
> token foo { a* }
## <::foo>
.namespace []
.sub "foo" :method
.param pmc adverbs :unique_reg :slurpy :named
.local pmc mob
.local string target :unique_reg
.local pmc mfrom, mpos :unique_reg
.local int cpos, iscont :unique_reg
$P0 = get_hll_global ['PGE'], '$!MATCH'
(mob, cpos, target, mfrom, mpos, iscont) = $P0.'new'(self, adverbs :flat :named)
.local int lastpos
lastpos = length target
if cpos > lastpos goto fail_rule
.local pmc cpool :unique_reg
.local pmc cstack :unique_reg
cpool = get_root_global ['parrot';'PGE';'Exp'], '@!CPOOL'
unless cpool goto new_cstack
cstack = pop cpool
goto have_cstack
new_cstack:
cstack = root_new ['parrot';'ResizableIntegerArray']
have_cstack:
.local pmc ustack :unique_reg
ustack = root_new ['parrot';'ResizablePMCArray']
.local int pos, rep, cutmark :unique_reg
try_match:
if cpos > lastpos goto fail_rule
mfrom = cpos
pos = cpos
cutmark = 0
local_branch cstack, R
if cutmark <= -2 goto fail_cut
inc cpos
if iscont goto try_match
fail_rule:
cutmark = -2
fail_cut:
assign cstack, 0
push cpool, cstack
fail_cut_loop:
mob.'_failcut'(cutmark)
.return (mob)
goto fail_cut_loop
succeed:
mpos = pos
.return (mob)
fail:
local_return cstack
R: # quant 0..Inf none
local_branch cstack, R_repeat
if cutmark != 245 goto fail
cutmark = 0
goto fail
R_repeat:
push ustack, pos
local_branch cstack, R244
pos = pop ustack
if cutmark != 0 goto fail
local_branch cstack, succeed
if cutmark != 0 goto fail
cutmark = 245
goto fail
R244: # literal
$I0 = pos + 1
if $I0 > lastpos goto fail
$S0 = substr target, pos, 1
if $S0 != "a" goto fail
pos += 1
goto R_repeat
.end
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment