Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0-array and 1-array composer broken #67

Closed
p6rt opened this issue Mar 30, 2008 · 9 comments
Closed

0-array and 1-array composer broken #67

p6rt opened this issue Mar 30, 2008 · 9 comments

Comments

@p6rt
Copy link

p6rt commented Mar 30, 2008

Migrated from rt.perl.org#52276 (status was 'resolved')

Searchable as RT52276$

@p6rt
Copy link
Author

p6rt commented Mar 30, 2008

From @cognominal

but n-array composer with n > 1 works correctly

$ alias rakudo
alias rakudo='./parrot languages/perl6/perl6.pbc'
$ rakudo -e 'my @​a = [1]; say @​a[0]'
get_pmc_keyed() not implemented in class 'Integer'
current instr.​: '_block10' pc 44 (EVAL_11​:25)
called from Sub 'parrot;PCT​::HLLCompiler;eval' pc 823
(src/PCT/HLLCompiler.pir​:476)
called from Sub 'parrot;PCT​::HLLCompiler;command_line' pc 1314
(src/PCT/HLLCompiler.pir​:704)
called from Sub 'parrot;Perl6​::Compiler;main' pc 8199 (perl6.pir​:169)

$ rakudo -e 'my @​a = []; say @​a[0]'
error​:imcc​:syntax error, unexpected COMMA (',')
  in file 'EVAL_11' line 15
error​:imcc​:syntax error, unexpected '\n'
  in file 'EVAL_11' line 17
get_pmc_keyed() not implemented in class 'Undef'
current instr.​: '_block10' pc 31 (EVAL_11​:23)
called from Sub 'parrot;PCT​::HLLCompiler;eval' pc 823
(src/PCT/HLLCompiler.pir​:476)
called from Sub 'parrot;PCT​::HLLCompiler;command_line' pc 1314
(src/PCT/HLLCompiler.pir​:704)
called from Sub 'parrot;Perl6​::Compiler;main' pc 8199 (perl6.pir​:169)

$ rakudo -e 'my @​a = [1,2]; say @​a[1]'
2

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented May 18, 2008

From @cognominal

This fixes the bug but does not handle multidimensional arrays.
It is dependant on the included nqp patch

Index​: languages/perl6/src/parser/actions.pm

==========
--- languages/perl6/src/parser/actions.pm (revision 27594)
+++ languages/perl6/src/parser/actions.pm (working copy)
@​@​ -1629,12 +1629,19 @​@​

method circumfix($/, $key) {
  my $past;
- if $key eq '( )' {
- $past := $( $<statementlist> );
+ if $key eq '[ ]' or $key eq '( )' {
+ my $statement := $&lt;statementlist><statement>;
+ if +$statement == 1 {
+ if $statement[0]<expr><expr><type> eq 'infix​:,' {
+ $past := $( $<statementlist> );
+ } else {
+ $past := PAST​::Op.new( :node($/), :name('list'),
:pasttype('call') );
+ $past.push( $( $statement<expr> ) );
+ }
+ } else {
+ $past := PAST​::Op.new( :node($/), :name('list'),
:pasttype('call') );
+ }
  }
- if $key eq '[ ]' {
- $past := $( $<statementlist> );
- }
  elsif $key eq '{ }' {
  $past := $( $<pblock> );
  }

Index​: compilers/nqp/src/Grammar.pg

==========
--- compilers/nqp/src/Grammar.pg (revision 27594)
+++ compilers/nqp/src/Grammar.pg (working copy)
@​@​ -487,3 +487,11 @​@​
  is nullterm
  { ... }

+## loose logical operators
+proto infix​:<and> is looser(infix​:<,>)
+ is pasttype('if')
+ { .... }
+
+proto infix​:<or> is looser(infix​:<and>)
+ is pasttype('unless')
+ { ... }

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented May 18, 2008

@cognominal - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 18, 2008

From @cognominal

it seems that lines have been folded. So I attach the diff here

@p6rt
Copy link
Author

p6rt commented May 18, 2008

From @cognominal

array_composer.diff
Index: languages/perl6/src/parser/actions.pm
===================================================================
--- languages/perl6/src/parser/actions.pm	(revision 27594)
+++ languages/perl6/src/parser/actions.pm	(working copy)
@@ -1629,12 +1629,19 @@
 
 method circumfix($/, $key) {
     my $past;
-    if $key eq '( )' {
-        $past := $( $<statementlist> );
+    if $key eq '[ ]' or $key eq '( )' {
+        my $statement := $<statementlist><statement>;
+        if +$statement  == 1 {
+            if $statement[0]<expr><expr><type> eq 'infix:,' {
+                $past := $( $<statementlist> );
+            } else {
+                $past := PAST::Op.new( :node($/), :name('list'), :pasttype('call') );
+                $past.push( $( $statement<expr> ) );
+            }
+        } else {
+           $past := PAST::Op.new( :node($/), :name('list'), :pasttype('call') );
+        }
     }
-    if $key eq '[ ]' {
-        $past := $( $<statementlist> );
-    }
     elsif $key eq '{ }' {
         $past := $( $<pblock> );
     }
Index: compilers/nqp/src/Grammar.pg
===================================================================
--- compilers/nqp/src/Grammar.pg	(revision 27594)
+++ compilers/nqp/src/Grammar.pg	(working copy)
@@ -487,3 +487,11 @@
     is nullterm
     { ... }
 
+## loose logical operators
+proto infix:<and> is looser(infix:<,>)
+    is pasttype('if')
+    { .... } 
+
+proto infix:<or> is looser(infix:<and>)
+    is pasttype('unless')
+    { ... }

@p6rt
Copy link
Author

p6rt commented May 18, 2008

From @cognominal

This fix the bug but does not handle multidimensional arrays.
It is dependant on the nqp patch

Index​: languages/perl6/src/parser/actions.pm

--- languages/perl6/src/parser/actions.pm (revision 27594)
+++ languages/perl6/src/parser/actions.pm (working copy)
@​@​ -1629,12 +1629,19 @​@​

method circumfix($/, $key) {
  my $past;
- if $key eq '( )' {
- $past := $( $<statementlist> );
+ if $key eq '[ ]' or $key eq '( )' {
+ my $statement := $&lt;statementlist><statement>;
+ if +$statement == 1 {
+ if $statement[0]<expr><expr><type> eq 'infix​:,' {
+ $past := $( $<statementlist> );
+ } else {
+ $past := PAST​::Op.new( :node($/), :name('list'),
:pasttype('call') );
+ $past.push( $( $statement<expr> ) );
+ }
+ } else {
+ $past := PAST​::Op.new( :node($/), :name('list'),
:pasttype('call') );
+ }
  }
- if $key eq '[ ]' {
- $past := $( $<statementlist> );
- }
  elsif $key eq '{ }' {
  $past := $( $<pblock> );
  }

Index​: compilers/nqp/src/Grammar.pg

--- compilers/nqp/src/Grammar.pg (revision 27594)
+++ compilers/nqp/src/Grammar.pg (working copy)
@​@​ -487,3 +487,11 @​@​
  is nullterm
  { ... }

+## loose logical operators
+proto infix​:<and> is looser(infix​:<,>)
+ is pasttype('if')
+ { .... }
+
+proto infix​:<or> is looser(infix​:<and>)
+ is pasttype('unless')
+ { ... }

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented May 19, 2008

From @pmichaud

On Sun May 18 15​:57​:25 2008, cognominal wrote​:

This fix the bug but does not handle multidimensional arrays.
It is dependant on the nqp patch

I've committed the nqp patch in r27647, thanks.

As far as the array composer goes, I can't really accept the patch
as-is. For one, it causes everything in parens to be treated as a list,
but an expression such as (3) or (3+4) shouldn't be treated as a list.
In particular, with this patch in place we get an error for mathematical
expressions involved parens, such as 5 * (3 + 2).

What really needs to happen here is to introduce a "list" past node type
into PCT, and to eliminate a lot of the direct references to "infix​:,"
in actions.pm . I know that people were using "infix​:," to make things
work, but it's fundamentally flawed to have it occurring as much as it
is. I hope to get infix​:, past generation fixed in the next couple of
days, and then we can revisit the array composers. Perhaps we'll soon
have list assignments working as well (it's high on the ROADMAP at the
moment).

Thanks!

Pm

@p6rt
Copy link
Author

p6rt commented May 29, 2008

From @pmichaud

Fixed in r27917, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented May 29, 2008

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 29, 2008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant