develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34594 - in branches/rvar/languages/perl6/src: builtins classes

From:
pmichaud
Date:
December 29, 2008 14:35
Subject:
[svn:parrot] r34594 - in branches/rvar/languages/perl6/src: builtins classes
Message ID:
20081229223505.62EBDCB9FA@x12.develooper.com
Author: pmichaud
Date: Mon Dec 29 14:35:04 2008
New Revision: 34594

Modified:
   branches/rvar/languages/perl6/src/builtins/assign.pir
   branches/rvar/languages/perl6/src/builtins/guts.pir
   branches/rvar/languages/perl6/src/classes/Array.pir
   branches/rvar/languages/perl6/src/classes/Hash.pir
   branches/rvar/languages/perl6/src/classes/Object.pir
   branches/rvar/languages/perl6/src/classes/Signature.pir

Log:
[rakudo]:  Fix a brain-o; we can't have Scalar(), Array(), Hash() subs
because those are actually types.  So work around it for now.


Modified: branches/rvar/languages/perl6/src/builtins/assign.pir
==============================================================================
--- branches/rvar/languages/perl6/src/builtins/assign.pir	(original)
+++ branches/rvar/languages/perl6/src/builtins/assign.pir	Mon Dec 29 14:35:04 2008
@@ -16,7 +16,7 @@
     .param pmc cont
     .param pmc source
 
-    source = 'Scalar'(source)
+    source = '!CALLMETHOD'('Scalar', source)
     .local pmc ro, type
     getprop ro, 'readonly', cont
     if null ro goto ro_ok

Modified: branches/rvar/languages/perl6/src/builtins/guts.pir
==============================================================================
--- branches/rvar/languages/perl6/src/builtins/guts.pir	(original)
+++ branches/rvar/languages/perl6/src/builtins/guts.pir	Mon Dec 29 14:35:04 2008
@@ -58,6 +58,36 @@
 .end
 
 
+=item !CALLMETHOD('method', obj)
+
+Invoke a method on a possibly foreign object.  If the object
+supports the requested method, we use it, otherwise we assume
+the object is foreign and try using the corresponding method
+from C<Any>.
+
+=cut
+
+.namespace []
+.sub '!CALLMETHOD'
+    .param string method
+    .param pmc obj
+    $I0 = isa obj, 'ObjectRef'
+    if $I0 goto any_method
+    $I0 = can obj, method
+    unless $I0 goto any_method
+    .tailcall obj.method()
+  any_method:
+    .local pmc anyobj
+    anyobj = get_global '$!ANY'
+    unless null anyobj goto any_method_1
+    anyobj = new 'Any'
+    set_global '$!ANY', anyobj
+  any_method_1:
+    $P0 = find_method anyobj, method
+    .tailcall obj.$P0()
+.end
+
+
 =item !VAR
 
 Helper function for implementing the VAR and .VAR macros.

Modified: branches/rvar/languages/perl6/src/classes/Array.pir
==============================================================================
--- branches/rvar/languages/perl6/src/classes/Array.pir	(original)
+++ branches/rvar/languages/perl6/src/classes/Array.pir	Mon Dec 29 14:35:04 2008
@@ -251,7 +251,7 @@
   array_loop:
     unless it goto array_done
     $P0 = shift it
-    $P0 = 'Scalar'($P0)
+    $P0 = '!CALLMETHOD'('Scalar',$P0)
     $P0 = clone $P0
     push array, $P0
     goto array_loop

Modified: branches/rvar/languages/perl6/src/classes/Hash.pir
==============================================================================
--- branches/rvar/languages/perl6/src/classes/Hash.pir	(original)
+++ branches/rvar/languages/perl6/src/classes/Hash.pir	Mon Dec 29 14:35:04 2008
@@ -130,7 +130,7 @@
     key = elem.'key'()
     value = elem.'value'()
   iter_kv:
-    value = 'Scalar'(value)
+    value = '!CALLMETHOD'('Scalar', value)
     hash[key] = value
     goto iter_loop
   iter_hash:
@@ -140,7 +140,7 @@
     unless hashiter goto hashiter_done
     $S0 = shift hashiter
     value = elem[$S0]
-    value = 'Scalar'(value)
+    value = '!CALLMETHOD'('Scalar', value)
     value = clone value
     hash[$S0] = value
     goto hashiter_loop

Modified: branches/rvar/languages/perl6/src/classes/Object.pir
==============================================================================
--- branches/rvar/languages/perl6/src/classes/Object.pir	(original)
+++ branches/rvar/languages/perl6/src/classes/Object.pir	Mon Dec 29 14:35:04 2008
@@ -200,20 +200,6 @@
     .return ($P0)
 .end
 
-.namespace []
-.sub 'Array'
-    .param pmc source
-    $I0 = isa source, 'ObjectRef'
-    if $I0 goto make_array
-    $I0 = can source, 'Array'
-    unless $I0 goto make_array
-    .tailcall source.'Array'()
-  make_array:
-    $P0 = new 'Perl6Array'
-    $P0.'!STORE'(source)
-    .return ($P0)
-.end
-
 =item Hash()
 
 =cut
@@ -225,20 +211,6 @@
     .return ($P0)
 .end
 
-.namespace []
-.sub 'Hash'
-    .param pmc source
-    $I0 = isa source, 'ObjectRef'
-    if $I0 goto make_hash
-    $I0 = can source, 'Hash'
-    unless $I0 goto make_hash
-    .tailcall source.'Hash'()
-  make_hash:
-    $P0 = new 'Perl6Hash'
-    $P0.'!STORE'(source)
-    .return ($P0)
-.end
-
 =item Iterator()
 
 =cut
@@ -265,21 +237,6 @@
     .return ($P0)
 .end
 
-.namespace []
-.sub 'Scalar'
-    .param pmc source
-    $I0 = isa source, 'ObjectRef'
-    if $I0 goto done
-    $I0 = can source, 'Scalar'
-    if $I0 goto can_scalar
-    $I0 = does source, 'scalar'
-    source = new 'ObjectRef', source
-  done:
-    .return (source)
-  can_scalar:
-    .tailcall source.'Scalar'()
-.end
-
 =item Str()
 
 Return a string representation of the invocant.  Default is

Modified: branches/rvar/languages/perl6/src/classes/Signature.pir
==============================================================================
--- branches/rvar/languages/perl6/src/classes/Signature.pir	(original)
+++ branches/rvar/languages/perl6/src/classes/Signature.pir	Mon Dec 29 14:35:04 2008
@@ -201,7 +201,7 @@
     orig = callerlex[name]
     if sigil == '@' goto param_array
     if sigil == '%' goto param_hash
-    var = 'Scalar'(orig)
+    var = '!CALLMETHOD'('Scalar', orig)
     ##  typecheck the argument
     if null type goto param_val_done
     .lex '$/', $P99
@@ -209,10 +209,10 @@
     unless $P0 goto err_param_type
     goto param_val_done
   param_array:
-    var = 'Array'(orig)
+    var = '!CALLMETHOD'('Array', orig)
     goto param_val_done
   param_hash:
-    var = 'Hash'(orig)
+    var = '!CALLMETHOD'('Hash', orig)
   param_val_done:
     ## handle readonly/copy traits
     $S0 = param['readtype']



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About