[svn:parrot] r38814 - trunk/docs/pct
coke at svn.parrot.org
coke at svn.parrot.org
Sat May 16 02:26:03 UTC 2009
Author: coke
Date: Sat May 16 02:26:03 2009
New Revision: 38814
URL: https://trac.parrot.org/parrot/changeset/38814
Log:
[docs] Mark & Test more PASM/PIR code.
Modified:
trunk/docs/pct/past_building_blocks.pod
trunk/docs/pct/pct_optable_guide.pod
Modified: trunk/docs/pct/past_building_blocks.pod
==============================================================================
--- trunk/docs/pct/past_building_blocks.pod Sat May 16 02:22:57 2009 (r38813)
+++ trunk/docs/pct/past_building_blocks.pod Sat May 16 02:26:03 2009 (r38814)
@@ -38,11 +38,15 @@
Without any attributes, a PAST::Block translates to the following:
+=begin PIR
+
.namespace []
.sub "_block10"
.return ()
.end
+=end PIR
+
=head2 Typical use
A block represents a lexical C<scope>. The most common use for a block
@@ -91,6 +95,8 @@
The block is invoked immediately. When the :blocktype attribute is set to this
value, the generated PIR becomes:
+=begin PIR
+
.namespace []
.sub "anon"
get_global $P11, "_block10"
@@ -103,6 +109,8 @@
.return ()
.end
+=end PIR
+
The sub C<anon> is the I<main> function, which is the entry point of the
whole program. It looks for the sub that we declared, creates a new closure
from that block (more on that later), and invokes that closure.
@@ -118,10 +126,13 @@
translates to:
+=begin PIR
+
.sub "foo"
.return ()
.end
+=end PIR
=head2 Symbol tables
As a block defines a new scope, a PAST::Block object has a symbol table,
@@ -197,8 +208,12 @@
results in:
+=begin PIR_FRAGMENT
+
find_lex $P10, "foo"
+=end PIR_FRAGMENT
+
=head2 Typical use
Nodes of type PAST::Var are used to represent variables and their declarations
@@ -226,8 +241,12 @@
When the C<:scope> attribute is set to C<lexical>, then the identifier
specified in the C<:name> attribute is handled as a lexical:
+=begin PIR_FRAGMENT
+
find_lex $P10, "foo"
+=end PIR_FRAGMENT
+
=item 'package'
Defines the variable as a C<package> variable. This is handled by the
@@ -237,9 +256,13 @@
Defines the variable as a parameter (but is stored as a lexical).
+=begin PIR_FRAGMENT
+
.param pmc param_10
.lex "foo", param_10
+=end PIR_FRAGMENT
+
=item 'keyed'
my $idx := PAST::Var.new( :name('foo'), :scope('package') );
@@ -248,10 +271,14 @@
results in:
+=begin PIR_FRAGMENT
+
get_global $P10, "foo" # get index, a package-scoped variable "foo"
get_global $P11, "bar" # get aggregate, a package-scoped variable "bar"
set $P12, $P11[$P10] # get the contents at bar[foo]
+=end PIR_FRAGMENT
+
=item 'attribute'
Defines the variable as an attribute of an object. The first child of
@@ -266,9 +293,13 @@
translates to:
+=begin PIR_FRAGMENT_INVALID
+
get_global $P10, "foo"
get_attribute $P11, $P10, "bar"
+=end PIR_FRAGMENT_INVALID
+
Note: currently, no child nodes are evaluated, so you can only get
attributes on C<self> for now.
@@ -279,8 +310,12 @@
If this flag is set, the variable represented by this PAST::Var node is
declared at this point. This flag is cleared by default.
+=begin PIR_FRAGMENT
+
.lex "foo", $P10
+=end PIR_FRAGMENT
+
=head3 C<:viviself>
When this attribute is set, the variable is initialized with the value
@@ -307,9 +342,13 @@
results in:
+=begin PIR_FRAGMENT
+
new $P10, "Integer"
assign $P10, 42
+=end PIR_FRAGMENT
+
=head2 Typical use
All literal values in your source language can be represented by
@@ -397,8 +436,12 @@
results in:
+=begin PIR_FRAGMENT
+
"foo"()
+=end PIR_FRAGMENT
+
while
my $fun := PAST::Var.new( :name('foo'), :scope('package'));
@@ -406,9 +449,13 @@
generates:
+=begin PIR_FRAGMENT
+
get_global $P10, "foo"
$P10()
+=end PIR_FRAGMENT
+
Children of a :pasttype('call') node are evaluated and passed as arguments.
If the node does not receive a C<:name> attribute, then the first child
is evaluated as the subroutine to be invoked.
@@ -423,10 +470,12 @@
generates:
+=begin PIR_FRAGMENT
+
get_global $P10, "foo"
$P10."bar"()
-
+=end PIR_FRAGMENT
=item C<bind>
@@ -439,14 +488,22 @@
results in:
+=begin PIR_FRAGMENT
+
new $P10, "Integer" # code for evaluating $rhs
assign $P10, 42
set_global "foo", $P10 # code for the :pasttype('bind') op
+=end PIR_FRAGMENT
+
when the scope is set to C<lexical>, the last line becomes:
+=begin PIR_FRAGMENT
+
store_lex "foo", $P10
+=end PIR_FRAGMENT
+
=back
=head3 C<:inline>
@@ -464,9 +521,12 @@
is transformed to:
+=begin PIR_FRAGMENT
+
find_lex $P10, "foo" # generated for $var
$P11 = $P10 # inline '%r = %0'
+=end PIR_FRAGMENT
=head1 TIPS AND TRICKS
Modified: trunk/docs/pct/pct_optable_guide.pod
==============================================================================
--- trunk/docs/pct/pct_optable_guide.pod Sat May 16 02:22:57 2009 (r38813)
+++ trunk/docs/pct/pct_optable_guide.pod Sat May 16 02:26:03 2009 (r38814)
@@ -152,6 +152,8 @@
C<infix:+>. Therefore, you need to write a subroutine for each operator
you define. The subroutine for the C<infix:+> operator could look like this:
+=begin PIR_INVALID
+
.sub 'infix:+'
.param pmc a # left operand
.param pmc b # right operand
@@ -159,6 +161,8 @@
.return ($P0)
.end
+=end PIR_INVALID
+
Whenever an expression such as C<42 + 1> is parsed, this will result in a
call to C<infix:+> with the operands C<42> and C<1>. The C<infix:+> sub
will create a new object, and assign the result of C<42 + 1> to it, after
More information about the parrot-commits
mailing list