Skip to content
Browse files

[perl6]

* The parser now compiles!  
* C< print "hello world\n" > works
* C< print 1; > works
* C< print 3+4*5; > works
* C< print (3+4)*5, " ", 60/4, "\n"; > works
* C< say "hello world" > works
* We need a new test harness.
* Added --target=PIR  option.



git-svn-id: http://svn.perl.org/parrot/trunk/languages/perl6@12204 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 0d1a5ba commit bcd1fc07da7ce0f2cf008219772b750bcb9efce6 @pmichaud pmichaud committed Apr 13, 2006
Showing with 654 additions and 70 deletions.
  1. +45 −22 README
  2. +22 −12 STATUS
  3. +210 −0 lib/PAST.pir
  4. +30 −0 lib/builtins.pir
  5. +2 −1 lib/{grammar.g → grammar.pge}
  6. +2 −1 lib/main.pir
  7. +18 −11 lib/parse.pir
  8. +132 −0 lib/past2pir.tge
  9. +166 −0 lib/pge2past.tge
  10. +27 −23 perl6.pir
View
67 README
@@ -1,21 +1,15 @@
=head1 Perl 6 parser
-This is a Perl 6 parser, an early version (no version numbers yet).
-
-I know you're probably looking for the Perl 6 compiler, but this
-isn't it, at least not yet. Eventually it probably will be, but
-for the moment it's just the parser. As we finish up TGE
-(compilers/tge) and code generation, then this will probably
-be the Perl 6 compiler.
-
-(If you're in a hurry to write Perl 6 programs, you might try
-looking at PUGS -- http://www.pugscode.org. Or, help us build
-the compiler here -- read on!)
+This is a Perl 6 parser/compiler, an early version (no version numbers
+yet). It's still very early, only simple expressions and functions are
+available. If you're in a hurry to write "real Perl 6" programs,
+you might try looking at PUGS -- http://www.pugscode.org. Or, you
+can send patches and contributions to the one being built here!
However, even though this is not a complete compiler yet, you can
still see how Perl 6 programs are parsed, help us create test
-cases, and extend/improve the grammar to cover more of Perl 6.
-Here's how to do it:
+cases, and extend/improve the grammar and runtime to cover more
+of Perl 6. Here's how the system currently works:
=head2 Compiling
@@ -29,12 +23,16 @@ input file named "foo.p6", use:
$ parrot perl6.pbc foo.p6
-To run interactively, entering single-line statements
-and displaying the parse tree for each:
+To run interactively, entering single-line statements:
$ parrot perl6.pbc
-At the moment perl6.pbc only displays the parse tree.
+To display the parse tree, add the "--target=parse" option:
+
+ $ parrot perl6.pbc --target=parse foo.p6
+
+Or, to display the abstract syntax tree or the generated PIR
+code, use "--target=PAST" or "--target=PIR".
To get a dump of the parser's operator precedence table,
use --dump-optable:
@@ -63,19 +61,44 @@ parsing Perl 6 that are better written directly in PIR instead
of using the top-down rules syntax or bottom-up operator
precedence parser.
+The F<lib/pge2past.tge> is a tree grammar that specifies how to
+convert the parse tree into the abstract syntax tree (PAST), and
+F<lib/past2pir.tge> generates PIR from PAST. These are both
+held together by the F<lib/PAST.pir> file which defines the
+Perl6::PAST node structures and other support features.
+(See also "What about POST?" below.)
+
The F<lib/main.pir> file controls what happens when the perl6.pbc
file is invoked directly from parrot (as opposed to being
loaded via the load_bytecode op).
The PIR files in F<lib/> are included as part of compiling
-F<perl6.pir> to produce F<perl6.pbc>. One can then parse Perl 6
-source by doing:
+F<perl6.pir> to produce F<perl6.pbc>.
+
+The F<perl6.pbc> file can also be used to compile Perl 6 code
+from PIR:
+
+ load_bytecode "perl6.pbc"
+ $S0 = 'say "hello world"' # source code to compile
+ $P0 = compreg("Perl6") # obtain the compiler
+ $P1 = $P0($S0) # compile source code
+ $P1() # execute
+
+One can also provide the "target" option to the compiler:
+
+ $P1 = $P0($S0, 'target'=>'parse') # obtain parse tree
+ $P1 = $P0($S0, 'target'=>'PAST') # get AST
+ $P1 = $P0($S0, 'target'=>'PIR') # get PIR
- $P0 = compreg "Perl6"
- $S0 = "...perl 6 source code..."
- $P1 = $P0($S0, target=>'parse')
- # $P1 holds the parse tree of the Perl 6 source code
+"What about POST?"
+The Perl 6 "Milestones" document says that translation will actually
+go from a parse tree to an abstract syntax tree (PAST), then from
+PAST to an opcode syntax tree (POST), and then to executable code.
+This is still the ultimate plan. However, to keep things slightly
+simpler initially, this version of the compiler simply goes straight
+from PAST to PIR until the division of labor between the two
+systems is a bit more well-defined and understood.
=head1 AUTHOR
View
34 STATUS
@@ -1,34 +1,44 @@
-This is a laundry list of things completed
-and items on the "to do" list for the Perl 6
-parser (and eventually the compiler).
+This is a laundry list of things completed and items on
+the "to do" list:
>> The MOST IMPORTANT to-do item at the moment is <<
->> we need a testing framework of some sort for <<
->> the parser, so that we know when things break. <<
-
+>> we need a testing framework. Setting up test <<
+>> frameworks isn't Patrick's forte, so hopefully <<
+>> someone else can start setting one up. <<
+
+Compiler implemented
+--------------------
+* Very basic expressions and operators
+* Listop parsing and execution
+* Simplified quoted strings
+
+Compiler to-do
+--------------
+* if, unless
+* infix:and, infix:or, infix:&&, infix:||, ternary:?? !!
+* blocks
+* subs
+* variables
Parser implemented
------------------
-* Basic expressions and operators
* Common if, while statements
* Basic blocks
* Perl 6 comments (excluding POD)
-* Listop parsing
-* List associative parsing
-
+* List associative operators
Parser to-do
------------
* POD comments
+* Long dot comments
* statement modifier operators
* real pointy subs
* subroutine definitions
* subroutine calling syntax
* variables
-* real quoted-string terms
* "use" statement
* statement labels
-
+* real quoted strings
Small patches are preferred over large ones. Send
patches to the <perl6-compiler@perl.org> mailing list.
View
210 lib/PAST.pir
@@ -0,0 +1,210 @@
+=head1 NAME
+
+Perl6::PAST - Abstract syntax tree nodes for Perl6
+
+=head1 DESCRIPTION
+
+This file implements the various abstract syntax tree nodes
+needed for Perl 6. The currently defined ast nodes:
+
+ Perl6::PAST::Node - base class for all ast nodes
+ Perl6::PAST::Stmts - a block of statements
+ Perl6::PAST::Stmt - a single statement
+ Perl6::PAST::Op - an operation
+ Perl6::PAST::Val - a constant value
+ Perl6::PAST::Var - a variable
+ Perl6::PAST::Vector - a vector of values
+ Perl6::PAST::Assign - an assignment operation
+
+The C<Perl6::PAST::Node> class itself is derived from C<Hash>, so
+that it's easy to store and retrieve attributes from each
+node object.
+
+This file also defines (by inclusion) C<Perl6::PAST::Grammar>,
+which converts a Match object into an abstract syntax tree.
+
+=head1 PAST functions
+
+=over 4
+
+=item C<__onload()>
+
+Creates the C<Perl6::PAST::*> classes.
+
+=cut
+
+.namespace [ 'Perl6::PAST' ]
+
+.sub '__onload' :load
+ .local pmc base
+ $P0 = getclass 'Hash'
+ base = subclass $P0, 'Perl6::PAST::Node'
+ addattribute base, '$.source' # original source
+ addattribute base, '$.pos' # offset position
+
+ $P0 = subclass base, 'Perl6::PAST::Stmts'
+ $P0 = subclass base, 'Perl6::PAST::Stmt'
+ $P0 = subclass base, 'Perl6::PAST::Exp'
+ $P0 = subclass base, 'Perl6::PAST::Op'
+ $P0 = subclass base, 'Perl6::PAST::Val'
+ $P0 = subclass base, 'Perl6::PAST::Var'
+
+ base = getclass 'TGE'
+ $P0 = subclass base, 'Perl6::PAST::Grammar'
+ $P0 = subclass base, 'Perl6::PIR::Grammar'
+
+ $P0 = new .Integer
+ store_global "Perl6::PAST", "$!serno", $P0
+.end
+
+.namespace [ 'Perl6::PAST::Node' ]
+
+=back
+
+=head2 Perl6::PAST::Node methods
+
+=over 4
+
+=item C<__init()>
+
+Initializes a new C<Perl6::PAST::Node> object.
+
+=cut
+
+.sub __init :method
+ $P0 = new .String
+ $P1 = new .Integer
+
+ setattribute self, "Perl6::PAST::Node\x0$.source", $P0
+ setattribute self, "Perl6::PAST::Node\x0$.pos", $P1
+ .return ()
+.end
+
+
+=item C<set_node(PMC match)>
+
+Initializes the current ast node with the source code
+information from a match object (presumably a component
+of the parse tree).
+
+=cut
+
+.sub 'set_node' :method
+ .param pmc match # match object of source
+ $P0 = getattribute self, "Perl6::PAST::Node\x0$.source"
+ $S0 = match
+ $P0 = $S0
+ $P1 = getattribute self, "Perl6::PAST::Node\x0$.pos"
+ $I1 = match.from()
+ $P1 = $I1
+ .return ()
+.end
+
+
+=item C<source()>
+
+Return the source code associated with the current node.
+
+=cut
+
+.sub 'source' :method
+ $P0 = getattribute self, "Perl6::PAST::Node\x0$.source"
+ .return ($P0)
+.end
+
+
+=item C<pos()>
+
+Return the source code offset associated with this
+node.
+
+=cut
+
+.sub 'pos' :method
+ $P0 = getattribute self, "Perl6::PAST::Node\x0$.pos"
+ .return ($P0)
+.end
+
+
+=item C<generate_unique(STR prefix)>
+
+Generate a unique string that begins with C<prefix>.
+
+=cut
+
+.sub "generate_unique" :method
+ .param string prefix
+ $P0 = find_global "Perl6::PAST", "$!serno"
+ $S0 = $P0
+ $S0 = concat prefix, $S0
+ inc $P0
+ .return ($S0)
+.end
+
+
+=item C<__dump(PMC dumper, STR label)>
+
+Display the contents of the current node in a form compatible
+with C<Data::Dumper>.
+
+=cut
+
+.sub '__dump' :method
+ .param pmc dumper
+ .param string label
+ .local string indent, subindent
+ .local pmc iter, val
+ .local string key
+ .local pmc hash
+ .local int hascapts
+
+ (subindent, indent) = dumper.'newIndent'()
+ print '=> '
+ $S0 = self.source()
+ dumper.'genericString'('', $S0)
+ $I0 = self.pos()
+ print ' @ '
+ print $I0
+ hascapts = 0
+ iter = new .Iterator, self
+ iter = 0
+ dump_hash_1:
+ unless iter goto dump_end
+ if hascapts goto dump_hash_2
+ print ' {'
+ hascapts = 1
+ dump_hash_2:
+ print "\n"
+ print subindent
+ key = shift iter
+ val = iter[key]
+ print '<'
+ print key
+ print '> => '
+ dumper.'dump'(label, val)
+ goto dump_hash_1
+ dump_end:
+ unless hascapts goto end
+ print "\n"
+ print indent
+ print '}'
+ end:
+ dumper.'deleteIndent'()
+.end
+
+.namespace [ 'Perl6::PAST::Grammar' ]
+.include 'lib/pge2past.pir'
+
+.namespace [ 'Perl6::PIR::Grammar' ]
+.include 'lib/past2pir.pir'
+
+=back
+
+=head1 LICENSE
+
+Copyright (c) 2005-2006 The Perl Foundation
+
+This is free software; you may redistribute it and/or modify
+it under the same terms as Parrot.
+
+=cut
View
30 lib/builtins.pir
@@ -0,0 +1,30 @@
+.namespace [ "" ]
+
+.sub 'print'
+ .param pmc list :slurpy
+ .local pmc iter
+
+ iter = new .Iterator, list
+ iter = 0
+ iter_loop:
+ unless iter goto iter_end
+ $P0 = shift iter
+ print $P0
+ goto iter_loop
+ iter_end:
+ .return ()
+.end
+
+
+.sub 'say'
+ .param pmc list :slurpy
+ 'print'(list :flat)
+ print "\n"
+ .return ()
+.end
+
+
+.sub 'list'
+ .param pmc list :slurpy
+ .return (list)
+.end
View
3 lib/grammar.g → lib/grammar.pge
@@ -90,7 +90,7 @@ rule term {
| <block>
| <number>
| <integer>
- | <PGE::Text::bracketed: '">
+ | <string_literal>
}
@@ -109,6 +109,7 @@ rule reserved_word { [ if | unless | while | until | for | loop ] \b }
rule sigil { <[$@%^]> }
rule integer { \d+ }
rule number { \d+ \. \d+ }
+rule string_literal { <PGE::Text::bracketed: '"> }
## The <syntax_error> rule generates a simple syntax
View
3 lib/main.pir
@@ -31,6 +31,8 @@ executing program statements.
$P0()
$P0 = find_global 'Perl6::Grammar', '__onload_parse'
$P0()
+ $P0 = find_global 'Perl6::PAST', '__onload'
+ $P0()
load_bytecode 'dumper.pbc'
load_bytecode 'PGE/Dumper.pbc'
@@ -86,7 +88,6 @@ executing program statements.
$P0 = perl6(stmt, 'target' => target)
if target == 'PIR' goto dump_pir
if target goto dump_object
- goto dump_object
$P0()
ret
dump_pir:
View
29 lib/parse.pir
@@ -26,7 +26,7 @@ and initializes it with the operators defined by Perl 6.
=cut
.sub "__onload_parse" :load
- .local pmc optable
+ .local pmc optable, op
$I0 = find_type "PGE::OPTable"
optable = new $I0
store_global "Perl6::Grammar", "$optable", optable
@@ -36,8 +36,10 @@ and initializes it with the operators defined by Perl 6.
# terms
$P0 = find_global "Perl6::Grammar", "term"
- optable.addtok("term:", "22=", "left", $P0)
- optable.addtok("circumfix:( )", "term:")
+ op = optable.addtok("term:", "22=", "left", $P0)
+ op['pastrule'] = 'past_term'
+ op = optable.addtok("circumfix:( )", "term:")
+ op['pircode'] = ' # circumfix:( )'
# method postfix
optable.addtok("postfix:.", "21=")
@@ -65,16 +67,19 @@ and initializes it with the operators defined by Perl 6.
optable.addtok("prefix:**", "prefix:!")
# multiplicative
- optable.addtok("infix:*", "17=")
- optable.addtok("infix:/", "infix:*")
+ op = optable.addtok("infix:*", "17=")
+ op['pircode'] = ' %r = %0 * %1'
+ op = optable.addtok("infix:/", "infix:*")
+ op['pircode'] = ' %r = %0 / %1'
optable.addtok("infix:%", "infix:*")
optable.addtok("infix:x", "infix:*")
optable.addtok("infix:xx", "infix:*")
optable.addtok("infix:+&", "infix:*")
optable.addtok("infix:+<", "infix:*")
# additive
- optable.addtok("infix:+", "16=")
+ op = optable.addtok("infix:+", "16=")
+ op['pircode'] = ' %r = %0 + %1'
optable.addtok("infix:-", "infix:+")
# named unary
@@ -98,7 +103,7 @@ and initializes it with the operators defined by Perl 6.
optable.addtok("infix:>", "infix:==")
# tight and
- optable.addtok("infix:&&", "10=")
+ op = optable.addtok("infix:&&", "10=")
# tight or
optable.addtok("infix:||", "09=")
@@ -114,26 +119,28 @@ and initializes it with the operators defined by Perl 6.
optable.addtok("infix:::=", "infix:=", "right")
# list item separator
- optable.addtok("infix:,", "06=", "list,nullterm")
+ op = optable.addtok("infix:,", "06=", "list,nullterm")
+ op['subname'] = 'list'
# list op
optable.addtok("infix:<==", "05=", "right")
$P0 = find_global "Perl6::Grammar", "listop"
- optable.addtok("prelist:", "infix:<==", "right,nullterm", $P0)
+ op = optable.addtok("prelist:", "infix:<==", "right,nullterm", $P0)
# pipe forward
optable.addtok("infix:==>", "04=")
# loose and
- optable.addtok("infix:and", "03=")
+ op = optable.addtok("infix:and", "03=")
# loose or
optable.addtok("infix:or", "02=")
optable.addtok("infix:xor", "infix:or")
optable.addtok("infix:err", "infix:or")
# expr terminator
- optable.addtok("infix:;", "01=", "nullterm")
+ op = optable.addtok("infix:;", "01=", "nullterm")
+ op['pircode'] = " #"
.end
View
132 lib/past2pir.tge
@@ -0,0 +1,132 @@
+Perl6::PAST::Stmts: pir(.) = {
+ .local pmc pir
+ pir = new 'PGE::CodeString'
+ pir.emit(".sub 'anon' :anon")
+ $P0 = node['children']
+ unless $P0 goto end
+
+ .local pmc iter
+ iter = new .Iterator, $P0
+ iter = 0
+ iter_loop:
+ unless iter goto iter_end
+ $P0 = shift iter
+ $P1 = tree.'get'('pir', $P0)
+ pir .= $P1
+ goto iter_loop
+ iter_end:
+ $P2 = $P0['ret']
+ node['ret'] = $P2
+ end:
+ pir.emit(".end")
+ .return (pir)
+}
+
+
+Perl6::PAST::Stmt: pir(.) = {
+ $P0 = node['statement']
+ $P1 = tree.'get'('pir', $P0)
+ $P2 = $P0['ret']
+ node['ret'] = $P2
+ .return ($P1)
+}
+
+
+Perl6::PAST::Exp: pir(.) = {
+ $P0 = node['expression']
+ $P1 = tree.'get'('pir', $P0)
+ $P2 = $P0['ret']
+ node['ret'] = $P2
+ .return ($P1)
+}
+
+
+Perl6::PAST::Op: pir(.) = {
+ .local pmc pir
+ pir = new 'PGE::CodeString'
+
+ .local pmc op, optable
+ optable = find_global "Perl6::Grammar", "$optable"
+ $S0 = node['op']
+ op = optable[$S0]
+
+ .local pmc childret
+ childret = new .ResizablePMCArray
+ $P0 = node['children']
+ unless $P0 goto end
+ if $S0 != 'prelist:' goto childops
+ $P1 = $P0[0]
+ $S0 = $P1['op']
+ if $S0 != 'infix:,' goto childops
+ $P0 = $P1['children']
+ unless $P0 goto end
+
+ childops:
+ .local pmc iter
+ iter = new .Iterator, $P0
+ iter = 0
+ iter_loop:
+ unless iter goto iter_end
+ $P0 = shift iter
+ $P1 = tree.'get'('pir', $P0)
+ pir .= $P1
+ $P2 = $P0['ret']
+ push childret, $P2
+ goto iter_loop
+ iter_end:
+ end:
+ .local string ret, fmt
+ ret = childret[0]
+ $S0 = node['subname']
+ fmt = op['pircode']
+ if fmt goto emit_pir
+ ret = pir.unique('$P')
+ fmt = " %r = '%f'(%,)"
+ emit_pir:
+ node['ret'] = ret
+ pir.emit(fmt, childret :flat, 'r'=>ret, 'f'=>$S0)
+ .return (pir)
+}
+
+
+Perl6::PAST::Val: pir(.) = {
+ .local pmc pir
+ .local string ret
+ .local string value
+ pir = new "PGE::CodeString"
+ ret = pir.unique('$P')
+ pir.emit(' %r = new .Undef', 0, 'r' => ret)
+ value = node['value']
+ $S0 = node['returns']
+ if $S0 == 'int' goto emit_pir
+
+ string:
+ $S1 = substr value, 0, 1
+ value = substr value, 1
+ chopn value, 1
+ value = escape value
+ if $S1 != '"' goto slash_end
+ # remove any '\\' sequences for double-quoted strings
+ $I0 = 0
+ slash_loop:
+ $I0 = index value, "\\\\", $I0
+ if $I0 < 0 goto slash_end
+ substr value, $I0, 2, "\\"
+ goto slash_loop
+ slash_end:
+ # add quotes for pir
+ value = concat '"', value
+ value = concat value, '"'
+ $I0 = index value, "\\x"
+ if $I0 >= 0 goto unicode
+ $I0 = index value, "\\u"
+ if $I0 >= 0 goto unicode
+ goto emit_pir
+ unicode:
+ value = concat 'unicode:', value
+
+ emit_pir:
+ pir.emit(' assign %r, %0', value, 'r' => ret)
+ node['ret'] = ret
+ .return (pir)
+}
View
166 lib/pge2past.tge
@@ -0,0 +1,166 @@
+ROOT: past(.) = {
+ $P0 = node['statement_list']
+ .return tree.'get'('past', $P0, 'Perl6::Grammar::statement_list')
+}
+
+
+Perl6::Grammar::statement_list: past(.) = {
+ .local pmc past
+ .local pmc children
+ .local pmc iter
+
+ past = new 'Perl6::PAST::Stmts'
+ past.'set_node'(node)
+
+ children = new .ResizablePMCArray
+ $P0 = node['statement']
+ iter = new .Iterator, $P0
+ iter = 0
+ iter_loop:
+ unless iter goto iter_end
+ $P1 = shift iter
+ $P2 = tree.'get'('past', $P1, 'Perl6::Grammar::statement')
+ if null $P2 goto iter_loop
+ push children, $P2
+ goto iter_loop
+ iter_end:
+ past['children'] = children
+ .return (past)
+}
+
+
+Perl6::Grammar::statement: past(.) = {
+ .local pmc past
+ past = new 'Perl6::PAST::Stmt'
+ past.'set_node'(node)
+
+ $P0 = node['expression']
+ if $P0 goto expression
+ goto end
+
+ expression:
+ $P1 = tree.'get'('past', $P0, 'Perl6::Grammar::expression')
+ past['statement'] = $P1
+
+ end:
+ .return (past)
+}
+
+
+Perl6::Grammar::expression: past(.) = {
+ .local pmc past
+
+ past = new 'Perl6::PAST::Exp'
+ past.set_node(node)
+
+ $P0 = node['opparse']
+ $P0 = $P0['expr']
+ $P1 = tree.'get'('past', $P0, 'Perl6::Grammar::expr')
+ past['expression'] = $P1
+ .return (past)
+}
+
+
+Perl6::Grammar::expr: past(.) = {
+ .local string type
+ .local pmc optable
+ .local pmc op
+ type = node['type']
+ if type != "" goto pastrule
+ null $P0
+ .return ($P0)
+
+ pastrule:
+ optable = find_global "Perl6::Grammar", "$optable"
+ op = optable[type]
+ $S0 = op['pastrule']
+ unless $S0 goto op_standard
+ .return tree.'get'($S0, node, 'Perl6::Grammar::expr')
+
+ op_standard:
+ .local pmc past, children, iter
+ past = new 'Perl6::PAST::Op'
+ past.set_node(node)
+ children = new .ResizablePMCArray
+ $P0 = node.'get_array'()
+ if null $P0 goto iter_end
+ iter = new .Iterator, $P0
+ iter = 0
+ iter_loop:
+ unless iter goto iter_end
+ $P0 = shift iter
+ $S0 = $P0
+ if $S0 == "" goto iter_loop
+ $P1 = tree.'get'('past', $P0, 'Perl6::Grammar::expr')
+ if null $P1 goto iter_loop
+ push children, $P1
+ goto iter_loop
+ iter_end:
+ past['children'] = children
+ past['op'] = type
+ subname:
+ $I0 = exists op['subname']
+ if $I0 goto subname_op
+ $I0 = exists node['ident']
+ if $I0 goto subname_ident
+ past['subname'] = type
+ goto end
+ subname_op:
+ $S0 = op['subname']
+ past['subname'] = $S0
+ goto end
+ subname_ident:
+ $S0 = node['ident']
+ past['subname'] = $S0
+ end:
+ .return (past)
+}
+
+
+Perl6::Grammar::expr: past_term(.) = {
+ .local pmc iter
+ $P0 = node.'get_hash'()
+ iter = new .Iterator, $P0
+ iter = 0
+ iter_loop:
+ unless iter goto term_error
+ $S0 = shift iter
+ $P0 = iter[$S0]
+ $S1 = concat 'Perl6::Grammar::', $S0
+ $P1 = tree.'get'('past', $P0, $S1)
+ if null $P1 goto iter_loop
+ .return ($P1)
+
+ term_error:
+ print "error: 'term' node has incorrect structure.\n"
+ end
+}
+
+
+Perl6::Grammar::type: past(.) = {
+ null $P0
+ .return ($P0)
+}
+
+
+Perl6::Grammar::integer: past(.) = {
+ .local pmc past
+ past = new 'Perl6::PAST::Val'
+ past.set_node(node)
+ past['returns'] = 'int'
+ $I0 = node
+ past['value'] = $I0
+ .return (past)
+}
+
+
+Perl6::Grammar::string_literal: past(.) = {
+ .local pmc past
+ past = new 'Perl6::PAST::Val'
+ past.set_node(node)
+ past['returns'] = 'str'
+ $S0 = node
+ past['value'] = $S0
+ .return (past)
+}
+
View
50 perl6.pir
@@ -18,12 +18,14 @@ But that should change soon.
=cut
-.include "lib/parse.pir"
+.include 'lib/parse.pir'
-.namespace [ "Perl6::Grammar" ]
-.include "lib/grammar.pir"
+.namespace [ 'Perl6::Grammar' ]
+.include 'lib/grammar.pir'
-.namespace [ "Perl6" ]
+.include 'lib/PAST.pir'
+
+.namespace [ 'Perl6' ]
=head2 Functions
@@ -38,23 +40,24 @@ compiler.
=cut
-.sub "__onload" :load
- load_bytecode "PGE.pbc"
- load_bytecode "PGE/Text.pir"
+.sub '__onload' :load
+ load_bytecode 'PGE.pbc'
+ load_bytecode 'PGE/Text.pir'
+ load_bytecode 'TGE.pbc'
- $I0 = find_type "Perl6::Grammar"
+ $I0 = find_type 'Perl6::Grammar'
if $I0 != 0 goto onload_1
- load_bytecode "PGE.pbc"
- $P0 = getclass "PGE::Rule"
- $P0 = subclass $P0, "Perl6::Grammar"
+ load_bytecode 'PGE.pbc'
+ $P0 = getclass 'PGE::Rule'
+ $P0 = subclass $P0, 'Perl6::Grammar'
onload_1:
- $P0 = compreg "PGE::P6Rule"
- $P1 = $P0("^<Perl6::Grammar::program>")
- store_global "Perl6", "&parse", $P1
+ $P0 = compreg 'PGE::P6Rule'
+ $P1 = $P0('^<Perl6::Grammar::program>')
+ store_global 'Perl6', '&parse', $P1
- $P0 = find_global "Perl6", "compile"
- compreg "Perl6", $P0
+ $P0 = find_global 'Perl6', 'compile'
+ compreg 'Perl6', $P0
.end
@@ -85,26 +88,25 @@ compiled code as a PMC.
unless match goto return_match
if target == 'parse' goto return_match
- goto return_match
build_ast:
- match = match['Perl::Grammar::statement_list']
+ match = match['Perl6::Grammar::program']
.local pmc astgrammar, astbuilder, ast
- astgrammar = new 'ASTGrammar'
+ astgrammar = new 'Perl6::PAST::Grammar'
astbuilder = astgrammar.apply(match)
- ast = astbuilder.get('result')
+ ast = astbuilder.get('past')
if target == 'PAST' goto return_ast
build_pir:
.local pmc pirgrammar, pirbuilder
.local string pir
- pirgrammar = new 'PIRGrammar'
+ pirgrammar = new 'Perl6::PIR::Grammar'
pirbuilder = pirgrammar.'apply'(ast)
pir = pirbuilder.get('pir')
if target == 'PIR' goto return_pir
compile_pir:
- $P0 = compreg "PIR"
+ $P0 = compreg 'PIR'
$P1 = $P0(pir)
.return ($P1)
@@ -116,7 +118,9 @@ compiled code as a PMC.
.return (pir)
.end
-.include "lib/main.pir"
+.include 'lib/main.pir'
+
+.include 'lib/builtins.pir'
=back

0 comments on commit bcd1fc0

Please sign in to comment.
Something went wrong with that request. Please try again.