Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created November 21, 2010 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnthn/709170 to your computer and use it in GitHub Desktop.
Save jnthn/709170 to your computer and use it in GitHub Desktop.
> "hi"~~/h/
>>>>>>>>>> Boilerplate to start with again...
"past" => PMC 'PAST;Block' {
<loadlibs> => ResizablePMCArray (size:2) [
"nqp_group",
"nqp_ops"
]
<pos> => 0
<source> => "\"hi\"~~/h/\n"
[0] => PMC 'PAST;Op' {
<pirop> => "nqp_dynop_setup v"
}
[1] => PMC 'PAST;Stmts'
[2] => PMC 'PAST;Op' {
<inline> => ResizablePMCArray (size:6) [
" $P0 = find_dynamic_lex \"$*CTXSAVE\"",
" if null $P0 goto ctxsave_done",
" $I0 = can $P0, \"ctxsave\"",
" unless $I0 goto ctxsave_done",
" $P0.\"ctxsave\"()",
" ctxsave_done:"
]
}
[3] => PMC 'PAST;Op' {
<pirop> => "return"
[0] => PMC 'PAST;Stmts' {
<pos> => 0
<source> => \past
>>>>>>>>>> "hi" ~~ /h/ translates to "hi".ACCEPTS(/h/), thus the ACCEPTS method call
[0] => PMC 'PAST;Op' {
<name> => "ACCEPTS"
<pasttype> => "callmethod"
<pos> => 4
<source> => \past
>>>>>>>>>> This is the invocant of the method call. /h/ is really
>>>>>>>>>> Regex::Regex.new([real /h/ thingy]) to wrap it up in an
>>>>>>>>>> object so we have something to call ACCEPTS on. We can
>>>>>>>>>> likely do a little better in the long run but can make
>>>>>>>>>> this way work for a first cut.
[0] => PMC 'PAST;Op' {
<name> => "new"
<pasttype> => "callmethod"
>>>>>>>>>> Here comes the regex code we saw last time around. This
>>>>>>>>>> is a tad weird - seems like there's some sink context
>>>>>>>>>> stuff going on here, so the node is installed under <scan>
>>>>>>>>>> but that doesn't impact compilation at all. It's just an
>>>>>>>>>> extra reference to the PAST for the regex body used by
>>>>>>>>>> the Actions.
<sink> => PMC 'PAST;Block' {
<blocktype> => "method"
<symtable> => Hash {
"$/" => Hash {
"scope" => "lexical"
},
"$¢" => Hash {
"scope" => "lexical"
}
}
[0] => PMC 'PAST;Stmts'
[1] => PMC 'PAST;Regex' {
<capnames> => Hash {
"" => 0
}
<pasttype> => "concat"
[0] => PMC 'PAST;Regex' {
<pasttype> => "scan"
}
[1] => PMC 'PAST;Regex' {
<pasttype> => "concat"
<pos> => 7
<source> => \past
[0] => PMC 'PAST;Regex' {
<pasttype> => "literal"
<pos> => 7
<source> => \past
[0] => "h"
}
}
[2] => PMC 'PAST;Regex' {
<backtrack> => "g"
<pasttype> => "pass"
}
}
}
>>>>>>>>>> This is Regex::Regex, which we're calling .new on
[0] => PMC 'PAST;Var' {
<name> => "Regex"
<namespace> => ResizablePMCArray (size:1) [
"Regex"
]
<scope> => "package"
}
>>>>>>>>>> Confusing as heck. But this is a reference to the actual
>>>>>>>>>> regex data structure itself. The same one attached to <scan>
>>>>>>>>>> but the dumper won't emit it twice, so it shows \past to
>>>>>>>>>> indicate it's a reference to something already emitted.
[1] => \past
}
>>>>>>>>>> This is passing the second argument to ACCEPTS which is the
>>>>>>>>>> string to match against.
[1] => PMC 'PAST;Val' {
<value> => "hi"
}
>>>>>>>>>> And that's the end of the interesting stuff - rest is more
>>>>>>>>>> boilerplate.
}
}
}
[4] => PMC 'PAST;Block' {
<lexical> => 0
<namespace> => ""
<pirflags> => ":load"
[0] => PMC 'PAST;Op' {
<pasttype> => "call"
[0] => PMC 'PAST;Val' {
<value> => \past
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment