39 #if MICROPY_PY_BUILTINS_FLOAT 43 static const char pad_spaces[] =
" ";
44 static const char pad_zeroes[] =
"0000000000000000";
64 int pad = width - len;
66 int total_chars_printed = 0;
67 const char *pad_chars;
69 if (!fill || fill ==
' ') {
70 pad_chars = pad_spaces;
71 pad_size =
sizeof(pad_spaces) - 1;
72 }
else if (fill ==
'0') {
73 pad_chars = pad_zeroes;
74 pad_size =
sizeof(pad_zeroes) - 1;
84 right_pad = pad - left_pad;
92 total_chars_printed += left_pad;
93 while (left_pad > 0) {
104 total_chars_printed += len;
107 total_chars_printed += right_pad;
108 while (right_pad > 0) {
117 return total_chars_printed;
122 #define INT_BUF_SIZE (sizeof(mp_int_t) * 4) 126 #define SUPPORT_INT_BASE_PREFIX (0) 158 }
while (b > buf && x != 0);
161 #if SUPPORT_INT_BASE_PREFIX 162 char prefix_char =
'\0';
166 prefix_char = base_char +
'b' -
'a';
167 }
else if (base == 8) {
168 prefix_char = base_char +
'o' -
'a';
169 }
else if (base == 16) {
170 prefix_char = base_char +
'x' -
'a';
181 #if SUPPORT_INT_BASE_PREFIX 184 len +=
mp_print_strn(print, &prefix_char, 1, flags, fill, 1);
189 #if SUPPORT_INT_BASE_PREFIX 190 if (prefix_char && b > &buf[1]) {
191 *(--b) = prefix_char;
195 if (sign && b > buf) {
208 assert(base == 2 || base == 8 || base == 10 || base == 16);
223 char *prefix = prefix_buf;
236 *prefix++ = base_char +
'b' -
'a';
237 }
else if (base == 8) {
240 *prefix++ = base_char +
'o' -
'a';
242 }
else if (base == 16) {
244 *prefix++ = base_char +
'x' -
'a';
248 int prefix_len = prefix - prefix_buf;
258 char stack_buf[
sizeof(
mp_int_t) * 4];
259 char *buf = stack_buf;
260 size_t buf_size =
sizeof(stack_buf);
272 x, base,
NULL, base_char, comma);
279 x, base, prefix, base_char, comma);
282 int spaces_before = 0;
283 int spaces_after = 0;
290 int prec_width = fmt_size;
291 if (prec_width < prec) {
298 prec_width += prefix_len;
300 if (prec_width < width) {
302 spaces_after = width - prec_width;
304 spaces_before = width - prec_width;
330 len +=
mp_print_strn(print, str, fmt_size, flags, fill, width);
336 if (buf != stack_buf) {
337 m_del(
char, buf, buf_size);
342 #if MICROPY_PY_BUILTINS_FLOAT 343 int mp_print_float(
const mp_print_t *print, mp_float_t f,
char fmt,
int flags,
char fill,
int width,
int prec) {
356 int len = mp_format_float(f, buf,
sizeof(buf), fmt, prec, sign);
393 while (*f !=
'\0' && *f !=
'%') {
413 while (*fmt !=
'\0') {
418 else if (*fmt ==
'0') {
427 for (;
'0' <= *fmt && *fmt <=
'9'; ++fmt) {
428 width = width * 10 + *fmt -
'0';
440 for (;
'0' <= *fmt && *fmt <=
'9'; ++fmt) {
441 prec = prec * 10 + *fmt -
'0';
465 chrs +=
mp_print_strn(print,
"false", 5, flags, fill, width);
478 const char *str = (
const char*)
qstr_data(qst, &len);
490 if (prec != 0 && str ==
NULL) {
491 chrs +=
mp_print_strn(print,
"(null)", 6, flags, fill, width);
517 #if MICROPY_PY_BUILTINS_FLOAT 525 #if ((MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT) || (MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE)) 527 chrs += mp_print_float(print, f, *fmt, flags, fill, width, prec);
529 #error Unknown MICROPY FLOAT IMPL 537 #if (MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D) || defined(_WIN64) 539 unsigned long long int arg_value =
va_arg(
args,
unsigned long long int);
541 if (*fmt ==
'u' || *fmt ==
'd') {
542 chrs +=
mp_print_int(print, arg_value, *fmt ==
'd', 10,
'a', flags, fill, width);
545 assert(!
"unsupported fmt char");
550 assert(*fmt ==
'%' || !
"unsupported fmt char");
const mp_print_t mp_plat_print
#define PF_FLAG_SHOW_COMMA
mp_print_strn_t print_strn
#define m_del(type, ptr, num)
int mp_print_str(const mp_print_t *print, const char *str)
mp_int_t mp_obj_get_int(mp_const_obj_t arg)
STATIC int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int base_char, int flags, char fill, int width)
char * mp_obj_int_formatted(char **buf, size_t *buf_size, size_t *fmt_size, mp_const_obj_t self_in, int base, const char *prefix, char base_char, char comma)
#define MP_OBJ_NEW_SMALL_INT(small_int)
size_t strlen(const char *s)
#define PF_FLAG_SHOW_SIGN
int mp_obj_int_sign(mp_obj_t self_in)
#define MP_PLAT_PRINT_STRN(str, len)
#define PF_FLAG_LEFT_ADJUST
const byte * qstr_data(qstr q, size_t *len)
#define PF_FLAG_SPACE_SIGN
__builtin_va_list va_list
int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args)
#define PF_FLAG_ADD_PERCENT
int mp_print_strn(const mp_print_t *print, const char *str, size_t len, int flags, char fill, int width)
#define PF_FLAG_SHOW_OCTAL_LETTER
#define PF_FLAG_CENTER_ADJUST
#define PF_FLAG_PAD_AFTER_SIGN
int mp_printf(const mp_print_t *print, const char *fmt,...)
#define PF_FLAG_SHOW_PREFIX
int mp_print_mp_int(const mp_print_t *print, mp_obj_t x, int base, int base_char, int flags, char fill, int width, int prec)
#define va_start(ap, last)
#define PF_FLAG_NO_TRAILZ
STATIC void plat_print_strn(void *env, const char *str, size_t len)