Permalink
Browse files

implemented lists

  • Loading branch information...
1 parent c6ec2fd commit a573e3572e635625e11d472c9d75c65c6da0acbc @fglock committed Aug 26, 2010
View
@@ -1,9 +1,11 @@
dev version - 2010-08-23
+- backends pending upgrade to the new AST: Go, Common Lisp, Python 2, and Ruby 1.9
+- backends not supported in this version: Parrot, Rakudo, Clojure
+
- correct operator precedence
- interpolation of variables in strings
- 'unless'
-- backends pending upgrade to the new AST: Go, Common Lisp, Python 2, and Ruby 1.9
-- backends not supported in this version: Parrot, Rakudo, Clojure
+- lists
6.0 2010-07-27
- Ruby backend bootstrap.
@@ -181,7 +181,18 @@ class Lit::Array {
has @.array1;
method emit_javascript {
my $needs_interpolation = 0;
+ my @items;
for @.array1 -> $item {
+ if $item.isa( 'Apply' ) && ( $item.code eq 'circumfix:<( )>' || $item.code eq 'list:<,>' ) {
+ for @($item.arguments) -> $arg {
+ @items.push($arg);
+ }
+ }
+ else {
+ @items.push($item);
+ }
+ }
+ for @items -> $item {
if ( $item.isa( 'Var' ) && $item.sigil eq '@' )
|| ( $item.isa( 'Apply' ) && $item.code eq 'prefix:<@>' )
{
@@ -190,7 +201,7 @@ class Lit::Array {
}
if $needs_interpolation {
my $s = '';
- for @.array1 -> $item {
+ for @items -> $item {
if ( $item.isa( 'Var' ) && $item.sigil eq '@' )
|| ( $item.isa( 'Apply' ) && $item.code eq 'prefix:<@>' )
{
@@ -208,7 +219,7 @@ class Lit::Array {
~ ' return a })()';
}
else {
- '[' ~ (@.array1.>>emit_javascript).join(', ') ~ ']';
+ '[' ~ (@items.>>emit_javascript).join(', ') ~ ']';
}
}
}
@@ -574,6 +585,11 @@ class Apply {
$str = $str ~ 'return (' ~ $var_js ~ '[' ~ $index_js ~ '] ' ~ ' = ' ~ $arguments.emit_javascript() ~ '); ';
return '(function () { ' ~ $str ~ '})()';
}
+ if $parameters.isa( 'Var' ) && $parameters.sigil eq '@'
+ || $parameters.isa( 'Decl' ) && $parameters.var.sigil eq '@'
+ {
+ $arguments = Lit::Array.new( array1 => [$arguments] );
+ }
'(' ~ $parameters.emit_javascript() ~ ' = ' ~ $arguments.emit_javascript() ~ ')';
}
}
@@ -625,6 +641,10 @@ class For {
has $.cond;
has @.body;
method emit_javascript {
+ my $cond = $.cond;
+ if !( $cond.isa( 'Var' ) && $cond.sigil eq '@' ) {
+ $cond = Lit::Array.new( array1 => [$cond] )
+ }
my $body = MiniPerl6::Javascript::LexicalBlock.new( block => @.body.stmts, needs_return => 0 );
my $sig = 'v__';
if $.body.sig() {
@@ -634,7 +654,7 @@ class For {
~ "(function ($sig) { "
~ $body.emit_javascript()
~ ' })(a_[i_]) } })'
- ~ '(' ~ $.cond.emit_javascript() ~ ')'
+ ~ '(' ~ $cond.emit_javascript() ~ ')'
}
}
@@ -71,9 +71,19 @@ class Lit::Array {
has @.array1;
method emit_perl5 {
my @s;
+ my @items;
for @.array1 -> $item {
- if ( $item.isa( 'Var' ) && $item.sigil eq '@' )
- {
+ if $item.isa( 'Apply' ) && ( $item.code eq 'circumfix:<( )>' || $item.code eq 'list:<,>' ) {
+ for @($item.arguments) -> $arg {
+ @items.push($arg);
+ }
+ }
+ else {
+ @items.push($item);
+ }
+ }
+ for @items -> $item {
+ if $item.isa( 'Var' ) && $item.sigil eq '@' {
push @s, '@{' ~ $item.emit_perl5() ~ '}';
}
else {
@@ -387,7 +397,11 @@ class Apply {
}
return $str ~ $parameters.emit_perl5() ~ ' }';
}
-
+ if $parameters.isa( 'Var' ) && $parameters.sigil eq '@'
+ || $parameters.isa( 'Decl' ) && $parameters.var.sigil eq '@'
+ {
+ $arguments = Lit::Array.new( array1 => [$arguments] );
+ }
'(' ~ $parameters.emit_perl5() ~ ' = ' ~ $arguments.emit_perl5() ~ ')';
}
}
@@ -437,16 +451,14 @@ class For {
has $.body;
method emit_perl5 {
my $cond = $.cond;
- if $cond.isa( 'Var' )
- && $cond.sigil eq '@'
- {
- $cond = Apply.new( code => 'prefix:<@>', arguments => [ $cond ] );
+ if !( $cond.isa( 'Var' ) && $cond.sigil eq '@' ) {
+ $cond = Lit::Array.new( array1 => [$cond] )
}
my $sig;
if $.body.sig() {
$sig = 'my ' ~ $.body.sig.emit_perl5() ~ ' ';
}
- return "for $sig ( " ~ $cond.emit_perl5() ~ ' ) { '
+ return 'for ' ~ $sig ~ '( @{' ~ $cond.emit_perl5() ~ '} ) { '
~ $.body.emit_perl5()
~ ' }';
}
@@ -133,7 +133,7 @@ class MiniPerl6::Python::LexicalBlock {
}
for @($block) -> $stmt {
- @anon_block = [];
+ @anon_block = ();
my $s2 = $stmt.emit_python_indented($level);
for @anon_block -> $stmt {
@s.push( $stmt.emit_python_indented( $level ) );
@@ -142,7 +142,7 @@ class MiniPerl6::Python::LexicalBlock {
}
if $.needs_return && $last_statement {
- @anon_block = [];
+ @anon_block = ();
my $s2;
if $last_statement.isa( 'If' ) {
my $cond = $last_statement.cond;
Oops, something went wrong.

0 comments on commit a573e35

Please sign in to comment.