Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[PGE]:

Move compilation of PGE::Exp nodes into PGE/Exp.pir and PGE::Exp
namespace.


git-svn-id: https://svn.parrot.org/parrot/trunk@15264 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
commit e1f7b0caf76ae8487830de128d01f3e2fc0dc897 1 parent 357adc3
@pmichaud pmichaud authored
View
43 compilers/pge/PGE/Exp.pir
@@ -44,6 +44,49 @@ PGE::Exp - base class for expressions
=over 4
+=item C<compile(PMC source, PMC adverbs :slurpy :named)>
+
+Compile the C<source> expression into PIR or a subroutine,
+according to the C<target> adverb.
+
+=cut
+
+.sub 'compile'
+ .param pmc source
+ .param pmc adverbs :slurpy :named
+
+ .local string target
+ target = adverbs['target']
+ target = downcase target
+
+ .local string grammar
+ .local string nsformat
+ nsformat = '.namespace'
+ grammar = adverbs['grammar']
+ if grammar == '' goto pir
+ nsformat = ".namespace [ '%0' ]"
+ pir:
+ .local pmc code
+ code = new 'PGE::CodeString'
+ code.'emit'(nsformat, grammar)
+ $P0 = source.'root_pir'(adverbs :flat :named)
+ code .= $P0
+ if target != 'pir' goto bytecode
+ .return (code)
+
+ bytecode:
+ $P0 = compreg 'PIR'
+ $P1 = $P0(code)
+ make_grammar:
+ if grammar == '' goto end
+ $I0 = find_type grammar
+ if $I0 > 0 goto end
+ $P0 = subclass 'PGE::Grammar', grammar
+ end:
+ .return ($P1)
+.end
+
+
=item C<root_pir(PMC adverbs)>
Return a CodeString object containing the entire expression
View
21 compilers/pge/PGE/P5Regex.pir
@@ -17,9 +17,10 @@
.local string target
target = adverbs['target']
+ target = downcase target
.local pmc match
- $P0 = get_hll_global ["PGE::Grammar"], "p5regex"
+ $P0 = get_global "p5regex"
match = $P0(source)
if target != 'parse' goto check
.return (match)
@@ -39,24 +40,10 @@
pad = new .Hash
pad['subpats'] = 0
exp = exp.'p5analyze'(pad)
- if target != 'exp' goto pir
- .return (exp)
-
- pir:
- .local pmc code
- code = exp.'root_pir'(adverbs :flat :named)
- if target != 'PIR' goto bytecode
- .return (code)
-
- bytecode:
- $P0 = compreg 'PIR'
- $P1 = $P0(code)
- .return ($P1)
+ .return exp.'compile'(adverbs :flat :named)
.end
-.namespace [ "PGE::Grammar" ]
-
.sub "p5regex"
.param pmc mob
.local pmc optable
@@ -70,8 +57,6 @@
.const int PGE_INF = 2147483647
-.namespace [ "PGE::P5Regex" ]
-
.sub "__onload" :load
.local pmc optable
View
31 compilers/pge/PGE/P6Regex.pir
@@ -76,6 +76,7 @@ or the resulting PIR code (target='PIR').
.local string target
target = adverbs['target']
+ target = downcase target
## If we're passed the results of a previous parse, use it.
.local pmc match, exp
@@ -110,35 +111,9 @@ or the resulting PIR code (target='PIR').
pad = clone adverbs
$P0 = new .Hash
pad['lexscope'] = $P0
- exp = exp.p6exp(pad)
- if target != 'exp' goto pir
- .return (exp)
-
- pir:
- .local pmc code
- .local string grammar
- .local string nsformat
- grammar = adverbs['grammar']
- nsformat = ".namespace"
- if grammar == '' goto pir_emit
- nsformat = ".namespace [ '%0' ]"
- pir_emit:
- code = new 'PGE::CodeString'
- code.emit(nsformat, grammar)
- $P0 = exp.root_pir(adverbs :flat :named)
- code .= $P0
- if target != 'PIR' goto bytecode
- .return (code)
+ exp = exp.'p6exp'(pad)
- bytecode:
- $P0 = compreg 'PIR'
- $P1 = $P0(code)
- make_grammar:
- $I0 = find_type grammar
- if $I0 > 0 goto end
- $P0 = subclass 'PGE::Grammar', grammar
- end:
- .return ($P1)
+ .return exp.'compile'(adverbs :flat :named)
.end
Please sign in to comment.
Something went wrong with that request. Please try again.