1 2=head1 DESCRIPTION 3 4Stream;Writer - a PIR sub as target for a Stream 5 6=head1 VERSION 7 8version 0.1 9 10=head1 SYNOPSIS 11 12 # create the stream 13 new stream, ['Stream'; 'Writer'] 14 15 # set the source sub 16 .const 'Sub' temp = "_reader" 17 stream."source"( temp ) 18 19 stream."write"( "hello, world" ) 20 21 ... 22 23 .sub _reader :method 24 .local string str 25 str = self."read"() 26 .end 27 28=cut 29 30.include "interpinfo.pasm" 31.namespace ['Stream'; 'Writer'] 32 33.sub __onload :load 34 $P0 = get_class ['Stream'; 'Writer'] 35 unless null $P0 goto END 36 37 load_bytecode 'Stream/Base.pbc' 38 39 get_class $P0, ['Stream'; 'Base'] 40 subclass $P1, $P0, ['Stream'; 'Writer'] 41 42 addattribute $P1, "writer" 43 addattribute $P1, "status" 44END: 45.end 46 47=head1 METHODS 48 49=over 4 50 51=cut 52 53.sub _reader_stub :method 54 .local pmc source 55 .local pmc mysub 56 #.local pmc myself 57 58 interpinfo mysub, .INTERPINFO_CURRENT_SUB 59 #interpinfo myself, .INTERPINFO_CURRENT_OBJECT 60 getprop source, mysub, "CALL" 61 source() 62 63 # close the source 64 source = get_hll_global ['Stream'; 'Base'], 'close' 65 self."setSource"() 66 67 # mark it as closed 68 .local pmc status 69 getattribute status, self, 'status' 70 status = 0 71.end 72 73.sub init :vtable :method 74 .local pmc status 75 76 new status, 'Integer' 77 set status, 0 78 setattribute self, 'status', status 79.end 80 81.sub set_pmc :vtable :method 82 .param pmc source 83 .local pmc status 84 85 .const 'Sub' stub = "_reader_stub" 86 setprop stub, "CALL", source 87 self."setSource"( stub ) 88 89 getattribute status, self, 'status' 90 status = 1 91.end 92 93.sub close :method 94 .local string str 95 96 null str 97LOOP: 98 $I0 = self."connected"() 99 unless $I0 goto END 100 self."write"( str ) 101 branch LOOP 102END: 103.end 104 105.sub connected :method 106 .local pmc status 107 .local int ret 108 109 getattribute status, self, 'status' 110 ret = status 111 .return(ret) 112.end 113 114=item source."write"() 115 116... 117 118=cut 119 120.sub write :method 121 .param string str 122 .local pmc source 123 .local pmc status 124 125 .include "interpinfo.pasm" 126 $P0 = interpinfo .INTERPINFO_CURRENT_CONT 127 setattribute self, 'writer', $P0 128 getattribute status, self, 'status' 129 130 if status == 0 goto END 131 if status == 2 goto WRITE 132 status = 2 133 self."write"( "" ) 134WRITE: 135 136 .include "interpinfo.pasm" 137 $P0 = interpinfo .INTERPINFO_CURRENT_CONT 138 setattribute self, 'writer', $P0 139 140 source = self."source"() 141 $I0 = defined source 142 unless $I0 goto END 143 144 source( str ) 145END: 146 .return() 147 goto WRITE # XXX else self gets overwritten by source 148.end 149 150=item source."rawRead"() (B<internal>) 151 152... 153 154=cut 155 156.sub rawRead :method 157 .local string str 158 .local pmc writer 159 .local pmc cont 160 161 cont = self."source"() 162 if_null cont, END_OF_STREAM 163 164 getattribute writer, self, 'writer' 165 str = self."_call_writer"(writer) 166 .return(str) 167END_OF_STREAM: 168 null writer 169 setattribute self, 'writer', writer 170 null str 171 172 .return(str) 173.end 174 175.sub _call_writer :method 176 .param pmc writer 177 .local pmc cont 178 .local string str 179 180 cont = interpinfo .INTERPINFO_CURRENT_CONT 181 self."setSource"( cont ) 182 str = writer() 183 .return(str) 184.end 185 186 187=back 188 189=head1 AUTHOR 190 191Jens Rieks E<lt>parrot at jensbeimsurfen dot deE<gt> is the author 192and maintainer. 193Please send patches and suggestions to the Perl 6 Internals mailing list. 194 195=head1 COPYRIGHT 196 197Copyright (C) 2004-2009, Parrot Foundation. 198 199=cut 200 201# Local Variables: 202# mode: pir 203# fill-column: 100 204# End: 205# vim: expandtab shiftwidth=4 ft=pir: 206