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

Proper implementation of 'succ'/'pred' handling. #356

Closed
p6rt opened this issue Oct 3, 2008 · 14 comments
Closed

Proper implementation of 'succ'/'pred' handling. #356

p6rt opened this issue Oct 3, 2008 · 14 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Oct 3, 2008

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

Searchable as RT59596$

@p6rt
Copy link
Author

p6rt commented Oct 3, 2008

From @masak

Rakudo r31589 does not follow S03 in deferring ++ to a user-defined
.succ method.

$ ./perl6 -e 'class A { method succ { say "OH HAI" } }; my $a = A.new; $a++'
increment() not implemented in class 'A'
[...]
Segmentation fault

This is mostly a question of a TODO, but it's also interesting to note
that this error produces another segmentation fault due to a double
free in Parrot.

@p6rt
Copy link
Author

p6rt commented Oct 11, 2008

From @masak

On Fri Oct 03 07​:39​:35 2008, masak wrote​:

Rakudo r31589 does not follow S03 in deferring ++ to a user-defined
.succ method.

Fixed as r31877. Also added four tests to
t/spec/S03-operators/autoincrement.t which succeed on the implemented
behaviour.

@p6rt
Copy link
Author

p6rt commented Oct 11, 2008

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

@p6rt
Copy link
Author

p6rt commented Oct 21, 2008

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

@p6rt
Copy link
Author

p6rt commented Oct 21, 2008

From @pmichaud

Reopening ticket because the patch applied isn't a correct implementation.

What should happen instead is that we
define the 'increment' and 'decrement' vtable functions in Object
to make use of the '.succ' and '.pred' methods.

Also, this patch relies on 'succ' and 'pred' being inplace
modifiers, but they are not defined that way in the Synopses.
$foo.succ should return the successor to $foo without modifying $foo.

Lastly, I'm not a fan of the exception handling approach being
used with find_method here. If the method doesn't exist,
that's the exception that should be thrown, not some other
exception or oddity that might occur from the 'inc' opcode.

Pm

@p6rt
Copy link
Author

p6rt commented Nov 7, 2008

From @bacek

Hello.

There is MMD based implementation of 'succ'/'pred' handling.

--
Bacek

@p6rt
Copy link
Author

p6rt commented Nov 7, 2008

From @bacek

succ_pred.patch
commit a47517ca10be429faabf3383b453c9c93262ab04
Author: Vasily Chekalkin <bacek@haste.optusnet.com.au>
Date:   Fri Nov 7 15:55:49 2008 +1100

    Revert "[rakudo] prefix/postfix ++ and -- now delegate to succ and pred, respectively"
    
    This reverts commit 48058ab367d5086e98d63edea4ce1a25c784ba25.
    
    Conflicts:

diff --git a/languages/perl6/src/builtins/op.pir b/languages/perl6/src/builtins/op.pir
index e256b6a..92c4eb7 100644
--- a/languages/perl6/src/builtins/op.pir
+++ b/languages/perl6/src/builtins/op.pir
@@ -31,47 +31,28 @@ src/builtins/op.pir - Perl6 builtin operators
 .sub 'postfix:++' :multi(_)
     .param pmc a
     $P0 = clone a
-    'prefix:++'(a)
+    inc a
     .return ($P0)
 .end
 
 .sub 'postfix:--' :multi(_)
     .param pmc a
     $P0 = clone a
-    'prefix:--'(a)
+    dec a
     .return ($P0)
 .end
 
 
 .sub 'prefix:++' :multi(_)
     .param pmc a
-    push_eh do_inc
-    $P1 = find_method a, "succ"
-    pop_eh
-    a.$P1()
-    goto done
-
-  do_inc:
-    pop_eh
     inc a
-
-  done:
     .return (a)
 .end
 
 
 .sub 'prefix:--' :multi(_)
     .param pmc a
-    push_eh do_dec
-    $P1 = find_method a, "pred"
-    pop_eh
-    a.$P1()
-    goto done
-
-  do_dec:
-    pop_eh
     dec a
-  done:
     .return (a)
 .end
 
diff --git a/languages/perl6/src/classes/Object.pir b/languages/perl6/src/classes/Object.pir
index fea74bc..6a57c0c 100644
--- a/languages/perl6/src/classes/Object.pir
+++ b/languages/perl6/src/classes/Object.pir
@@ -167,6 +167,29 @@ Return a string representation of the object
 .end
 
 
+=item increment
+
+Override increment in Objects to use 'succ' method.
+
+=cut
+
+.sub '' :method :vtable('increment')
+    self = self.'succ'()
+    .return(self)
+.end
+
+=item decrement
+
+Override decrement in Objects to use 'pred' method.
+
+=cut
+
+.sub '' :method :vtable('decrement')
+    self = self.'pred'()
+    .return(self)
+.end
+
+
 =item new()
 
 Create a new object having the same class as the invocant.

@p6rt
Copy link
Author

p6rt commented Nov 7, 2008

From @bacek

Hello.

Revised version after pmichaud's comments.

--
Bacek

@p6rt
Copy link
Author

p6rt commented Nov 7, 2008

From @bacek

succ_pred2.patch
diff --git a/languages/perl6/src/builtins/op.pir b/languages/perl6/src/builtins/op.pir
index e256b6a..92c4eb7 100644
--- a/languages/perl6/src/builtins/op.pir
+++ b/languages/perl6/src/builtins/op.pir
@@ -31,47 +31,28 @@ src/builtins/op.pir - Perl6 builtin operators
 .sub 'postfix:++' :multi(_)
     .param pmc a
     $P0 = clone a
-    'prefix:++'(a)
+    inc a
     .return ($P0)
 .end
 
 .sub 'postfix:--' :multi(_)
     .param pmc a
     $P0 = clone a
-    'prefix:--'(a)
+    dec a
     .return ($P0)
 .end
 
 
 .sub 'prefix:++' :multi(_)
     .param pmc a
-    push_eh do_inc
-    $P1 = find_method a, "succ"
-    pop_eh
-    a.$P1()
-    goto done
-
-  do_inc:
-    pop_eh
     inc a
-
-  done:
     .return (a)
 .end
 
 
 .sub 'prefix:--' :multi(_)
     .param pmc a
-    push_eh do_dec
-    $P1 = find_method a, "pred"
-    pop_eh
-    a.$P1()
-    goto done
-
-  do_dec:
-    pop_eh
     dec a
-  done:
     .return (a)
 .end
 
diff --git a/languages/perl6/src/classes/Object.pir b/languages/perl6/src/classes/Object.pir
index b2724b8..4b09b56 100644
--- a/languages/perl6/src/classes/Object.pir
+++ b/languages/perl6/src/classes/Object.pir
@@ -145,6 +145,31 @@ Return true if the object is defined.
 .end
 
 
+=item increment
+
+Override increment in Objects to use 'succ' method.
+
+=cut
+
+.sub '' :method :vtable('increment')
+    $P0 = self.'succ'()
+    self.'infix:='($P0)
+    .return(self)
+.end
+
+=item decrement
+
+Override decrement in Objects to use 'pred' method.
+
+=cut
+
+.sub '' :method :vtable('decrement')
+    $P0 = self.'pred'()
+    self.'infix:='($P0)
+    .return(self)
+.end
+
+
 =item new()
 
 Create a new object having the same class as the invocant.

@p6rt
Copy link
Author

p6rt commented Nov 7, 2008

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

@p6rt
Copy link
Author

p6rt commented Nov 8, 2008

From @bacek

And again...

@p6rt
Copy link
Author

p6rt commented Nov 8, 2008

From @bacek

succ_pred3.patch
diff --git a/languages/perl6/src/builtins/op.pir b/languages/perl6/src/builtins/op.pir
index e256b6a..92c4eb7 100644
--- a/languages/perl6/src/builtins/op.pir
+++ b/languages/perl6/src/builtins/op.pir
@@ -31,47 +31,28 @@ src/builtins/op.pir - Perl6 builtin operators
 .sub 'postfix:++' :multi(_)
     .param pmc a
     $P0 = clone a
-    'prefix:++'(a)
+    inc a
     .return ($P0)
 .end
 
 .sub 'postfix:--' :multi(_)
     .param pmc a
     $P0 = clone a
-    'prefix:--'(a)
+    dec a
     .return ($P0)
 .end
 
 
 .sub 'prefix:++' :multi(_)
     .param pmc a
-    push_eh do_inc
-    $P1 = find_method a, "succ"
-    pop_eh
-    a.$P1()
-    goto done
-
-  do_inc:
-    pop_eh
     inc a
-
-  done:
     .return (a)
 .end
 
 
 .sub 'prefix:--' :multi(_)
     .param pmc a
-    push_eh do_dec
-    $P1 = find_method a, "pred"
-    pop_eh
-    a.$P1()
-    goto done
-
-  do_dec:
-    pop_eh
     dec a
-  done:
     .return (a)
 .end
 
diff --git a/languages/perl6/src/classes/Object.pir b/languages/perl6/src/classes/Object.pir
index b2724b8..4b09b56 100644
--- a/languages/perl6/src/classes/Object.pir
+++ b/languages/perl6/src/classes/Object.pir
@@ -145,6 +145,31 @@ Return true if the object is defined.
 .end
 
 
+=item increment
+
+Override increment in Objects to use 'succ' method.
+
+=cut
+
+.sub '' :method :vtable('increment')
+    $P0 = self.'succ'()
+    'infix:='(self, $P0)
+    .return(self)
+.end
+
+=item decrement
+
+Override decrement in Objects to use 'pred' method.
+
+=cut
+
+.sub '' :method :vtable('decrement')
+    $P0 = self.'pred'()
+    'infix:='(self, $P0)
+    .return(self)
+.end
+
+
 =item new()
 
 Create a new object having the same class as the invocant.

@p6rt
Copy link
Author

p6rt commented Nov 9, 2008

From @moritz

On Fri Nov 07 17​:47​:48 2008, bacek wrote​:

And again...

Applied as r32473, thanks.

Moritz

@p6rt
Copy link
Author

p6rt commented Nov 9, 2008

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

@p6rt p6rt closed this as completed Nov 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