3 * Copyright (C) 2002-2008, Parrot Foundation.
8 #include "../io/io_private.h"
22 When making changes to any ops file, run C<make bootstrap-ops> to regenerate
23 all generated ops files.
27 ###############################################################################
29 =head2 Parrot IO API Operations
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.
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);
57 /* Workaround for older msvcrt and openbsd. TT #313 */
58 if (Parrot_is_nzero($1)) {
59 Parrot_io_printf(interp, "-0");
62 Parrot_io_printf(interp, FLOATVAL_FMT, $1);
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 {
75 STRING * const s = (VTABLE_get_string(interp, p));
77 Parrot_io_putps(interp, _PIO_STDOUT(interp), s);
84 =item B<say>(invar PMC)
88 Print $1 to standard output with a trailing newline.
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);
100 /* Workaround for older msvcrt and openbsd. TT #313 */
101 if (Parrot_is_nzero($1)) {
102 Parrot_io_printf(interp, "-0\n");
105 Parrot_io_printf(interp, FLOATVAL_FMT "\n", $1);
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 {
120 if (PMC_IS_NULL(p)) {
121 opcode_t *handler = Parrot_ex_throw_from_op_args(interp, expr NEXT(),
122 EXCEPTION_UNEXPECTED_NULL,
124 goto ADDRESS(handler);
127 STRING * const s = VTABLE_get_string(interp, p);
129 Parrot_io_putps(interp, _PIO_STDOUT(interp), s);
130 Parrot_io_putps(interp, _PIO_STDOUT(interp), Parrot_str_new_constant(interp, "\n"));
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.
151 op print(invar PMC, in INT) :base_io {
153 STRING * const s = Parrot_str_from_int(interp, $2);
154 Parrot_io_putps(interp, $1, s);
158 op print(invar PMC, in NUM) :base_io {
160 STRING * const s = Parrot_sprintf_c(interp, FLOATVAL_FMT, $2);
161 Parrot_io_putps(interp, $1, s);
165 op print(invar PMC, in STR) :base_io {
167 Parrot_io_putps(interp, $1, $2);
171 op print(invar PMC, invar PMC) :base_io {
173 STRING * const s = VTABLE_get_string(interp, $2);
174 Parrot_io_putps(interp, $1, s);
178 =item B<getstdin>(out PMC)
180 Create a new ParrotIO object for the stdin file descriptor and
183 =item B<getstdout>(out PMC)
185 Create a new ParrotIO object for the stdout file descriptor and
188 =item B<getstderr>(out PMC)
190 Create a new ParrotIO object for the stderr file descriptor and
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 ###############################################################################
211 * c-file-style: "parrot"
213 * vim: expandtab shiftwidth=4: