Author: jonathan
Date: Fri Mar 28 12:15:24 2008
New Revision: 26599

Added:
   trunk/languages/perl6/src/classes/IO.pir   (contents, props changed)
Modified:
   trunk/languages/perl6/config/makefiles/root.in
   trunk/languages/perl6/src/builtins/io.pir
   trunk/languages/perl6/src/builtins/misc.pir
   trunk/languages/perl6/src/parser/grammar-oper.pg

Log:
[rakudo] Start sticking in some bits of file I/O. open, which returns the new 
IO object, and has methods .print, .say and .close. prefix:= added too, but 
looks like Parrot IO iterator maybe isn't done yet. It's a start, anyway.

Modified: trunk/languages/perl6/config/makefiles/root.in
==============================================================================
--- trunk/languages/perl6/config/makefiles/root.in      (original)
+++ trunk/languages/perl6/config/makefiles/root.in      Fri Mar 28 12:15:24 2008
@@ -43,6 +43,7 @@
   src/classes/Str.pir \
   src/classes/Num.pir \
   src/classes/Int.pir \
+  src/classes/IO.pir \
   src/classes/List.pir \
   src/classes/Hash.pir \
   src/classes/Code.pir \

Modified: trunk/languages/perl6/src/builtins/io.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/io.pir   (original)
+++ trunk/languages/perl6/src/builtins/io.pir   Fri Mar 28 12:15:24 2008
@@ -76,6 +76,42 @@
     p6compiler.'evalfiles'(filename)
 .end
 
+.sub 'open'
+    .param string filename
+    .param int r :named('r') :optional
+    .param int w :named('w') :optional
+    .param int a :named('a') :optional
+
+    # Work out a mode string. XXX Default to r?
+    .local string mode
+    if r goto is_read
+    if w goto is_write
+    if a goto is_append
+is_read:
+    mode = "<"
+    goto done_mode
+is_write:
+    mode = ">"
+    goto done_mode
+is_append:
+    mode = ">>"
+    goto done_mode
+done_mode:
+
+    # Open file to get PIO file handle.
+    $P0 = open filename, mode
+    if $P0 goto opened_ok
+    'die'("Unable to open file") # XXX better message
+opened_ok:
+
+    # Create IO object and set handle.
+    .local pmc obj
+    obj = get_hll_global 'IO'
+    obj = obj.'new'()    
+    setattribute obj, "$!PIO", $P0
+    .return(obj)
+.end
+
 =back
 
 =cut

Modified: trunk/languages/perl6/src/builtins/misc.pir
==============================================================================
--- trunk/languages/perl6/src/builtins/misc.pir (original)
+++ trunk/languages/perl6/src/builtins/misc.pir Fri Mar 28 12:15:24 2008
@@ -6,6 +6,12 @@
 
 =cut
 
+.sub 'prefix:='
+    .param pmc what
+    $P0 = iter what
+    .return($P0)
+.end
+
 .sub 'WHAT'
     .param pmc x
     .return x.'WHAT'()

Added: trunk/languages/perl6/src/classes/IO.pir
==============================================================================
--- (empty file)
+++ trunk/languages/perl6/src/classes/IO.pir    Fri Mar 28 12:15:24 2008
@@ -0,0 +1,107 @@
+## $Id: $
+
+=head1 TITLE
+
+IO - Perl 6 IO class
+
+=head1 DESCRIPTION
+
+This file implements the IO file handle class.
+
+=head1 Methods
+
+=over 4
+
+=cut
+
+.namespace ['IO']
+
+.sub 'onload' :anon :init :load
+    $P0 = subclass 'Perl6Object', 'IO'
+    addattribute $P0, "$!PIO" # for Parrot IO object
+    $P1 = get_hll_global ['Perl6Object'], 'make_proto'
+    $P1($P0, 'IO')
+.end
+
+
+=item print
+
+Writes the given list of items to the file.
+
+=cut
+
+.sub 'print' :method
+    .param pmc args            :slurpy
+    .local pmc iter
+    .local pmc PIO
+    PIO = getattribute self, "$!PIO"
+    args = 'list'(args)
+    iter = new 'Iterator', args
+  iter_loop:
+    unless iter goto iter_end
+    $S0 = shift iter
+    print PIO, $S0
+    goto iter_loop
+  iter_end:
+    .return (1)
+.end
+
+
+=item say
+
+Writes the given list of items to the file, then a newline character.
+
+=cut
+
+.sub 'say' :method
+    .param pmc list            :slurpy
+    .local pmc PIO
+    PIO = getattribute self, "$!PIO"
+    self.'print'(list)
+    print PIO, "\n"
+    .return (1)
+.end
+
+
+=item close
+
+Closes the file.
+
+=cut
+
+.sub 'close' :method
+    .local pmc PIO
+    PIO = getattribute self, "$!PIO"
+    close PIO
+    .return(1)
+.end
+
+
+=item get_iter (vtable)
+
+Gets an iterator for this IO handle.
+
+=cut
+
+.sub 'get_iter' :method :vtable
+    .local pmc PIO
+    PIO = getattribute self, "$!PIO"
+    $P0 = iter PIO
+    .return($P0)
+.end
+
+
+=item say
+
+
+
+
+=back
+
+=cut
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:

Modified: trunk/languages/perl6/src/parser/grammar-oper.pg
==============================================================================
--- trunk/languages/perl6/src/parser/grammar-oper.pg    (original)
+++ trunk/languages/perl6/src/parser/grammar-oper.pg    Fri Mar 28 12:15:24 2008
@@ -19,6 +19,7 @@
 proto prefix:<+^> is equiv(prefix:<+>)
     is pirop('n_bnot')
     { ... }
+proto prefix:<=> is equiv(prefix:<+>) { ... }
 
 ## multiplicative operators
 proto infix:<*> is precedence('u=') { ... }

Reply via email to