fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / ops / io.ops
blob203d50cccebdda534fd4b9abd7dd45ee8d4fb265
1 /*
2  * $Id$
3  * Copyright (C) 2002-2008, Parrot Foundation.
4 ** io.ops
5 */
7 BEGIN_OPS_PREAMBLE
8 #include "../io/io_private.h"
9 END_OPS_PREAMBLE
12 =head1 NAME
14 io.ops - I/O Opcodes
16 =cut
18 =head1 DESCRIPTION
20 Parrot's IO API
22 When making changes to any ops file, run C<make bootstrap-ops> to regenerate
23 all generated ops files.
25 =cut
27 ###############################################################################
29 =head2 Parrot IO API Operations
31 =over 4
33 =cut
35 ########################################
37 =item B<print>(in INT)
39 =item B<print>(in NUM)
41 =item B<print>(invar PMC)
43 =item B<print>(in STR)
45 Print $1 to standard output.
47 =cut
49 inline op print(in INT) :base_io {
50     Parrot_io_printf(interp, INTVAL_FMT, (INTVAL)$1);
53 inline op print(in NUM) :base_io {
54 #ifdef PARROT_HAS_NEGATIVE_ZERO
55     Parrot_io_printf(interp, FLOATVAL_FMT, $1);
56 #else
57     /* Workaround for older msvcrt and openbsd. TT #313 */
58     if (Parrot_is_nzero($1)) {
59         Parrot_io_printf(interp, "-0");
60     }
61     else {
62         Parrot_io_printf(interp, FLOATVAL_FMT, $1);
63     }
64 #endif
67 op print(in STR) :base_io {
68     STRING * const s = $1;
69     if (s && Parrot_str_byte_length(interp, s))
70         Parrot_io_putps(interp, _PIO_STDOUT(interp), s);
73 op print(invar PMC) :base_io {
74     PMC * const p = $1;
75     STRING * const s = (VTABLE_get_string(interp, p));
76     if (s)
77         Parrot_io_putps(interp, _PIO_STDOUT(interp), s);
80 =item B<say>(in INT)
82 =item B<say>(in NUM)
84 =item B<say>(invar PMC)
86 =item B<say>(in STR)
88 Print $1 to standard output with a trailing newline.
90 =cut
92 inline op say(in INT) :base_io {
93     Parrot_io_printf(interp, INTVAL_FMT "\n", (INTVAL)$1);
96 inline op say(in NUM) :base_io {
97 #ifdef PARROT_HAS_NEGATIVE_ZERO
98     Parrot_io_printf(interp, FLOATVAL_FMT "\n", $1);
99 #else
100     /* Workaround for older msvcrt and openbsd. TT #313 */
101     if (Parrot_is_nzero($1)) {
102         Parrot_io_printf(interp, "-0\n");
103     }
104     else {
105         Parrot_io_printf(interp, FLOATVAL_FMT "\n", $1);
106     }
107 #endif
110 op say(in STR) :base_io {
111     STRING * const s = $1;
112     if (s && Parrot_str_byte_length(interp, s))
113         Parrot_io_putps(interp, _PIO_STDOUT(interp), s);
114     Parrot_io_putps(interp, _PIO_STDOUT(interp), Parrot_str_new_constant(interp, "\n"));
117 op say(invar PMC) :base_io {
118     PMC * const p = $1;
120     if (PMC_IS_NULL(p)) {
121         opcode_t *handler = Parrot_ex_throw_from_op_args(interp, expr NEXT(),
122              EXCEPTION_UNEXPECTED_NULL,
123             "Null PMC in say");
124         goto ADDRESS(handler);
125     }
126     else {
127         STRING * const s = VTABLE_get_string(interp, p);
128         if (s)
129             Parrot_io_putps(interp, _PIO_STDOUT(interp), s);
130         Parrot_io_putps(interp, _PIO_STDOUT(interp), Parrot_str_new_constant(interp, "\n"));
131     }
137 ##########################################
139 =item B<print>(invar PMC, in INT)
141 =item B<print>(invar PMC, in NUM)
143 =item B<print>(invar PMC, in STR)
145 =item B<print>(invar PMC, invar PMC)
147 Print $2 on the IO stream object $1.
149 =cut
151 op print(invar PMC, in INT) :base_io {
152     if ($1) {
153         STRING * const s = Parrot_str_from_int(interp, $2);
154         Parrot_io_putps(interp, $1, s);
155     }
158 op print(invar PMC, in NUM) :base_io {
159     if ($1) {
160         STRING * const s = Parrot_sprintf_c(interp, FLOATVAL_FMT, $2);
161         Parrot_io_putps(interp, $1, s);
162     }
165 op print(invar PMC, in STR) :base_io {
166     if ($2 && $1) {
167         Parrot_io_putps(interp, $1, $2);
168     }
171 op print(invar PMC, invar PMC) :base_io {
172     if ($2 && $1) {
173         STRING * const s = VTABLE_get_string(interp, $2);
174         Parrot_io_putps(interp, $1, s);
175     }
178 =item B<getstdin>(out PMC)
180 Create a new ParrotIO object for the stdin file descriptor and
181 store it in $1
183 =item B<getstdout>(out PMC)
185 Create a new ParrotIO object for the stdout file descriptor and
186 store it in $1
188 =item B<getstderr>(out PMC)
190 Create a new ParrotIO object for the stderr file descriptor and
191 store it in $1
193 =cut
195 inline op getstdin(out PMC) :base_io {
196     $1 = _PIO_STDIN(interp);
199 inline op getstdout(out PMC) :base_io {
200     $1 = _PIO_STDOUT(interp);
203 inline op getstderr(out PMC) :base_io {
204     $1 = _PIO_STDERR(interp);
207 ###############################################################################
210  * Local variables:
211  *   c-file-style: "parrot"
212  * End:
213  * vim: expandtab shiftwidth=4:
214  */