Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implemented IO.ins
  • Loading branch information
Carl Masak committed Apr 6, 2009
1 parent a04f610 commit e83b2b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/classes/IO.pir
Expand Up @@ -14,7 +14,7 @@ This file implements the IO file handle class.
.sub '' :anon :init :load
.local pmc p6meta
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
$P0 = p6meta.'new_class'('IO', 'parent'=>'Any', 'attr'=>'$!PIO')
$P0 = p6meta.'new_class'('IO', 'parent'=>'Any', 'attr'=>'$!PIO $!ins')
$P0.'!MUTABLE'()
p6meta.'new_class'('IOIterator', 'parent'=>'Perl6Object', 'attr'=>'$!IO')

Expand Down Expand Up @@ -77,9 +77,12 @@ Read a single line and return it.

.namespace ['IOIterator']
.sub 'item' :method :vtable('shift_pmc')
.local pmc pio, chomper
.local pmc pio, ins, chomper
$P0 = getattribute self, "$!IO"
pio = getattribute $P0, "$!PIO"
ins = getattribute $P0, "$!ins"
'prefix:++'(ins)
setattribute $P0, "$!ins", ins
pio = '!DEREF'(pio)
$P0 = pio.'readline'()
chomper = get_hll_global 'chomp'
Expand All @@ -94,14 +97,17 @@ Read all of the lines and return them as a List.
.namespace ['IOIterator']
.sub 'list' :method
.local pmc pio, res, chomper
.local pmc pio, ins, res, chomper
$P0 = getattribute self, "$!IO"
pio = getattribute $P0, "$!PIO"
pio = '!DEREF'(pio)
res = new 'List'
chomper = get_hll_global 'chomp'
loop:
ins = getattribute $P0, "$!ins"
'prefix:++'(ins)
setattribute $P0, "$!ins", ins
$S0 = pio.'readline'()
if $S0 == '' goto done
$S0 = chomper($S0)
Expand Down
4 changes: 4 additions & 0 deletions src/setting/IO.pm
Expand Up @@ -11,6 +11,10 @@ class IO is also {
return ?$!PIO.eof();
}

multi method ins() {
return $!ins;
}

multi method lines() is export {
my @result = ();
while !$.eof {
Expand Down

0 comments on commit e83b2b8

Please sign in to comment.