Author: tene
Date: Fri Mar 28 13:39:50 2008
New Revision: 26604
Added:
trunk/languages/lolcode/t/06-functionparams.t
Modified:
trunk/languages/lolcode/src/parser/actions.pm
Log:
Fix the last test failure.
Add tests for functions that have parameters.
Modified: trunk/languages/lolcode/src/parser/actions.pm
==============================================================================
--- trunk/languages/lolcode/src/parser/actions.pm (original)
+++ trunk/languages/lolcode/src/parser/actions.pm Fri Mar 28 13:39:50 2008
@@ -40,8 +40,8 @@
method declare($/) {
- $($<variable>).isdecl(1);
if ($<expression>) {
+ $($<variable>).isdecl(1);
# XXX Someone clever needs to refactor this into C<assign>
my $past := PAST::Op.new( :pasttype('bind'), :node( $/ ) );
$past.push( $( $<variable> ) );
@@ -65,19 +65,17 @@
$block.blocktype('declaration');
my $arglist;
- if $<arglist> {
- $arglist := PAST::Stmts.new( :node($<arglist>) );
- # if there are any parameters, get the PAST for each of them and
- # adjust the scope to parameter.
- $block.arity(0);
- for $<parameters> {
- #my $param := $($_);
- #$param.scope('parameter');
- my $param := PAST::Var.new(:name(~$_<identifier>),
:scope('parameter'), :node($($_)));
- $param.isdecl(1);
- $arglist.push($param);
- $block.arity($block.arity() + 1);
- }
+ $arglist := PAST::Stmts.new();
+ # if there are any parameters, get the PAST for each of them and
+ # adjust the scope to parameter.
+ $block.arity(0);
+ for $<parameters> {
+ #my $param := $($_);
+ #$param.scope('parameter');
+ my $param := PAST::Var.new(:name(~$_<identifier>),
:scope('parameter'), :node($($_)));
+ $param.isdecl(1);
+ $arglist.push($param);
+ $block.arity($block.arity() + 1);
}
@@ -87,7 +85,7 @@
$it := PAST::Var.new( :name( 'IT' ), :scope('lexical'));
$block[0].push($it);
- if $<arglist> { $block.unshift($arglist); }
+ if $<parameters> { $block.unshift($arglist); }
$block.name(~$<variable><identifier>);
make $block;
Added: trunk/languages/lolcode/t/06-functionparams.t
==============================================================================
--- (empty file)
+++ trunk/languages/lolcode/t/06-functionparams.t Fri Mar 28 13:39:50 2008
@@ -0,0 +1,22 @@
+HAI 1.2
+ VISIBLE "1..3"
+
+ BTW MAEK AN OKAY FUNCTION
+ HOW DUZ I OKAY YR NUM
+ VISIBLE "ok " NUM
+ IF U SAY SO
+
+ I HAS A TESTNUM ITZ 1
+ OKAY TESTNUM
+
+ HOW DUZ I PASSTWOTESTS YR first AN YR second
+ OKAY first
+ OKAY second
+ IF U SAY SO
+
+ TESTNUM R 2
+
+ PASSTWOTESTS TESTNUM SUM OF TESTNUM AN 1
+
+ BTW vim: set filetype=lolcode :
+KTHXBYE