Author: jkeenan Date: Sun Jan 28 09:27:47 2007 New Revision: 16824 Modified: branches/buildtools/languages/lua/Lua/build.pm branches/buildtools/languages/lua/Lua/opcode.pm branches/buildtools/languages/lua/Lua/pir.pm branches/buildtools/languages/lua/t/function.t branches/buildtools/lib/Parrot/Ops2pm/Utils.pm branches/buildtools/lib/Parrot/Pmc2c/Utils.pm branches/buildtools/t/tools/ops2pmutils/05-renum_op_map_file.t branches/buildtools/t/tools/ops2pmutils/06-load_op_map_files.t branches/buildtools/tools/build/ops2pm.pl
Log: 1. Eliminated unused variables in two test files. 2. Wrote documentation for tools/build/ops2pm.pl and lib/Parrot/Ops2pm/Utils.pm. Not yet complete. 3. Synched files in 'buildtools' branch to recent changes to trunk. Modified: branches/buildtools/languages/lua/Lua/build.pm ============================================================================== --- branches/buildtools/languages/lua/Lua/build.pm (original) +++ branches/buildtools/languages/lua/Lua/build.pm Sun Jan 28 09:27:47 2007 @@ -1136,6 +1136,23 @@ sub BuildReturn { my ( $parser, $exprs ) = @_; + if ( scalar @{$exprs} == 1 ) { + my $expr = $exprs->[0]; + if ( scalar $expr->[1] ) { + my @opcodes = @{ $expr->[1] }; + if ( scalar @opcodes and $opcodes[-1]->isa('CallOp') ) { + my $call = pop @opcodes; + my $ass = pop @opcodes; + my $loc = pop @opcodes; + push @opcodes, new TailCallDir( + $parser, + 'arg1' => $call->{arg1}, + 'arg2' => $call->{arg2}, + ); + return [EMAIL PROTECTED]; + } + } + } my @opcodes = (); my @returns = (); for my $expr ( @{$exprs} ) { Modified: branches/buildtools/languages/lua/Lua/opcode.pm ============================================================================== --- branches/buildtools/languages/lua/Lua/opcode.pm (original) +++ branches/buildtools/languages/lua/Lua/opcode.pm Sun Jan 28 09:27:47 2007 @@ -97,6 +97,9 @@ package CallMethOp; use base qw(Lua::opcode); +package TailCallDir; +use base qw(Lua::opcode); + package LabelOp; use base qw(Lua::opcode); Modified: branches/buildtools/languages/lua/Lua/pir.pm ============================================================================== --- branches/buildtools/languages/lua/Lua/pir.pm (original) +++ branches/buildtools/languages/lua/Lua/pir.pm Sun Jan 28 09:27:47 2007 @@ -243,6 +243,24 @@ return; } + sub visitTailCallDir { + my $self = shift; + my ($op) = @_; + my $FH = $self->{fh}; + print {$FH} " .return $op->{arg1}->{symbol}("; + my $first = 1; + foreach ( @{ $op->{arg2} } ) { + print {$FH} ", " unless ($first); + print {$FH} "$_->{symbol}"; + if ( exists $_->{pragma} and $_->{pragma} eq 'multi' ) { + print {$FH} " :flat"; + } + $first = 0; + } + print {$FH} ")\n"; + return; + } + sub visitBranchIfOp { my $self = shift; my ($op) = @_; Modified: branches/buildtools/languages/lua/t/function.t ============================================================================== --- branches/buildtools/languages/lua/t/function.t (original) +++ branches/buildtools/languages/lua/t/function.t Sun Jan 28 09:27:47 2007 @@ -23,7 +23,7 @@ use FindBin; use lib "$FindBin::Bin"; -use Parrot::Test tests => 11; +use Parrot::Test tests => 12; use Test::More; language_output_is( 'lua', <<'CODE', <<'OUT', 'add' ); @@ -202,6 +202,24 @@ /no loop to break/ OUT +language_output_is( 'lua', <<'CODE', <<'OUT', 'tail call' ); +local function foo (n) + print(n) + if n > 0 then + return foo(n -1) + end + return 'end', 0 +end + +print(foo(3)) +CODE +3 +2 +1 +0 +end 0 +OUT + # Local Variables: # mode: cperl # cperl-indent-level: 4 Modified: branches/buildtools/lib/Parrot/Ops2pm/Utils.pm ============================================================================== --- branches/buildtools/lib/Parrot/Ops2pm/Utils.pm (original) +++ branches/buildtools/lib/Parrot/Ops2pm/Utils.pm Sun Jan 28 09:27:47 2007 @@ -10,6 +10,53 @@ use lib ("lib/"); use Parrot::OpsFile; +=head1 NAME + +Parrot::Ops2pm::Utils - Methods holding functionality for F<tools/build/ops2pm.pl>. + +=head1 SYNOPSIS + + use Parrot::Ops2pm::Utils; + + $self = Parrot::Ops2pm::Utils->new( { + argv => [ @ARGV ], + nolines => $nolines_flag, + renum => $renum_flag, + moddir => "lib/Parrot/OpLib", + module => "core.pm", + inc_dir => "include/parrot/oplib", + inc_f => "ops.h", + script => "tools/build/ops2pm.pl", + } ); + + $self->prepare_ops(); + + if ($renum_flag) { + $self->renum_op_map_file(); + exit 0; + } + + $self->load_op_map_files(); + $self->sort_ops(); + $self->prepare_real_ops(); + $self->print_module(); + $self->print_h(); + exit 0; + +=cut + +=head1 DESCRIPTION + +Parrot::Ops2pm::Utils provides methods called by F<tools/build/ops2pm.pl>, a +program which is called at the very beginning of the Parrot F<make> process. +The program's function is to build two files: + +The functionality originally found in F<tools/build/ops2pm.pl> has been +extracted into this package's methods in order to support component-focused +testing and future refactoring. + +=cut + ############### Package-scoped Lexical Variables ############### my $NUM_FILE = "src/ops/ops.num"; @@ -17,6 +64,41 @@ ############### Subroutines ############### +=head1 METHODS + +=head2 C<new()> + +B<Purpose:> Process files provided as command-line arguments to +F<tools/build/ops2pm.pl> and construct a Parrot::Ops2pm::Utils object. + +B<Arguments:> Hash reference with the following elements: + + argv : reference to @ARGV + nolines : set to true value to eliminate #line + directives in output + renum : set to true value if + moddir : directory where output module is created + (generally, lib/Parrot/OpLib) + module : name of output module + (generally, core.pm) + inc_dir : directory where C-header file is created + (generally, include/parrot/oplib) + inc_f : name of output C-header file + (generally, ops.h) + script : name of the script to be executed by 'make' + (generally, tools/build/ops2pm.pl) + +B<Return Value:> Parrot::Ops2pm::Utils object. + +B<Comment:> Arguments for the constructor have been selected so as to provide +subsequent methods with all information needed to execute properly and to be +testable. A Parrot::Ops2pm::Utils object I<can> be constructed lacking some +of these arguments and still suffice for the execution of particular methods +-- this is done during the test suite -- but such an object would not suffice +for F<make>'s call to F<tools/build/ops2pm.pl>. + +=cut + sub new { my ($class, $argsref) = @_; my @argv = @{$argsref->{argv}}; @@ -28,6 +110,22 @@ return bless $argsref, $class; } +=head2 C<prepare_ops()> + +B<Purpose:> Call C<Parrot::OpsFile->new()>, then populate the resulting +C<$opts> hash reference with information from each of the F<.ops> files +provided as command-line arguments to F<tools/build/ops2pm.pl>. + +B<Arguments:> None. (Implicitly requires that at least the C<argv> and +C<script> elements were provided to the constructor.) + +B<Return Value:> None. Internally, sets the C<ops> key in the object's data +structure. + +B<Comment:> + +=cut + sub prepare_ops { my $self = shift; my $ops = Parrot::OpsFile->new( [$self->{file}], $self->{nolines} ); @@ -65,6 +163,21 @@ $self->{ops} = $ops; } +=head2 C<renum_op_map_file()> + +B<Purpose:> Triggered when F<tools/build/ops2pm.pl> is called with the +C<--renum> flag, this method ... + +B<Arguments:> String holding name of an F<.ops> file; defaults to +F<src/ops/ops.num>. + +B<Return Value:> Returns true value upon success. + +B<Comment:> After being called by F<tools/build/ops2pm.pl>, that script +exits, making this the only Parrot::Ops2pm::Utils method which is I<not> a +stepping stone on the path to building F<lib/Parrot/OpLib/core.pm>. + +=cut sub renum_op_map_file { my $self = shift; @@ -110,6 +223,20 @@ return 1; } +=head2 C<load_op_map_files()> + +B<Purpose:> + +B<Arguments:> None. + +B<Return Value:> Returns true value upon success. Internally, sets these +keys in the object's data structure: C<max_op_num>, C<skiptable> and +C<optable>. + +B<Comment:> + +=cut + sub load_op_map_files { my $self = shift; my $num_file = $NUM_FILE; @@ -118,9 +245,6 @@ my ( $op, $name, $number, $prev ); $self->{max_op_num} ||= 0; -# unless ($self->{max_op_num}) { -# $self->{max_op_num} = 0; -# } open $op, '<', $num_file or die "Can't open $num_file: $!"; @@ -164,6 +288,19 @@ return 1; } +=head2 C<sort_ops()> + +B<Purpose:> + +B<Arguments:> None. + +B<Return Value:> None. Internally, sets the C<ops> key of the object's data +structure. + +B<Comment:> + +=cut + sub sort_ops { my $self = shift; for my $el ( @{ $self->{ops}->{OPS} } ) { @@ -192,6 +329,19 @@ @{ $self->{ops}->{OPS} } = sort { $a->{CODE} <=> $b->{CODE} } ( @{ $self->{ops}->{OPS} } ); } +=head2 C<prepare_real_ops()> + +B<Purpose:> + +B<Arguments:> None. + +B<Return Value:> None. Internally, sets the C<real_ops> key of the object's data +structure. + +B<Comment:> + +=cut + sub prepare_real_ops { my $self = shift; @@ -217,6 +367,19 @@ $self->{real_ops} = $real_ops; } +=head2 C<print_module()> + +B<Purpose:> Uses information in the object's data structure to create +F<lib/Parrot/OpLib/core.pm>. + +B<Arguments:> None. + +B<Return Value:> Returns true value upon success. + +B<Comment:> + +=cut + sub print_module { my $self = shift; my $cwd = cwd(); @@ -279,6 +442,19 @@ return 1; } +=head2 C<print_h()> + +B<Purpose:> Uses information in the object's data structure to create +F<include/parrot/oplib/ops.h>. + +B<Arguments:> None. + +B<Return Value:> Returns true value upon success. + +B<Comment:> + +=cut + sub print_h { my $self = shift; my $cwd = cwd(); Modified: branches/buildtools/lib/Parrot/Pmc2c/Utils.pm ============================================================================== --- branches/buildtools/lib/Parrot/Pmc2c/Utils.pm (original) +++ branches/buildtools/lib/Parrot/Pmc2c/Utils.pm Sun Jan 28 09:27:47 2007 @@ -1,5 +1,5 @@ # Copyright (C) 2004-2006, The Perl Foundation. -# $Id: Parrot::Pmc2c::Utils.pm 15044 2006-10-29 00:00:11Z jonathan $ +# $Id$ package Parrot::Pmc2c::Utils; use strict; use warnings; Modified: branches/buildtools/t/tools/ops2pmutils/05-renum_op_map_file.t ============================================================================== --- branches/buildtools/t/tools/ops2pmutils/05-renum_op_map_file.t (original) +++ branches/buildtools/t/tools/ops2pmutils/05-renum_op_map_file.t Sun Jan 28 09:27:47 2007 @@ -26,9 +26,6 @@ use_ok( 'Parrot::Ops2pm::Utils' ); ok(chdir $main::topdir, "Positioned at top-level Parrot directory"); -my ( $nolines_flag, $help_flag, $renum_flag ); -my ($file, $argvref); -my ($ops, %temp); # regular case { Modified: branches/buildtools/t/tools/ops2pmutils/06-load_op_map_files.t ============================================================================== --- branches/buildtools/t/tools/ops2pmutils/06-load_op_map_files.t (original) +++ branches/buildtools/t/tools/ops2pmutils/06-load_op_map_files.t Sun Jan 28 09:27:47 2007 @@ -30,9 +30,6 @@ use constant SKIP_FILE => "src/ops/ops.skip"; ok(chdir $main::topdir, "Positioned at top-level Parrot directory"); -my ( $nolines_flag, $help_flag, $renum_flag ); -my ($file, $argvref); -my ($ops, %temp); { local @ARGV = qw( src/ops/core.ops Modified: branches/buildtools/tools/build/ops2pm.pl ============================================================================== --- branches/buildtools/tools/build/ops2pm.pl (original) +++ branches/buildtools/tools/build/ops2pm.pl Sun Jan 28 09:27:47 2007 @@ -55,9 +55,13 @@ =head1 DESCRIPTION Reads the ops files listed on the command line and outputs a -C<Parrot::OpLib::core> module containing information about the ops. +F<Parrot::OpLib::core> module containing information about the ops. +Also outputs F<include/parrot/oplib/ops.h>. This program is called by Parrot's +F<make>. -=head2 Options +If called with the C<--renum> flag, ... + +=head1 OPTIONS =over 4 @@ -76,7 +80,13 @@ =back -=head2 WARNING +Most of the functionality in this program is now held in Parrot::Ops2pm::Util +methods and a small number of Parrot::Ops2pm::Auxiliary subroutines. +See those modules' documentation for discussion of those functions. +Revisions to the functionality should be made in those packages and tested +against tests found in F<t/tools/ops2pmutils/>. + +=head1 WARNING Generating a C<Parrot::OpLib::core> module for a set of ops files that you do not later turn into C code (see F<tools/build/ops2c.pl>) with the @@ -111,8 +121,14 @@ =item F<tools/build/ops2c.pl>. +=item F<lib/Parrot/Ops2pm/Utils.pm>. + +=item F<lib/Parrot/Ops2pm/Auxiliary.pm>. + =back +=head1 AUTHOR + =cut # Local Variables: