Skip to content

Commit

Permalink
fix rows.t, multi-row cells werent' initializing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Whiteknight committed Dec 9, 2009
1 parent 327017e commit 136c693
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/internals/aggregates.pir
Expand Up @@ -11,6 +11,11 @@
.return(ary)
.end

.sub '!cell'
$P0 = new ['PMCMatrix2D']
.return($P0)
.end

.sub '!matrix_from_rows'
.param pmc ary :slurpy
.local pmc lengths
Expand Down Expand Up @@ -78,6 +83,7 @@
row = shift myiter
$I1 = row
if $I1 != length goto lengths_not_equal
inc $I0
goto loop_top
loop_bottom:
new_empty_cell:
Expand Down
7 changes: 6 additions & 1 deletion src/internals/dispatch.pir
Expand Up @@ -80,7 +80,7 @@ found, null otherwise.

# Second, look for a locally-defined function
# TODO: Fix this to be "Matrixy";"functions" instead
sub_obj = get_hll_global ["Matrixy::functions"], name
sub_obj = get_hll_global ["Matrixy";"functions"], name
$I0 = defined sub_obj
if $I0 goto _dispatch_found_sub

Expand Down Expand Up @@ -441,6 +441,11 @@ file.
.return(sub_obj)
.end
.sub '!unpack_return_array'
.param pmc args
.return(args :flat)
.end
.namespace []
62 changes: 46 additions & 16 deletions src/parser/actions.pm
Expand Up @@ -366,8 +366,7 @@ method variable_declaration($/) {
method func_def($/) {
our @?BLOCK;
our $?BLOCK;

our @RETID;
our @FUNCRETURNS;

my $past := $( $<func_sig> );

Expand All @@ -376,14 +375,18 @@ method func_def($/) {
}

# add a return statement if needed
# TODO: Support multiple returns
if @RETID {
my $var := PAST::Var.new(
:name(@RETID[0].name())
if @FUNCRETURNS {
my $retop := PAST::Op.new(
:pasttype('return')
);
my $retop := PAST::Op.new( $var, :pasttype('return') );
for @FUNCRETURNS {
$retop.push(
PAST::Var.new(
:name($_.name())
)
)
}
$past.push($retop);
@RETID.shift();
}

# remove the block from the scope stack
Expand All @@ -398,14 +401,15 @@ method func_def($/) {
method func_sig($/) {
our $?BLOCK;
our @?BLOCK;
our @RETID;
our @FUNCRETURNS;

@FUNCRETURNS := _new_empty_array();
my $name := $( $<identifier>[0] );
$<identifier>.shift();

my $past := PAST::Block.new(
:blocktype('declaration'),
:namespace('Matrixy::functions'),
:namespace('Matrixy', 'functions'),
:node($/),
:name($name.name()),
PAST::Var.new(
Expand Down Expand Up @@ -459,12 +463,38 @@ method func_sig($/) {
}

if $<return_identifier> {
my $param := $( $<return_identifier>[0] );
$param.scope('lexical');
$param.isdecl(1);
$past.push($param);
$past.symbol($param.name(), :scope('lexical'));
@RETID[0] := $param;
my $hasvarargout := 0;
my $varargout;
for $<return_identifier> {
if $hasvarargout == 1 {
_error_all("varargout must be the last return value")
}
my $param := $( $_ );
$param.scope('lexical');
$param.isdecl(1);
$past.symbol($param.name(), :scope('lexical'));
if $param.name() eq "varargout" {
$hasvarargout := 1;
$varargout := $param;
}
$past.push($param);
@FUNCRETURNS.push($param);
}
if $hasvarargout == 1 {
# if we have the varargout return identifier, autovivify it into
# a cell
$past.push(
PAST::Op.new(
$varargout,
PAST::Op.new(
:pasttype('call'),
:name('!cell')
),
:pasttype('bind'),
:node($/)
)
);
}
}

## set this block as the current block, and store it on the scope stack
Expand Down
9 changes: 7 additions & 2 deletions src/parser/grammar.pg
Expand Up @@ -228,8 +228,13 @@ rule func_def {
}

rule func_sig {
'function' [<return_identifier> '=']? <identifier>
['(' [ <identifier> [',' <identifier>]* ]? ')']?
'function'
[
<return_identifier> [',' <return_identifier> ]* '='
| '(' <return_identifier> [',' <return_identifier> ]* '=' ')'
]?
<identifier>
['(' [ <identifier> [',' <identifier>]* ]? ')']?
{*}
}

Expand Down
2 changes: 1 addition & 1 deletion t/2-function.t
Expand Up @@ -76,7 +76,7 @@ function x = argsouttest()
if nargout == 1
printf("ok 10\n");
else
printf("not ok 10 # TODO need to implement nargout\n");
printf("not ok 10 - %d# TODO need to implement nargout\n", nargout);
endif
endfunction
a = argsouttest();

0 comments on commit 136c693

Please sign in to comment.