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

correction and extension of the pair implementation #63

Closed
p6rt opened this issue Mar 2, 2008 · 4 comments
Closed

correction and extension of the pair implementation #63

p6rt opened this issue Mar 2, 2008 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Mar 2, 2008

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

Searchable as RT51350$

@p6rt
Copy link
Author

p6rt commented Mar 2, 2008

From @cognominal

support of :a :!a and :$a, beginning of .perl method for Pair, .perl
method for Bool

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented Mar 2, 2008

From @cognominal

parrot_colonpair.patch
Index: languages/perl6/src/parser/actions.pm
===================================================================
--- languages/perl6/src/parser/actions.pm	(revision 26135)
+++ languages/perl6/src/parser/actions.pm	(working copy)
@@ -780,7 +780,10 @@
 }
 
 
-method scoped($/) {
+  method scoped($/) {
+    if $<typename> {
+        $/.panic('statically typed variables are not yet implemented');
+    }
     my $past := $( $<variable_decl> );
     make $past;
 }
@@ -1239,13 +1242,12 @@
     make $past;
 }
 
-
 method colonpair($/, $key) {
     my $pair_key;
     my $pair_val;
 
     if $key eq 'false' {
-        my $pair_key := PAST::Val.new( :value(~$<key>) );
+        $pair_key := PAST::Val.new( :value(~$<ident>) );
         $pair_val := PAST::Var.new(
             :name('False'),
             :namespace('Bool'),
@@ -1253,7 +1255,7 @@
         );
     }
     elsif $key eq 'value' {
-        my $pair_key := PAST::Val.new( :value(~$<key>) );
+        $pair_key := PAST::Val.new( :value(~$<ident>) );
         if $<postcircumfix> {
             # XXX TODO
             $/.panic('postcircumfix on colonpair not yet implemented');
@@ -1266,7 +1268,16 @@
             );
         }
     }
-    else {
+    elsif $key eq 'varname' {
+        my $nm  := $<variable><name>;
+        my $idx := $<variable><matchidx>;
+        # say $nm;
+        # if (! $nm || ! $idx ) {
+        #     $/.panic( "bad sigiled pair")
+        # }
+        $pair_key := PAST::Val.new( :value( ~$nm || ~$idx) );
+        $pair_val := $( $<variable> );
+    } else {
         $/.panic($key ~ " pairs not yet implemented.");
     }
 
Index: languages/perl6/src/parser/grammar.pg
===================================================================
--- languages/perl6/src/parser/grammar.pg	(revision 26135)
+++ languages/perl6/src/parser/grammar.pg	(working copy)
@@ -479,7 +479,7 @@
 
 
 rule scoped {
-    <variable_decl> {*}
+    <typename>? <variable_decl> {*}
 }
 
 rule scope_declarator {
@@ -657,10 +657,10 @@
 token colonpair {
     ':'
     [
-    | '!' <ident>                                        {*}    #= false
+     || '!' <ident>                                      {*}    #= false
     | <ident> [ <.unsp>? <postcircumfix> ]?              {*}    #= value
     | <postcircumfix>                                    {*}    #= structural
-    | <sigil> <twigil>? <desigilname>                    {*}    #= varname
+    | <variable>                                         {*}    #= varname
     ]
 }
 
Index: languages/perl6/src/classes/Bool.pir
===================================================================
--- languages/perl6/src/classes/Bool.pir	(revision 26135)
+++ languages/perl6/src/classes/Bool.pir	(working copy)
@@ -28,6 +28,14 @@
 .end
 
 
+.sub 'perl' :method
+     $I0 = $P0
+     if  $I0 goto true
+    .return ("False")
+true:
+    .return ("True")
+.end
+
 .sub 'ACCEPTS' :method
     .param pmc topic
     .return (self)
Index: languages/perl6/src/classes/Pair.pir
===================================================================
--- languages/perl6/src/classes/Pair.pir	(revision 26135)
+++ languages/perl6/src/classes/Pair.pir	(working copy)
@@ -17,6 +17,74 @@
     $P1('Pair', 'Pair')
 .end
 
+
+.sub get_string :method
+     $S0 = self.'perl'()
+     return ( $S0 )
+.end
+
+# should be pedagical and gives the smartest representation of a pair
+.sub perl :method
+     $P0 = self.'key'()    
+     $P1 = self.'value'()
+     $S0 = $P0.'WHAT'()
+     $S1 = $P1.'WHAT'()
+     if $S0 != 'Str' goto keyisnotstring
+     $S2 = $P0
+     $S3 = escape $S2
+     if $S3 != $S2 goto keyescaped
+     if $S1 != 'Bool' goto valnobool
+     $S5 = ":"
+     if $P1 goto trueval
+     concat $S5, "!"
+trueval:
+     concat $S5, $S2
+     .return ($S5)
+valnobool:
+     if $S1 == 'Str' goto valliteral
+     if $S1 == 'Int' goto valnum
+     if $S1 == 'Num' goto valnum
+     die "TBD"
+
+valliteral:
+     $S6 = ":" 
+     $S7 = $P0
+     concat $S6, $S7
+     concat $S6, '<' 
+     $S7 = $P1
+     concat $S6, $S7
+     concat $S6, '>'
+     .return ( $S6 )
+
+valnum:
+     $S6 = ":" 
+     $S7 = $P0
+     concat $S6, $S7
+     concat $S6, '(' 
+     $S7 = $P1
+     concat $S6, $S7
+     concat $S6, ')'
+     .return ( $S6 )
+
+
+keyescaped:
+     die "TBD"
+
+keyisnotstring:      
+     # ugly, probably not correct, certainly not yet supported
+     $S2 =  "{ (my $p=Pair.new()), "
+     concat $S2, "$p[ "
+     $S3 = $P0.perl()
+     concat $S2, $S3
+     concat $S2, "] = "
+     $S3 = $P1.perl()
+     concat $S2, $S3
+     concat $S3, "}"
+keyissnottring:
+     die "TBD"
+.end
+
+
 =back
 
 =cut

@p6rt
Copy link
Author

p6rt commented May 9, 2008

From @pmichaud

Events have since overtaken this patch, so marking it as resolved. If
the current version of Rakudo doesn't provide one of the capabilities,
feel free to re-submit the patch.

(Also, it's easier to comment+apply if separate features are submitted
as separate patches rather than combined into a single patch.)

Thanks for the patch!

Pm

@p6rt
Copy link
Author

p6rt commented May 9, 2008

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

@p6rt p6rt closed this as completed May 9, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant