Author: allison
Date: Thu Apr 27 19:01:11 2006
New Revision: 12453
Added:
trunk/languages/punie/t/post_label.t
Modified:
trunk/ (props changed)
trunk/languages/punie/lib/Node.pir
trunk/languages/punie/lib/PAST/Op.pir
trunk/languages/punie/lib/PAST/Val.pir
trunk/languages/punie/lib/POST/Label.pir
trunk/languages/punie/lib/POST/Op.pir
trunk/languages/punie/lib/POST/Val.pir
trunk/languages/punie/lib/POST/Var.pir
trunk/languages/punie/lib/past2post.tg
trunk/languages/punie/lib/pge2past.tg
trunk/languages/punie/t/node.t
trunk/languages/punie/t/past.t
trunk/languages/punie/t/past_op.t
trunk/languages/punie/t/past_val.t
trunk/languages/punie/t/post.t
trunk/languages/punie/t/post_op.t
trunk/languages/punie/t/post_val.t
trunk/languages/punie/t/post_var.t
Log:
Punie: refactoring 'set_node' method out of all node types, refactoring
for new 'add_child' method in Node.
Modified: trunk/languages/punie/lib/Node.pir
==============================================================================
--- trunk/languages/punie/lib/Node.pir (original)
+++ trunk/languages/punie/lib/Node.pir Thu Apr 27 19:01:11 2006
@@ -30,24 +30,36 @@
setattribute self, "children", $P3
.end
-.sub "set_node" :method
- .param string source
- .param int pos
- .param pmc children
- $P1 = getattribute self, "source"
- $P1 = source
- $P2 = getattribute self, "pos"
- $P2 = pos
- setattribute self, "children", children
- .return ()
+.sub '__elements' :method
+ $P1 = getattribute self, 'children'
+ $I1 = elements $P1
+ .return ($I1)
.end
.sub source :method
+ .param string source :optional
+ .param int got_source :opt_flag
+ unless got_source goto get
+ set:
+ $P1 = new .String
+ $P1 = source
+ setattribute self, "source", $P1
+ .return ($P1)
+ get:
$P2 = getattribute self, "source"
.return ($P2)
.end
.sub pos :method
+ .param int pos :optional
+ .param int got_pos :opt_flag
+ unless got_pos goto get
+ set:
+ $P1 = new .Integer
+ $P1 = pos
+ setattribute self, "pos", $P1
+ .return ($P1)
+ get:
$P2 = getattribute self, "pos"
.return ($P2)
.end
@@ -57,6 +69,28 @@
.return ($P2)
.end
+# Get the source string and position offset from start of source
+# code for a PGE match node.
+.sub clone_pge :method
+ .param pmc node
+ $S1 = node
+ self."source"($S1)
+ $I1 = node.from()
+ self."pos"($I1)
+ .return ()
+.end
+
+# Get the source string and position offset from start of source
+# code for a tree node.
+.sub clone_node :method
+ .param pmc node
+ $S1 = node.'source'()
+ self.'source'($S1)
+ $I1 = node.'pos'()
+ self.'pos'($I1)
+ .return ()
+.end
+
.sub "dump" :method
.param int level :optional
.local string indent
@@ -130,3 +164,16 @@
print "]\n"
.return ()
.end
+
+.sub 'add_child' :method
+ .param pmc child
+ .local pmc children
+ children = getattribute self, 'children'
+ $I0 = defined children
+ if $I0 goto children_exist
+ children = new .ResizablePMCArray
+ setattribute self, "children", children
+ children_exist:
+ push children, child
+ .return()
+.end
Modified: trunk/languages/punie/lib/PAST/Op.pir
==============================================================================
--- trunk/languages/punie/lib/PAST/Op.pir (original)
+++ trunk/languages/punie/lib/PAST/Op.pir Thu Apr 27 19:01:11 2006
@@ -19,25 +19,6 @@
.return ()
.end
-.sub "set_node" :method
- .param string source
- .param int pos
- .param string op
- .param pmc children :optional
- .param int got_children :opt_flag
- $P1 = getattribute self, "source"
- $P1 = source
- $P2 = getattribute self, "pos"
- $P2 = pos
- $P3 = new .String
- $P3 = op
- setattribute self, "op", $P3
- unless got_children goto no_children
- setattribute self, "children", children
- no_children:
- .return ()
-.end
-
.sub "dump" :method
.param int level :optional
.local string indent
@@ -61,7 +42,16 @@
.return ()
.end
-.sub op :method
+.sub 'op' :method
+ .param string op :optional
+ .param int got_op :opt_flag
+ unless got_op goto get
+ set:
+ $P1 = new .String
+ $P1 = op
+ setattribute self, "op", $P1
+ .return ($P1)
+ get:
$P2 = getattribute self, "op"
.return ($P2)
.end
Modified: trunk/languages/punie/lib/PAST/Val.pir
==============================================================================
--- trunk/languages/punie/lib/PAST/Val.pir (original)
+++ trunk/languages/punie/lib/PAST/Val.pir Thu Apr 27 19:01:11 2006
@@ -19,20 +19,6 @@
.return ()
.end
-.sub "set_node" :method
- .param string source
- .param int pos
- .param string value
- $P1 = getattribute self, "source"
- $P1 = source
- $P2 = getattribute self, "pos"
- $P2 = pos
- $P3 = new .String
- $P3 = value
- setattribute self, "value", $P3
- .return ()
-.end
-
.sub "dump" :method
.param int level :optional
.local string indent
@@ -57,13 +43,23 @@
.end
.sub value :method
+ .param string value :optional
+ .param int got_value :opt_flag
+ unless got_value goto get
+ set:
+ $P1 = new .String
+ $P1 = value
+ setattribute self, "value", $P1
+ .return ($P1)
+ get:
$P2 = getattribute self, "value"
.return ($P2)
.end
.sub valtype :method
.param string valtype :optional
- unless valtype goto get
+ .param int got_valtype :opt_flag
+ unless got_valtype goto get
set:
$P1 = new .String
$P1 = valtype
Modified: trunk/languages/punie/lib/POST/Label.pir
==============================================================================
--- trunk/languages/punie/lib/POST/Label.pir (original)
+++ trunk/languages/punie/lib/POST/Label.pir Thu Apr 27 19:01:11 2006
@@ -22,25 +22,6 @@
.return ()
.end
-.sub "set_node" :method
- .param string source
- .param int pos
- .param string name :optional
- .param int got_name :opt_flag
- $P1 = getattribute self, "source"
- $P1 = source
- $P2 = getattribute self, "pos"
- $P2 = pos
-
- unless got_name goto no_name
- $P3 = new .String
- $P3 = name
- setattribute self, "name", $P3
- no_name:
- .return ()
-.end
-
-
.sub name :method
.param string name :optional
.param int got_name :opt_flag
Modified: trunk/languages/punie/lib/POST/Op.pir
==============================================================================
--- trunk/languages/punie/lib/POST/Op.pir (original)
+++ trunk/languages/punie/lib/POST/Op.pir Thu Apr 27 19:01:11 2006
@@ -19,25 +19,6 @@
.return ()
.end
-.sub "set_node" :method
- .param string source
- .param int pos
- .param string op
- .param pmc children :optional
- .param int got_children :opt_flag
- $P1 = getattribute self, "source"
- $P1 = source
- $P2 = getattribute self, "pos"
- $P2 = pos
- $P3 = new .String
- $P3 = op
- setattribute self, "op", $P3
- unless got_children goto no_children
- setattribute self, "children", children
- no_children:
- .return ()
-.end
-
.sub "dump" :method
.param int level :optional
.local string indent
@@ -61,7 +42,16 @@
.return ()
.end
-.sub op :method
+.sub 'op' :method
+ .param string op :optional
+ .param int got_op :opt_flag
+ unless got_op goto get
+ set:
+ $P1 = new .String
+ $P1 = op
+ setattribute self, "op", $P1
+ .return ($P1)
+ get:
$P2 = getattribute self, "op"
.return ($P2)
.end
Modified: trunk/languages/punie/lib/POST/Val.pir
==============================================================================
--- trunk/languages/punie/lib/POST/Val.pir (original)
+++ trunk/languages/punie/lib/POST/Val.pir Thu Apr 27 19:01:11 2006
@@ -19,20 +19,6 @@
.return ()
.end
-.sub "set_node" :method
- .param string source
- .param int pos
- .param string value
- $P1 = getattribute self, "source"
- $P1 = source
- $P2 = getattribute self, "pos"
- $P2 = pos
- $P3 = new .String
- $P3 = value
- setattribute self, "value", $P3
- .return ()
-.end
-
.sub "dump" :method
.param int level :optional
.local string indent
@@ -57,12 +43,21 @@
.end
.sub value :method
+ .param string value :optional
+ .param int got_value :opt_flag
+ unless got_value goto get
+ set:
+ $P1 = new .String
+ $P1 = value
+ setattribute self, "value", $P1
+ .return ($P1)
+ get:
$P2 = getattribute self, "value"
.return ($P2)
.end
.sub valtype :method
- .param string valtype :optional
+ .param string valtype :optional
.param int got_valtype :opt_flag
unless got_valtype goto get
set:
Modified: trunk/languages/punie/lib/POST/Var.pir
==============================================================================
--- trunk/languages/punie/lib/POST/Var.pir (original)
+++ trunk/languages/punie/lib/POST/Var.pir Thu Apr 27 19:01:11 2006
@@ -19,24 +19,6 @@
.return ()
.end
-.sub "set_node" :method
- .param string source
- .param int pos
- .param string varname :optional
- .param int got_varname :opt_flag
- $P1 = getattribute self, "source"
- $P1 = source
- $P2 = getattribute self, "pos"
- $P2 = pos
-
- unless got_varname goto no_varname
- $P3 = new .String
- $P3 = varname
- setattribute self, "varname", $P3
- no_varname:
- .return ()
-.end
-
.sub generate_temp :method
.local string temp
temp = "$P"
@@ -62,26 +44,23 @@
.end
.sub new_dummy :method
- .param string nodesource
- .param string nodepos
# First we create a temporary variable
- self.set_node(nodesource,nodepos)
self.new_temp()
- # Then we create a child array for a fabricated op to create a new
- # pmc of type 'Undef'. It has 2 arguments: the temp variable and
- # the type.
- $P5 = new .ResizablePMCArray
- push $P5, self
+ # Then we create a fabricated op to create a new pmc of type
+ # 'Undef'. It has 2 arguments: the temp variable and the type.
+ .local pmc newop
+ newop = new 'POST::Op'
+ newop.'clone_node'(self)
+ newop.'op'('new')
+
+ newop.'add_child'(self)
$I1 = find_type 'Undef'
$S10 = $I1
$P6 = new 'POST::Val'
- $P6.set_node(nodesource,nodepos,$S10)
- $P6.valtype('int')
- push $P5, $P6
- # Then we create the 'new' op.
- $P7 = new 'POST::Op'
- $P7.set_node(nodesource,nodepos,'new',$P5)
- .return ($P7)
+ $P6.'value'($S10)
+ $P6.'valtype'('int')
+ newop.'add_child'($P6)
+ .return (newop)
.end
.sub varname :method
Modified: trunk/languages/punie/lib/past2post.tg
==============================================================================
--- trunk/languages/punie/lib/past2post.tg (original)
+++ trunk/languages/punie/lib/past2post.tg Thu Apr 27 19:01:11 2006
@@ -1,6 +1,8 @@
ROOT: result(.) = {
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
+ .local pmc result
+ result = new 'POST::Sub'
+ result.'clone_node'(node)
+
$P1 = node.children()
.local pmc iter
iter = new Iterator, $P1 # setup iterator for node
@@ -9,19 +11,18 @@
unless iter, iter_end # while (entries) ...
shift $P2, iter
$P3 = tree.get('result', $P2)
- push newchildren, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- $S1 = node.source()
- $I1 = node.pos()
- $P4 = new 'POST::Sub'
- $P4.set_node($S1,$I1,newchildren)
- .return ($P4)
+
+ .return (result)
}
PAST::Stmts: result(.) = {
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
+ .local pmc result
+ result = new 'POST::Ops'
+ result.'clone_node'(node)
+
$P1 = node.children()
.local pmc iter
iter = new Iterator, $P1 # setup iterator for node
@@ -30,14 +31,10 @@
unless iter, iter_end # while (entries) ...
shift $P2, iter
$P3 = tree.get('result', $P2)
- push newchildren, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- $S1 = node.source()
- $I1 = node.pos()
- $P4 = new 'POST::Ops'
- $P4.set_node($S1,$I1,newchildren)
- .return ($P4)
+ .return (result)
}
PAST::Stmt: result(.) = {
@@ -86,10 +83,15 @@
not_nullop:
# Iterate through the children of the node, and generate the result
# for each child.
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
+ .local pmc childop
+ childop = new 'POST::Op'
+ childop.'clone_node'(node)
+ $S2 = node.op()
+ childop.op($S2)
+
+ # Create a node to contain the generated ops.
.local pmc newops
- newops = new .ResizablePMCArray
+ newops = new 'POST::Ops'
$P1 = node.children()
.local pmc iter
iter = new Iterator, $P1 # setup iterator for node
@@ -103,11 +105,11 @@
unless $S1 == 'POST::Ops' goto simple_result
$P1 = $P3.tmpvar()
if null $P1 goto simple_result
- push newchildren, $P1
- push newops, $P3
+ childop.'add_child'($P1)
+ newops.'add_child'($P3)
goto iter_loop
simple_result:
- push newchildren, $P3
+ childop.'add_child'($P3)
goto iter_loop
iter_end:
@@ -123,41 +125,45 @@
# newchildren = $P5.children()
no_munge:
- # The results for the children become the children of the new node.
- $S1 = node.source()
- $I1 = node.pos()
- $S2 = node.op()
- $P4 = new 'POST::Op'
- $P4.set_node($S1,$I1,$S2,newchildren)
-
+
# Check if we had setup code for one of the children. If so, bundle
# it up in an Ops node.
$I0 = elements newops
if $I0 > 0 goto bundle_ops
- .return ($P4)
+ .return (childop)
bundle_ops:
- push newops, $P4
+ newops.'add_child'(childop)
- # Create a node to contain the generated ops.
- $P5 = new 'POST::Ops'
- $P5.set_node($S1,$I1,newops)
- .return ($P5)
+ .return (newops)
}
PAST::Op: infix(.) = {
+ # Create the node to contain all the generated ops.
+ .local pmc newops
+ newops = new 'POST::Ops'
+ newops.'clone_node'(node)
+
+ # Create the op for the current node
+ .local pmc childop
+ childop = new 'POST::Op'
+
.local string opname
.local pmc oplookup
oplookup = find_global 'PunieOpLookup', 'lookup'
$S1 = node.op()
opname = oplookup($S1)
- .local string nodesource
- .local string nodepos
- nodesource = node.source()
- nodepos = node.pos()
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
- .local pmc newops
- newops = new .ResizablePMCArray
+ childop.'op'(opname)
+
+ # Create a temporary variable
+ .local pmc temp_var
+ temp_var = new 'POST::Var'
+ temp_var.'clone_node'(node)
+ $P8 = temp_var.new_dummy()
+ newops.'add_child'($P8)
+
+ # Add the temporary variable as the destination register of the op
+ childop.'add_child'(temp_var)
+
$P1 = node.children()
.local pmc iter
iter = new Iterator, $P1 # setup iterator for node
@@ -169,66 +175,52 @@
$S1 = typeof $P3
if $S1 == 'POST::Ops' goto complex_result # the argument has setup
if $S1 == 'POST::Val' goto create_tmp # the argument needs setup
- push newchildren, $P3
+ childop.'add_child'($P3)
goto iter_loop
create_tmp:
# Create a temp variable
$P4 = new 'POST::Var'
- $P5 = $P4.new_dummy(nodesource,nodepos)
- push newops, $P5
- push newchildren, $P4
+ $P4.'clone_node'(node)
+ $P5 = $P4.new_dummy()
+ newops.'add_child'($P5)
+ childop.'add_child'($P4)
# Assign the value node to the variable
- $P6 = new .ResizablePMCArray
- push $P6, $P4 # the first argument is the variable
- push $P6, $P3 # the second argument is the value
$P7 = new 'POST::Op'
- $P7.set_node(nodesource,nodepos,'set',$P6)
- push newops, $P7
+ $P7.'clone_node'(node)
+ $P7.'op'('set')
+ $P7.'add_child'($P4) # the first argument is the variable
+ $P7.'add_child'($P3) # the second argument is the value
+ newops.'add_child'($P7)
goto iter_loop
complex_result:
$P1 = $P3.tmpvar()
- push newchildren, $P1
- push newops, $P3
+ childop.'add_child'($P1)
+ newops.'add_child'($P3)
goto iter_loop
iter_end:
+ # The childop goes after all the setup code.
+ newops.'add_child'(childop)
+ newops.'tmpvar'(temp_var)
- # First we create a temporary variable
- .local pmc temp_var
- temp_var = new 'POST::Var'
- $P8 = temp_var.new_dummy(nodesource,nodepos)
- push newops, $P8
-
- # Add the temporary variable as the destination register of the op
- unshift newchildren, temp_var
- # Create the op for the current node
- $P9 = new 'POST::Op'
- $P9.set_node(nodesource,nodepos,opname,newchildren)
- push newops, $P9
-
- # Create the node to contain all the generated ops.
- $P10 = new 'POST::Ops'
- $P10.set_node(nodesource,nodepos,newops)
- $P10.tmpvar(temp_var)
-
- .return ($P10)
+ .return (newops)
}
PAST::Op: conditional(.) = {
+ # Create the node to contain all the generated ops.
+ .local pmc newops
+ newops = new 'POST::Ops'
+
.local string opname
.local pmc oplookup
oplookup = find_global 'PunieOpLookup', 'lookup'
$S1 = node.op()
opname = oplookup($S1)
- .local string nodesource
- .local string nodepos
- nodesource = node.source()
- nodepos = node.pos()
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
- .local pmc newops
- newops = new .ResizablePMCArray
+ .local pmc childop
+ childop = new 'POST::Op'
+ childop.'clone_node'(node)
+ childop.'op'(opname)
# Set up to handle children of Op node.
$P1 = node.children()
@@ -242,12 +234,12 @@
$P3 = tree.get('result', $P2)
$S1 = typeof $P3
if $S1 == 'POST::Ops' goto complex_result # the argument has setup
- push newchildren, $P3
+ childop.'add_child'($P3)
goto end_condition
complex_result:
$P1 = $P3.'tmpvar'()
- push newchildren, $P1
- push newops, $P3
+ childop.'add_child'($P1)
+ newops.'add_child'($P3)
end_condition:
# Second, create the branching op. The first child is the result of
@@ -255,48 +247,43 @@
.local pmc falselabel
falselabel = new 'POST::Label'
falselabel.'new_dummy'('false')
- push newchildren, falselabel
+ childop.'add_child'(falselabel)
- $P2 = new 'POST::Op'
- $P2.'set_node'(nodesource,nodepos,opname,newchildren)
- push newops, $P2
+ newops.'add_child'(childop)
# Next handle the conditional body
shift $P2, iter
$P3 = tree.'get'('result', $P2)
- push newops, $P3
+ newops.'add_child'($P3)
# When conditional body is selected, skip over any else/elsif
.local pmc endlabel
endlabel = new 'POST::Label'
endlabel.'new_dummy'('endcond')
$P4 = new 'POST::Op'
- $P5 = new .ResizablePMCArray
- push $P5, endlabel
- $P4.'set_node'(nodesource,nodepos,'goto',$P5)
- push newops, $P4
+ $P4.'clone_node'(node)
+ $P4.'op'('goto')
+ $P4.'add_child'(endlabel)
+ newops.'add_child'($P4)
# Destination for the branching op
$P6 = clone falselabel
$P6.dest(1)
- push newops, $P6
+ newops.'add_child'($P6)
# Finally handle the else/elsif block if it exists
unless iter goto no_else_elsif
shift $P2, iter
$P3 = tree.'get'('result', $P2)
- push newops, $P3
+ newops.'add_child'($P3)
no_else_elsif:
# Destination for the end of the conditional
$P6 = clone endlabel
$P6.dest(1)
- push newops, $P6
+ newops.'add_child'($P6)
- # Create the node to contain all the generated ops.
- $P10 = new 'POST::Ops'
- $P10.'set_node'(nodesource,nodepos,newops)
- .return ($P10)
+ .return (newops)
}
PAST::Op: nullop(.) = {
@@ -307,18 +294,11 @@
}
PAST::Op: print_op(.) = {
- .local string opname
- opname = node.op()
- .local string nodesource
- .local string nodepos
- nodesource = node.source()
- nodepos = node.pos()
-
# This fairly lengthy bit collapses comma ops, by traversing down
# the tree and yanking up the children of the comma op to the
# current level.
$P1 = node.children()
- $I0 = elements $P1
+ $I0 = elements node
if $I0 > 1 goto no_munge
$P2 = $P1[0]
$S3 = typeof $P2
@@ -333,12 +313,17 @@
no_munge:
# Done collapsing comma ops
+ # Create a node to contain the generated ops.
+ .local pmc newops
+ newops = new 'POST::Ops'
+ newops.'clone_node'(node)
+
+ # Store the opname for later reuse
+ .local string opname
+ opname = node.op()
+
# Iterate through the children of the node, and generate the result
# for each child.
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
- .local pmc newops
- newops = new .ResizablePMCArray
.local pmc iter
iter = new Iterator, $P1 # setup iterator for node
iter = 0
@@ -347,15 +332,15 @@
shift $P2, iter
$P3 = tree.get('result', $P2)
$S1 = typeof $P3
- $P4 = new .ResizablePMCArray
$P5 = new 'POST::Op'
+ $P5.'clone_node'(node)
+ $P5.'op'(opname)
$S1 = typeof $P3
if $S1 == 'POST::Ops' goto complex_result # the argument has setup
# The default case, create a new 'print' op node with the child
# as an argument and push it on the list of new ops.
- push $P4, $P3
- $P5.set_node(nodesource,nodepos,opname,$P4)
- push newops, $P5
+ $P5.'add_child'($P3)
+ newops.'add_child'($P5)
goto iter_loop
complex_result:
# The complex case, retrieve the temp variable from the Ops
@@ -363,26 +348,22 @@
# create a new 'print' op node with the temp variable as an
# argument and push it on the list of new ops.
$P1 = $P3.tmpvar()
- push newops, $P3
- push $P4, $P1
- $P5.set_node(nodesource,nodepos,opname,$P4)
- push newops, $P5
+ newops.'add_child'($P3)
+ $P5.'add_child'($P1)
+ newops.'add_child'($P5)
goto iter_loop
iter_end:
- # Create a node to contain the generated ops.
- $P5 = new 'POST::Ops'
- $P5.set_node(nodesource,nodepos,newops)
- .return ($P5)
+ .return (newops)
}
PAST::Val: result(.) = {
- $S1 = node.source()
- $I1 = node.pos()
- $P1 = node.value()
- $P3 = node.valtype()
- $P2 = new 'POST::Val'
- $P2.set_node($S1,$I1,$P1)
- $P2.valtype($P3)
- .return ($P2)
+ .local pmc result
+ result = new 'POST::Val'
+ result.'clone_node'(node)
+ $P1 = node.'value'()
+ result.'value'($P1)
+ $P2 = node.'valtype'()
+ result.'valtype'($P2)
+ .return (result)
}
Modified: trunk/languages/punie/lib/pge2past.tg
==============================================================================
--- trunk/languages/punie/lib/pge2past.tg (original)
+++ trunk/languages/punie/lib/pge2past.tg Thu Apr 27 19:01:11 2006
@@ -29,8 +29,10 @@
}
PunieGrammar::lineseq: result(.) = {
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
+ .local pmc result
+ result = new 'PAST::Stmts'
+ result.'clone_pge'(node)
+
# Ask the child node for its result
.local pmc child
$I0 = defined node["PunieGrammar::line"]
@@ -44,25 +46,20 @@
unless iter, iter_end # while (entries) ...
shift $P2, iter
$P3 = tree.get('result', $P2, 'PunieGrammar::line')
- push newchildren, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- # get the source string and position offset from start of source
- # code for this match node
- $S1 = node
- $I1 = node.from()
- $P4 = new 'PAST::Stmts'
- $P4.set_node($S1,$I1,newchildren)
- .return ($P4)
+ .return (result)
err_no_tree:
print "The 'lineseq' node doesn't contain a 'line' match.\n"
end
}
PunieGrammar::line: result(.) = {
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
+ .local pmc result
+ result = new 'PAST::Stmt'
+ result.'clone_pge'(node)
.local pmc iter
iter = new Iterator, node # setup iterator for node
@@ -73,26 +70,18 @@
$P2 = iter[$S1]
$P3 = tree.get('result', $P2, $S1)
if null $P3 goto iter_loop
- push newchildren, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $I1 = node.from()
- .local pmc result
- result = new 'PAST::Stmt'
- result.set_node($S2,$I1,newchildren)
-
.return (result)
}
PunieGrammar::expr: result(.) = {
.local pmc result
- .local pmc children
- children = new .ResizablePMCArray
result = new 'PAST::Exp'
+ result.'clone_pge'(node)
+
$P1 = node.get_hash()
$P0 = new Iterator, $P1 # setup iterator for node
set $P0, 0 # reset iterator, begin at start
@@ -102,23 +91,20 @@
$P2 = $P0[$S2] # get entry at current key
$P3 = tree.get('result', $P2, $S2)
if null $P3 goto iter_loop
- push children, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $I3 = node.from()
- result.set_node($S2,$I3,children)
.return (result)
}
PunieGrammar::gprint: result(.) = {
.local pmc result
- .local pmc children
- children = new .ResizablePMCArray
result = new 'PAST::Op'
+ result.'clone_pge'(node)
+ $S1 = node[0]
+ result.'op'($S1)
+
$P1 = node.get_hash()
$P0 = new Iterator, $P1 # setup iterator for node
set $P0, 0 # reset iterator, begin at start
@@ -128,24 +114,20 @@
$P2 = $P0[$S2] # get entry at current key
$P3 = tree.get('result', $P2, $S2)
if null $P3 goto iter_loop
- push children, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $S3 = node[0]
- $I3 = node.from()
- result.set_node($S2,$I3,$S3,children)
.return (result)
}
PunieGrammar::cond: result(.) = {
.local pmc result
- .local pmc children
- children = new .ResizablePMCArray
result = new 'PAST::Op'
+ result.'clone_pge'(node)
+ $S1 = node[0]
+ result.'op'($S1)
+
$P1 = node.get_hash()
.local pmc iter
iter = new Iterator, $P1 # setup iterator for node
@@ -156,27 +138,23 @@
$P2 = iter[$S2] # get entry at current key
$P3 = tree.get('result', $P2, $S2)
if null $P3 goto iter_loop
- push children, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $S3 = node[0]
- $I3 = node.from()
- result.set_node($S2,$I3,$S3,children)
.return (result)
}
PunieGrammar::else: result(.) = {
- .local pmc result
- .local pmc children
.local pmc onechild
- children = new PerlArray
- result = new 'PAST::Op'
onechild = node[0]
unless onechild goto no_child
+ .local pmc result
+ result = new 'PAST::Op'
+ result.'clone_pge'(onechild)
+ $S1 = onechild[0]
+ result.'op'($S1)
+
$P1 = onechild.get_hash()
.local pmc iter
iter = new Iterator, $P1 # setup iterator for node
@@ -187,16 +165,10 @@
$P2 = iter[$S2] # get entry at current key
$P3 = tree.get('result', $P2, $S2)
if null $P3 goto iter_loop
- push children, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = onechild
- $S3 = onechild[0]
- $I3 = onechild.from()
- result.set_node($S2,$I3,$S3,children)
.return (result)
no_child:
.return ()
@@ -211,8 +183,10 @@
$I0 = defined node["PunieGrammar::oexpr"]
unless $I0 goto err_no_oexpr
$P1 = node["PunieGrammar::oexpr"]
- .local pmc children
- children = new .ResizablePMCArray
+ result = new 'PAST::Op'
+ result.'clone_pge'(node)
+ result.'op'('O_COMMA')
+
$P0 = new Iterator, $P1 # setup iterator for node
set $P0, 0 # reset iterator, begin at start
iter_loop:
@@ -220,21 +194,17 @@
shift $P2, $P0 # get next entry
$P3 = tree.get('result', $P2, 'PunieGrammar::oexpr')
if null $P3 goto iter_loop
- push children, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
# If there's only one child node, it's a single element, not a list,
# so just return the single element. Otherwise, we have a comma
# separated list, so build a comma op node.
+ .local pmc children
+ children = result.'children'()
$I0 = elements children
unless $I0 > 1 goto no_comma
- result = new 'PAST::Op'
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $I3 = node.from()
- result.set_node($S2,$I3,'O_COMMA',children)
.return (result)
no_comma:
result = shift children # there's only one result
@@ -245,8 +215,9 @@
}
PunieGrammar::oexpr: result(.) = {
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
+ .local pmc result
+ result = new 'PAST::Exp'
+ result.'clone_pge'(node)
.local pmc iter
$P1 = node.get_hash()
@@ -258,18 +229,10 @@
$P2 = iter[$S1]
$P3 = tree.get('result', $P2, $S1)
if null $P3 goto iter_loop
- push newchildren, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $I1 = node.from()
- .local pmc result
- result = new 'PAST::Exp'
- result.set_node($S2,$I1,newchildren)
-
.return (result)
}
@@ -277,39 +240,28 @@
PunieGrammar::number: result(.) = {
.local pmc result
result = new 'PAST::Val'
-
- # get the source string and position offset from start of source
- # code for this match node
+ result.'clone_pge'(node)
$S2 = node
- $I3 = node.from()
+ result.'value'($S2)
+ result.'valtype'('num')
- result.set_node($S2,$I3,$S2)
- result.valtype('num')
.return (result)
}
PunieGrammar::integer: result(.) = {
.local pmc result
result = new 'PAST::Val'
-
- # get the source string and position offset from start of source
- # code for this match node
+ result.'clone_pge'(node)
$S2 = node
- $I3 = node.from()
-
- result.set_node($S2,$I3,$S2)
- result.valtype('int')
+ result.'value'($S2)
+ result.'valtype'('int')
.return (result)
}
PunieGrammar::stringdouble: result(.) = {
.local pmc result
result = new 'PAST::Val'
-
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $I3 = node.from()
+ result.'clone_pge'(node)
.local string value
# Check if this is a string match
@@ -323,19 +275,15 @@
value = $P2
no_bracketed_value:
- result.set_node($S2,$I3,value)
- result.valtype('strqq')
+ result.'value'(value)
+ result.'valtype'('strqq')
.return (result)
}
PunieGrammar::stringsingle: result(.) = {
.local pmc result
result = new 'PAST::Val'
-
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $I3 = node.from()
+ result.'clone_pge'(node)
.local string value
# Check if this is a string match
@@ -349,8 +297,8 @@
value = $P2
no_bracketed_value:
- result.set_node($S2,$I3,value)
- result.valtype('strq')
+ result.'value'(value)
+ result.'valtype'('strq')
.return (result)
}
@@ -377,10 +325,12 @@
}
expr: op(.) = {
- .local string type
- type = node["type"]
- .local pmc newchildren
- newchildren = new .ResizablePMCArray
+ .local pmc result
+ result = new 'PAST::Op'
+ result.'clone_pge'(node)
+ $S1 = node["type"]
+ result.'op'($S1)
+
$P1 = node.get_array()
.local pmc iter
iter = new Iterator, $P1 # setup iterator for node
@@ -390,17 +340,10 @@
shift $P2, iter # get entry
$P3 = tree.get('result', $P2, 'expr')
if null $P3 goto iter_loop
- push newchildren, $P3
+ result.'add_child'($P3)
goto iter_loop
iter_end:
- # get the source string and position offset from start of source
- # code for this match node
- $S2 = node
- $I3 = node.from()
- .local pmc result
- result = new 'PAST::Op'
- result.set_node($S2,$I3,type,newchildren)
.return (result)
}
Modified: trunk/languages/punie/t/node.t
==============================================================================
--- trunk/languages/punie/t/node.t (original)
+++ trunk/languages/punie/t/node.t Thu Apr 27 19:01:11 2006
@@ -56,11 +56,13 @@
load_bytecode 'languages/punie/lib/Node.pir'
.local pmc node
node = new 'Node'
+ node.'source'('foo')
+ node.'pos'(42)
+
$P0 = new .String
$P0 = 'bar'
- $P1 = new .ResizablePMCArray
- push $P1, $P0
- node.set_node('foo', 42, $P1)
+ node.'add_child'($P0)
+
$P1 = getattribute node, 'source'
print $P1
print "\n"
@@ -83,13 +85,16 @@
.sub _main
load_bytecode 'languages/punie/lib/Node.pir'
.local pmc node1
- .local pmc node2
node1 = new 'Node'
+ node1.'source'('foo')
+ node1.'pos'(42)
+
+ .local pmc node2
node2 = new 'Node'
- node2.set_node('b', 9, $P0)
- $P1 = new .ResizablePMCArray
- push $P1, node2
- node1.set_node('foo', 42, $P1)
+ node2.'source'('b')
+ node2.'pos'(9)
+
+ node1.'add_child'(node2)
node1.dump()
.return ()
.end
Modified: trunk/languages/punie/t/past.t
==============================================================================
--- trunk/languages/punie/t/past.t (original)
+++ trunk/languages/punie/t/past.t Thu Apr 27 19:01:11 2006
@@ -23,9 +23,10 @@
$code .= <<'CODE'
$P0 = new .String
$P0 = 'bar'
- $P1 = new .ResizablePMCArray
- push $P1, $P0
- node.set_node('foo', 42, $P1)
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'add_child'($P0)
+
$P1 = getattribute node, 'source'
print $P1
print "\n"
Modified: trunk/languages/punie/t/past_op.t
==============================================================================
--- trunk/languages/punie/t/past_op.t (original)
+++ trunk/languages/punie/t/past_op.t Thu Apr 27 19:01:11 2006
@@ -9,7 +9,9 @@
load_bytecode 'languages/punie/lib/PAST.pir'
.local pmc node
node = new 'PAST::Op'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'op'('bar')
$P1 = getattribute node, 'source'
print $P1
print "\n"
@@ -32,7 +34,9 @@
load_bytecode 'languages/punie/lib/PAST.pir'
.local pmc node
node = new 'PAST::Op'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'op'('bar')
node.dump()
.return ()
.end
Modified: trunk/languages/punie/t/past_val.t
==============================================================================
--- trunk/languages/punie/t/past_val.t (original)
+++ trunk/languages/punie/t/past_val.t Thu Apr 27 19:01:11 2006
@@ -9,7 +9,9 @@
load_bytecode 'languages/punie/lib/PAST.pir'
.local pmc node
node = new 'PAST::Val'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'value'('bar')
$P1 = getattribute node, 'source'
print $P1
print "\n"
@@ -32,7 +34,9 @@
load_bytecode 'languages/punie/lib/PAST.pir'
.local pmc node
node = new 'PAST::Val'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'value'('bar')
node.dump()
.return ()
.end
Modified: trunk/languages/punie/t/post.t
==============================================================================
--- trunk/languages/punie/t/post.t (original)
+++ trunk/languages/punie/t/post.t Thu Apr 27 19:01:11 2006
@@ -23,9 +23,10 @@
$code .= <<'CODE'
$P0 = new .String
$P0 = 'bar'
- $P1 = new .ResizablePMCArray
- push $P1, $P0
- node.set_node('foo', 42, $P1)
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'add_child'($P0)
+
$P1 = getattribute node, 'source'
print $P1
print "\n"
Added: trunk/languages/punie/t/post_label.t
==============================================================================
--- (empty file)
+++ trunk/languages/punie/t/post_label.t Thu Apr 27 19:01:11 2006
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+
+use strict;
+use lib qw(t . lib ../lib ../../lib ../../../lib);
+use Parrot::Test tests => 3;
+
+pir_output_is(<<'CODE', <<'OUT', 'set attributes via method');
+.sub _main
+ load_bytecode 'languages/punie/lib/POST.pir'
+ .local pmc node
+ node = new 'POST::Label'
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'name'('bar')
+ $P1 = getattribute node, 'source'
+ print $P1
+ print "\n"
+ $P1 = getattribute node, 'pos'
+ print $P1
+ print "\n"
+ $P1 = getattribute node, 'name'
+ print $P1
+ print "\n"
+ .return ()
+.end
+CODE
+foo
+42
+bar
+OUT
+
+pir_output_is(<<'CODE', <<'OUT', 'dump node structure in visual format');
+.sub _main
+ load_bytecode 'languages/punie/lib/POST.pir'
+ .local pmc node
+ node = new 'POST::Label'
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'name'('bar')
+ node.dump()
+ .return ()
+.end
+CODE
+<POST::Label> => {
+ 'source' => 'foo',
+ 'pos' => '42',
+ 'name' => 'bar',
+ 'dest' => undef,
+}
+OUT
+
+pir_output_is(<<'CODE', <<'OUT', 'generate a label');
+.sub _main
+ load_bytecode 'languages/punie/lib/POST.pir'
+ .local pmc node
+ node = new 'POST::Label'
+ $S1 = node.generate_label('name')
+ print $S1
+ print "\n"
+ $S2 = node.generate_label()
+ print $S2
+ print "\n"
+ .return()
+.end
+CODE
+name_label_1
+label_2
+OUT
Modified: trunk/languages/punie/t/post_op.t
==============================================================================
--- trunk/languages/punie/t/post_op.t (original)
+++ trunk/languages/punie/t/post_op.t Thu Apr 27 19:01:11 2006
@@ -9,7 +9,9 @@
load_bytecode 'languages/punie/lib/POST.pir'
.local pmc node
node = new 'POST::Op'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'op'('bar')
$P1 = getattribute node, 'source'
print $P1
print "\n"
@@ -32,7 +34,9 @@
load_bytecode 'languages/punie/lib/POST.pir'
.local pmc node
node = new 'POST::Op'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'op'('bar')
node.dump()
.return ()
.end
Modified: trunk/languages/punie/t/post_val.t
==============================================================================
--- trunk/languages/punie/t/post_val.t (original)
+++ trunk/languages/punie/t/post_val.t Thu Apr 27 19:01:11 2006
@@ -9,7 +9,9 @@
load_bytecode 'languages/punie/lib/POST.pir'
.local pmc node
node = new 'POST::Val'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'value'('bar')
$P1 = getattribute node, 'source'
print $P1
print "\n"
@@ -32,7 +34,9 @@
load_bytecode 'languages/punie/lib/POST.pir'
.local pmc node
node = new 'POST::Val'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'value'('bar')
node.dump()
.return ()
.end
Modified: trunk/languages/punie/t/post_var.t
==============================================================================
--- trunk/languages/punie/t/post_var.t (original)
+++ trunk/languages/punie/t/post_var.t Thu Apr 27 19:01:11 2006
@@ -9,7 +9,9 @@
load_bytecode 'languages/punie/lib/POST.pir'
.local pmc node
node = new 'POST::Var'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'varname'('bar')
$P1 = getattribute node, 'source'
print $P1
print "\n"
@@ -32,7 +34,9 @@
load_bytecode 'languages/punie/lib/POST.pir'
.local pmc node
node = new 'POST::Var'
- node.set_node('foo', 42, 'bar')
+ node.'source'('foo')
+ node.'pos'(42)
+ node.'varname'('bar')
node.dump()
.return ()
.end