Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix rows.t, multi-row cells werent' initializing correctly

  • Loading branch information...
commit 136c693413cf583e7d9c96e96097a16c54a076fc 1 parent 327017e
@Whiteknight authored
View
6 src/internals/aggregates.pir
@@ -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
@@ -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:
View
7 src/internals/dispatch.pir
@@ -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
@@ -441,6 +441,11 @@ file.
.return(sub_obj)
.end
+.sub '!unpack_return_array'
+ .param pmc args
+ .return(args :flat)
+.end
+
.namespace []
View
62 src/parser/actions.pm
@@ -366,8 +366,7 @@ method variable_declaration($/) {
method func_def($/) {
our @?BLOCK;
our $?BLOCK;
-
- our @RETID;
+ our @FUNCRETURNS;
my $past := $( $<func_sig> );
@@ -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
@@ -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(
@@ -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
View
9 src/parser/grammar.pg
@@ -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>]* ]? ')']?
{*}
}
View
2  t/2-function.t
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.