mruby/c VM Source Code release 3.4
Loading...
Searching...
No Matches
console.c
Go to the documentation of this file.
1
13
14/***** Feature test switches ************************************************/
15/***** System headers *******************************************************/
16//@cond
17#include "vm_config.h"
18#include <stdint.h>
19#include <stdarg.h>
20#include <string.h>
21#include <assert.h>
22#if MRBC_USE_FLOAT
23#include <stdio.h>
24#endif
25//@endcond
26
27/***** Local headers ********************************************************/
28#include "mrubyc.h"
29
30/***** Constant values ******************************************************/
31#define MRBC_PRINTF_MAX_WIDTH 82
32
33
34/***** Macros ***************************************************************/
35/***** Typedefs *************************************************************/
36/***** Function prototypes **************************************************/
37/***** Local variables ******************************************************/
38/***** Global variables *****************************************************/
39/***** Signal catching functions ********************************************/
40/***** Local functions ******************************************************/
41//----------------------------------------------------------------
42/* sub function for mrbc_printf
43*/
44static int mrbc_printf_sub_output_arg( mrbc_printf_t *pf, va_list *ap )
45{
46 int ret;
47
48 switch(pf->fmt.type) {
49 case 'c':
50 ret = mrbc_printf_char( pf, va_arg(*ap, int) );
51 break;
52
53 case 's':
54 ret = mrbc_printf_str( pf, va_arg(*ap, char *), ' ');
55 break;
56
57 case 'd':
58 case 'i':
59 case 'u':
60 ret = mrbc_printf_int( pf, va_arg(*ap, int), 10);
61 break;
62
63 case 'D': // for mrbc_int_t (see mrbc_print_sub)
64 ret = mrbc_printf_int( pf, va_arg(*ap, mrbc_int_t), 10);
65 break;
66
67 case 'b':
68 case 'B':
69 ret = mrbc_printf_bit( pf, va_arg(*ap, unsigned int), 1);
70 break;
71
72 case 'x':
73 case 'X':
74 ret = mrbc_printf_bit( pf, va_arg(*ap, unsigned int), 4);
75 break;
76
77#if MRBC_USE_FLOAT
78 case 'f':
79 case 'e':
80 case 'E':
81 case 'g':
82 case 'G':
83 ret = mrbc_printf_float( pf, va_arg(*ap, double) );
84 break;
85#endif
86 case 'p':
87 ret = mrbc_printf_pointer( pf, va_arg(*ap, void *) );
88 break;
89
90 default:
91 ret = 0;
92 break;
93 }
94
95 return ret;
96}
97
98
99/***** Global functions *****************************************************/
100
101//================================================================
106void mrbc_putchar(char c)
107{
108#if defined(MRBC_CONVERT_CRLF)
109 static const char CRLF[2] = "\r\n";
110 if( c == '\n' ) {
111 hal_write(1, CRLF, 2);
112 } else {
113 hal_write(1, &c, 1);
114 }
115
116#else
117 hal_write(1, &c, 1);
118#endif
119}
120
121
122//================================================================
128{
129 // normal case
130 if( !mrbc_is_nested_symid(sym_id) ) {
131 mrbc_print( mrbc_symid_to_str(sym_id) );
132 return;
133 }
134
135 // nested case
136 mrbc_sym id1, id2;
137 mrbc_separate_nested_symid( sym_id, &id1, &id2 );
138
139 mrbc_print_symbol( id1 );
140 mrbc_print("::");
141 mrbc_print_symbol( id2 );
142}
143
144
145//================================================================
151void mrbc_nprint(const char *str, int size)
152{
153#if defined(MRBC_CONVERT_CRLF)
154 static const char CRLF[2] = "\r\n";
155 const char *p1 = str;
156 const char *p2 = str;
157
158 for( int i = 0; i < size; i++ ) {
159 if( *p1++ == '\n' ) {
160 hal_write(1, p2, p1 - p2 - 1);
161 hal_write(1, CRLF, 2);
162 p2 = p1;
163 }
164 }
165 if( p1 != p2 ) {
166 hal_write(1, p2, p1 - p2);
167 }
168
169#else
170 hal_write(1, str, size);
171#endif
172}
173
174
175//================================================================
180void mrbc_printf(const char *fstr, ...)
181{
182 va_list ap;
183 va_start(ap, fstr);
184
185 mrbc_vprintf( fstr, ap );
186
187 va_end(ap);
188}
189
190
191//================================================================
198void mrbc_asprintf(char **buf, int bufsiz, const char *fstr, ...)
199{
200 va_list ap;
201 va_start(ap, fstr);
202
203 mrbc_vasprintf( buf, bufsiz, fstr, ap );
204
205 va_end(ap);
206}
207
208
209//================================================================
216void mrbc_snprintf(char *buf, int bufsiz, const char *fstr, ...)
217{
218 va_list ap;
219 va_start(ap, fstr);
220
221 mrbc_printf_t pf;
222 mrbc_printf_init( &pf, buf, bufsiz, fstr );
223
224 while( 1 ) {
225 if( mrbc_printf_main( &pf ) <= 0 ) break;
226 // normal end (==0) or buffer full (<0).
227 if( mrbc_printf_sub_output_arg( &pf, &ap ) != 0 ) break;
228 }
229
230 mrbc_printf_end( &pf );
231 va_end(ap);
232}
233
234
235//================================================================
241void mrbc_vprintf(const char *fstr, va_list ap)
242{
243 va_list ap1;
244 va_copy( ap1, ap );
245
246 mrbc_printf_t pf;
247 char buf[MRBC_PRINTF_MAX_WIDTH];
248 mrbc_printf_init( &pf, buf, sizeof(buf), fstr );
249
250 while( 1 ) {
251 int ret = mrbc_printf_main( &pf );
252 if( mrbc_printf_len( &pf ) ) {
253 mrbc_nprint( buf, mrbc_printf_len( &pf ) );
254 mrbc_printf_clear( &pf );
255 }
256 if( ret == 0 ) break;
257 if( ret < 0 ) continue;
258
259 mrbc_printf_sub_output_arg( &pf, &ap1 );
260 mrbc_nprint( buf, mrbc_printf_len( &pf ) );
261 mrbc_printf_clear( &pf );
262 }
263
264 va_end(ap1);
265}
266
267
268//================================================================
276void mrbc_vasprintf(char **buf, int bufsiz, const char *fstr, va_list ap)
277{
278 va_list ap1, ap_bak;
279 va_copy( ap1, ap );
280
281 mrbc_printf_t pf;
282 mrbc_printf_init( &pf, *buf, bufsiz, fstr );
283
284 while( 1 ) {
285 va_copy(ap_bak, ap1);
286 mrbc_printf_t pf_bak = pf;
287
288 int ret = mrbc_printf_main( &pf );
289 if( ret == 0 ) break; // normal break loop.
290 if( ret < 0 ) goto INCREASE_BUFFER;
291
292 ret = mrbc_printf_sub_output_arg( &pf, &ap1 );
293 if( ret >= 0 ) goto NEXT_LOOP;
294
295 va_end(ap1);
296 va_copy(ap1, ap_bak);
297 pf = pf_bak;
298
299 INCREASE_BUFFER:
300 bufsiz += 64;
301 void *newbuf = mrbc_raw_realloc( pf.buf, bufsiz );
302 if( !newbuf ) break;
303 mrbc_printf_replace_buffer( &pf, newbuf, bufsiz );
304 *buf = newbuf;
305
306 NEXT_LOOP:
307 va_end(ap_bak);
308 }
309
310 mrbc_printf_end( &pf );
311 va_end(ap1);
312 va_end(ap_bak);
313}
314
315
316//================================================================
321void mrbc_p(const mrbc_value *v)
322{
323 mrbc_p_sub( v );
324 mrbc_putchar('\n');
325}
326
327
328//================================================================
334{
335 if( !v ) {
336 mrbc_print("(null)"); // wrong things are happen. but it give me a clue.
337 return 0;
338 }
339
340 switch( mrbc_type(*v) ) {
341 case MRBC_TT_NIL:
342 mrbc_print("nil");
343 break;
344
345 case MRBC_TT_SYMBOL:{
346 const char *s = mrbc_symbol_cstr( v );
347 const char *fmt = strchr(s, ':') ? "\":%s\"" : ":%s";
348 mrbc_printf(fmt, s);
349 } break;
350
351#if MRBC_USE_STRING
352 case MRBC_TT_STRING:{
353 mrbc_putchar('"');
354 const unsigned char *s = (const unsigned char *)mrbc_string_cstr(v);
355
356 for( int i = 0; i < mrbc_string_size(v); i++ ) {
357 if( s[i] < ' ' || 0x7f <= s[i] ) { // tiny isprint()
358 mrbc_printf("\\x%02X", s[i]);
359 } else {
360 mrbc_putchar(s[i]);
361 }
362 }
363 mrbc_putchar('"');
364 } break;
365#endif
366
367 case MRBC_TT_RANGE:{
369 mrbc_p_sub(&v1);
370 mrbc_print( mrbc_range_exclude_end(v) ? "..." : ".." );
371 v1 = mrbc_range_last(v);
372 mrbc_p_sub(&v1);
373 } break;
374
375 default:
377 break;
378 }
379
380#if 0
381 // display reference counter
383 mrbc_printf("#%d", v->obj->ref_count);
384 }
385#endif
386
387 return 0;
388}
389
390
391//================================================================
399{
400 if( mrbc_type(*v) == MRBC_TT_ARRAY ) {
401
402 for( int i = 0; i < mrbc_array_size(v); i++ ) {
403 if( i != 0 ) mrbc_putchar('\n');
404 mrbc_value v1 = mrbc_array_get(v, i);
405 mrbc_puts_sub(&v1);
406 }
407 return 0;
408 }
409
410 return mrbc_print_sub(v);
411}
412
413
414//================================================================
422{
423 int ret = 0;
424
425 switch( mrbc_type(*v) ) {
426 case MRBC_TT_EMPTY: mrbc_print("(empty)"); break;
427 case MRBC_TT_NIL: break;
428 case MRBC_TT_FALSE: mrbc_print("false"); break;
429 case MRBC_TT_TRUE: mrbc_print("true"); break;
430 case MRBC_TT_INTEGER: mrbc_printf("%D", v->i); break;
431#if MRBC_USE_FLOAT
432 case MRBC_TT_FLOAT: mrbc_printf("%g", v->d); break;
433#endif
434 case MRBC_TT_SYMBOL: mrbc_print_symbol(v->sym_id); break;
435 case MRBC_TT_CLASS: // fall through.
436 case MRBC_TT_MODULE: mrbc_print_symbol(v->cls->sym_id); break;
437
438 case MRBC_TT_OBJECT:{
439 mrbc_printf("#<");
442
444 while( mrbc_kv_i_has_next( &ite ) ) {
445 mrbc_printf( mrbc_kv_i_is_first(&ite) ? " " : ", " );
446 const mrbc_kv *kv = mrbc_kv_i_next( &ite );
448 mrbc_p_sub(&kv->value);
449 }
450 mrbc_printf(">");
451 } break;
452
453 case MRBC_TT_PROC:
454 mrbc_printf("#<Proc:%08x>", MRBC_PTR_TO_UINT32(v->proc) );
455 //mrbc_printf("#<Proc:%08x, callinfo=%p>", MRBC_PTR_TO_UINT32(v->proc), MRBC_PTR_TO_UINT32(v->proc->callinfo) );
456 break;
457
458 case MRBC_TT_ARRAY:{
459 mrbc_putchar('[');
460 for( int i = 0; i < mrbc_array_size(v); i++ ) {
461 if( i != 0 ) mrbc_print(", ");
462 mrbc_value v1 = mrbc_array_get(v, i);
463 mrbc_p_sub(&v1);
464 }
465 mrbc_putchar(']');
466 } break;
467
468#if MRBC_USE_STRING
469 case MRBC_TT_STRING:
471 if( mrbc_string_size(v) != 0 &&
472 mrbc_string_cstr(v)[ mrbc_string_size(v) - 1 ] == '\n' ) ret = 1;
473 break;
474#endif
475
476 case MRBC_TT_RANGE:{
478 mrbc_print_sub(&v1);
479 mrbc_print( mrbc_range_exclude_end(v) ? "..." : ".." );
480 v1 = mrbc_range_last(v);
481 mrbc_print_sub(&v1);
482 } break;
483
484 case MRBC_TT_HASH:{
485 mrbc_putchar('{');
487 while( mrbc_hash_i_has_next(&ite) ) {
488 mrbc_value *vk = mrbc_hash_i_next(&ite);
489 mrbc_p_sub(vk);
490 mrbc_print("=>");
491 mrbc_p_sub(vk+1);
492 if( mrbc_hash_i_has_next(&ite) ) mrbc_print(", ");
493 }
494 mrbc_putchar('}');
495 } break;
496
497 case MRBC_TT_HANDLE:
498 mrbc_printf("#<Handle:%08x>", MRBC_PTR_TO_UINT32(v->handle) );
499 break;
500
503 v->exception->message ?
504 (const char *)v->exception->message :
506 break;
507
508 default:
509 mrbc_printf("Not support MRBC_TT_XX(%d)", mrbc_type(*v));
510 break;
511 }
512
513 return ret;
514}
515
516
517//================================================================
524void mrbc_printf_replace_buffer(mrbc_printf_t *pf, char *buf, int size)
525{
526 int p_ofs = pf->p - pf->buf;
527 pf->buf = buf;
528 pf->buf_end = buf + size - 1;
529 pf->p = pf->buf + p_ofs;
530}
531
532
533//================================================================
543{
544 int ch = -1;
545 pf->fmt = (struct RPrintfFormat){0};
546
547 while( pf->p < pf->buf_end && (ch = *pf->fstr) != '\0' ) {
548 pf->fstr++;
549 if( ch == '%' ) {
550 if( *pf->fstr == '%' ) { // is "%%"
551 pf->fstr++;
552 } else {
553 goto PARSE_FLAG;
554 }
555 }
556 *pf->p++ = ch;
557 }
558 return -(ch != '\0');
559
560
561 PARSE_FLAG:
562 // parse format - '%' [flag] [width] [.precision] type
563 // e.g. "%05d"
564 while( (ch = *pf->fstr) ) {
565 switch( ch ) {
566 case '+': pf->fmt.flag_plus = 1; break;
567 case ' ': pf->fmt.flag_space = 1; break;
568 case '-': pf->fmt.flag_minus = 1; break;
569 case '0': pf->fmt.flag_zero = 1; break;
570 default : goto PARSE_WIDTH;
571 }
572 pf->fstr++;
573 }
574
575 PARSE_WIDTH:
576 while( (void)(ch = *pf->fstr - '0'), (0 <= ch && ch <= 9)) { // isdigit()
577 pf->fmt.width = pf->fmt.width * 10 + ch;
578 pf->fstr++;
579 }
580 if( *pf->fstr == '.' ) {
581 pf->fstr++;
582 while( (void)(ch = *pf->fstr - '0'), (0 <= ch && ch <= 9)) {
583 pf->fmt.precision = pf->fmt.precision * 10 + ch;
584 pf->fstr++;
585 }
586 }
587 if( *pf->fstr ) pf->fmt.type = *pf->fstr++;
588
589 return 1;
590}
591
592
593//================================================================
603{
604 if( pf->fmt.flag_minus ) {
605 if( pf->p == pf->buf_end ) return -1;
606 *pf->p++ = ch;
607 }
608
609 int width = pf->fmt.width;
610 while( --width > 0 ) {
611 if( pf->p == pf->buf_end ) return -1;
612 *pf->p++ = ' ';
613 }
614
615 if( !pf->fmt.flag_minus ) {
616 if( pf->p == pf->buf_end ) return -1;
617 *pf->p++ = ch;
618 }
619
620 return 0;
621}
622
623
624//================================================================
635int mrbc_printf_bstr( mrbc_printf_t *pf, const char *str, int len, int pad )
636{
637 int ret = 0;
638
639 if( str == NULL ) {
640 str = "(null)";
641 len = 6;
642 }
643 if( pf->fmt.precision && len > pf->fmt.precision ) len = pf->fmt.precision;
644
645 int tw = len;
646 if( pf->fmt.width > len ) tw = pf->fmt.width;
647
648 int remain = pf->buf_end - pf->p;
649 if( len > remain ) {
650 len = remain;
651 ret = -1;
652 }
653 if( tw > remain ) {
654 tw = remain;
655 ret = -1;
656 }
657
658 int n_pad = tw - len;
659
660 if( !pf->fmt.flag_minus ) {
661 while( n_pad-- > 0 ) {
662 *pf->p++ = pad;
663 }
664 }
665 while( len-- > 0 ) {
666 *pf->p++ = *str++;
667 }
668 while( n_pad-- > 0 ) {
669 *pf->p++ = pad;
670 }
671
672 return ret;
673}
674
675
676
677//================================================================
687int mrbc_printf_int( mrbc_printf_t *pf, mrbc_int_t value, unsigned int base )
688{
689 int sign = 0;
690 mrbc_uint_t v = value;
691 char *pf_p_ini_val = pf->p;
692
693 if( value < 0 ) {
694 sign = '-';
695 v = -value;
696 } else if( pf->fmt.flag_plus ) {
697 sign = '+';
698 } else if( pf->fmt.flag_space ) {
699 sign = ' ';
700 }
701
702 // disable zero padding if conflict parameters exists.
703 if( pf->fmt.flag_minus || pf->fmt.width == 0 || pf->fmt.precision != 0 ) {
704 pf->fmt.flag_zero = 0;
705 }
706
707 // create string to temporary buffer
708 char buf[sizeof(mrbc_int_t) * 8];
709 char *p = buf + sizeof(buf);
710
711 do {
712 unsigned int ch = v % base;
713 *--p = ch + ((ch < 10)? '0' : 'a' - 10);
714 v /= base;
715 } while( v != 0 );
716
717 int dig_width = buf + sizeof(buf) - p;
718
719 // write padding character, if adjust right.
720 if( !pf->fmt.flag_minus && pf->fmt.width ) {
721 int pad = pf->fmt.flag_zero ? '0' : ' ';
722 int pad_width = pf->fmt.width - !!sign;
723 pad_width -= (pf->fmt.precision > dig_width)? pf->fmt.precision: dig_width;
724
725 for( ; pad_width > 0; pad_width-- ) {
726 *pf->p++ = pad;
727 if( pf->p >= pf->buf_end ) return -1;
728 }
729 }
730
731 // sign
732 if( sign ) {
733 *pf->p++ = sign;
734 if( pf->p >= pf->buf_end ) return -1;
735 }
736
737 // precision
738 int pre_width = pf->fmt.precision - dig_width;
739 for( ; pre_width > 0; pre_width-- ) {
740 *pf->p++ = '0';
741 if( pf->p >= pf->buf_end ) return -1;
742 }
743
744 // digit
745 for( ; dig_width > 0; dig_width-- ) {
746 *pf->p++ = *p++;
747 if( pf->p >= pf->buf_end ) return -1;
748 }
749
750 // write space, if adjust left.
751 if( pf->fmt.flag_minus && pf->fmt.width ) {
752 int pad_width = pf->fmt.width - (pf->p - pf_p_ini_val);
753 for( ; pad_width > 0; pad_width-- ) {
754 *pf->p++ = ' ';
755 if( pf->p >= pf->buf_end ) return -1;
756 }
757 }
758
759 return 0;
760}
761
762
763
764//================================================================
774int mrbc_printf_bit( mrbc_printf_t *pf, mrbc_int_t value, int bit )
775{
776 if( pf->fmt.flag_plus || pf->fmt.flag_space ) {
777 return mrbc_printf_int( pf, value, 1 << bit );
778 }
779
780 if( pf->fmt.flag_minus || pf->fmt.width == 0 ) {
781 pf->fmt.flag_zero = 0; // disable zero padding if left align or width zero.
782 }
783 pf->fmt.precision = 0;
784
785 mrbc_int_t v = value;
786 int offset_a = (pf->fmt.type == 'X') ? 'A' - 10 : 'a' - 10;
787 int mask = (1 << bit) - 1; // 0x0f, 0x07, 0x01
788 int mchar = mask + ((mask < 10)? '0' : offset_a);
789
790 // create string to local buffer
791 char buf[sizeof(mrbc_int_t) * 8 + 5];
792 assert( sizeof(buf) > (sizeof(mrbc_int_t) * 8 + 4) );
793 char *p = buf + sizeof(buf) - 1;
794 *p = '\0';
795 int n;
796 do {
797 assert( p >= buf );
798 n = v & mask;
799 *--p = n + ((n < 10)? '0' : offset_a);
800 v >>= bit;
801 } while( v != 0 && v != -1 );
802
803 // add "..f" for negative value?
804 // (note) '0' flag such as "%08x" is incompatible with ruby.
805 if( value < 0 && !pf->fmt.flag_zero ) {
806 if( n != mask ) *--p = mchar;
807 *--p = '.';
808 *--p = '.';
809 assert( p >= buf );
810 }
811
812 // decide pad character and output sign character
813 int pad;
814 if( pf->fmt.flag_zero ) {
815 pad = (value < 0) ? mchar : '0';
816 } else {
817 pad = ' ';
818 }
819
820 return mrbc_printf_str( pf, p, pad );
821}
822
823
824
825#if MRBC_USE_FLOAT
826//================================================================
834int mrbc_printf_float( mrbc_printf_t *pf, double value )
835{
836 char fstr[16];
837 const char *p1 = pf->fstr;
838 char *p2 = fstr + sizeof(fstr) - 1;
839
840 *p2 = '\0';
841 while( (*--p2 = *--p1) != '%' )
842 ;
843
844 snprintf( pf->p, (pf->buf_end - pf->p + 1), p2, value );
845
846 while( *pf->p != '\0' )
847 pf->p++;
848
849 return -(pf->p == pf->buf_end);
850}
851#endif
852
853
854
855//================================================================
869{
870 uint32_t v = MRBC_PTR_TO_UINT32(ptr);
871 int n = sizeof(ptr) * 2;
872 if( n > 8 ) n = 8;
873
874 // check buffer size.
875 if( (pf->buf_end - pf->p) < n+1 ) return -1;
876
877 // write pointer value.
878 *pf->p++ = '$';
879 pf->p += n;
880 char *p = pf->p - 1;
881
882 for(; n > 0; n-- ) {
883 *p-- = (v & 0xf) < 10 ? (v & 0xf) + '0' : (v & 0xf) - 10 + 'a';
884 v >>= 4;
885 }
886
887 return 0;
888}
void * mrbc_raw_realloc(void *ptr, unsigned int size)
Definition alloc.c:796
mrbc_value mrbc_array_get(const mrbc_value *ary, int idx)
Definition c_array.c:216
static int mrbc_array_size(const mrbc_value *ary)
Definition c_array.h:81
static mrbc_value * mrbc_hash_i_next(mrbc_hash_iterator *ite)
Definition c_hash.h:141
static int mrbc_hash_i_has_next(mrbc_hash_iterator *ite)
Definition c_hash.h:133
struct RHashIterator mrbc_hash_iterator
Define Hash iterator.
static mrbc_hash_iterator mrbc_hash_iterator_new(const mrbc_value *v)
Definition c_hash.h:120
static mrbc_value mrbc_range_last(const mrbc_value *v)
Definition c_range.h:72
static int mrbc_range_exclude_end(const mrbc_value *v)
Definition c_range.h:80
static mrbc_value mrbc_range_first(const mrbc_value *v)
Definition c_range.h:64
static char * mrbc_string_cstr(const mrbc_value *v)
Definition c_string.h:116
static int mrbc_string_size(const mrbc_value *str)
Definition c_string.h:108
static mrbc_class * find_class_by_object(const mrbc_value *obj)
Definition class.h:235
void mrbc_p(const mrbc_value *v)
Definition console.c:321
int mrbc_printf_float(mrbc_printf_t *pf, double value)
Definition console.c:834
int mrbc_print_sub(const mrbc_value *v)
Definition console.c:421
void mrbc_printf(const char *fstr,...)
Definition console.c:180
int mrbc_printf_int(mrbc_printf_t *pf, mrbc_int_t value, unsigned int base)
Definition console.c:687
int mrbc_printf_char(mrbc_printf_t *pf, int ch)
Definition console.c:602
void mrbc_vprintf(const char *fstr, va_list ap)
Definition console.c:241
void mrbc_nprint(const char *str, int size)
Definition console.c:151
int mrbc_printf_bstr(mrbc_printf_t *pf, const char *str, int len, int pad)
Definition console.c:635
int mrbc_puts_sub(const mrbc_value *v)
Definition console.c:398
void mrbc_asprintf(char **buf, int bufsiz, const char *fstr,...)
Definition console.c:198
int mrbc_p_sub(const mrbc_value *v)
Definition console.c:333
int mrbc_printf_pointer(mrbc_printf_t *pf, void *ptr)
Definition console.c:868
void mrbc_vasprintf(char **buf, int bufsiz, const char *fstr, va_list ap)
Definition console.c:276
void mrbc_snprintf(char *buf, int bufsiz, const char *fstr,...)
Definition console.c:216
void mrbc_printf_replace_buffer(mrbc_printf_t *pf, char *buf, int size)
Definition console.c:524
void mrbc_putchar(char c)
Definition console.c:106
#define MRBC_PRINTF_MAX_WIDTH
Definition console.c:31
int mrbc_printf_bit(mrbc_printf_t *pf, mrbc_int_t value, int bit)
Definition console.c:774
void mrbc_print_symbol(mrbc_sym sym_id)
Definition console.c:127
int mrbc_printf_main(mrbc_printf_t *pf)
Definition console.c:542
static int mrbc_printf_sub_output_arg(mrbc_printf_t *pf, va_list *ap)
Definition console.c:44
static void mrbc_printf_clear(mrbc_printf_t *pf)
Definition console.h:133
static void mrbc_print(const char *str)
Definition console.h:104
static void mrbc_printf_end(mrbc_printf_t *pf)
Definition console.h:144
static int mrbc_printf_len(mrbc_printf_t *pf)
Definition console.h:156
struct RPrintf mrbc_printf_t
printf tiny (mruby/c) version data container.
static int mrbc_printf_str(mrbc_printf_t *pf, const char *str, int pad)
Definition console.h:172
static void mrbc_printf_init(mrbc_printf_t *pf, char *buf, int size, const char *fstr)
Definition console.h:118
static mrbc_kv * mrbc_kv_i_next(mrbc_kv_iterator *ite)
Definition keyvalue.h:152
static int mrbc_kv_i_has_next(const mrbc_kv_iterator *ite)
Definition keyvalue.h:136
struct RKeyValue mrbc_kv
Key-Value data.
static int mrbc_kv_i_is_first(const mrbc_kv_iterator *ite)
Definition keyvalue.h:128
struct RKeyValueIterator mrbc_kv_iterator
Key-Value iterator.
static mrbc_kv_iterator mrbc_kv_iterator_new(const mrbc_kv_handle *h)
Definition keyvalue.h:115
Include at once the necessary header files.
mrbc_sym sym_id
class name's symbol ID
Definition class.h:84
struct RClass * cls
exception class.
Definition error.h:50
const uint8_t * message
to heap or ROM.
Definition error.h:53
struct RKeyValueHandle ivar
instance variable.
Definition class.h:159
mrbc_sym sym_id
symbol ID as key.
Definition keyvalue.h:42
mrbc_value value
stored value.
Definition keyvalue.h:43
struct RProc * proc
Definition value.h:162
struct RException * exception
Definition value.h:167
struct RInstance * instance
Definition value.h:161
mrbc_sym sym_id
Definition value.h:158
void * handle
Definition value.h:168
mrbc_float_t d
Definition value.h:156
struct RBasic * obj
Definition value.h:159
struct RClass * cls
Definition value.h:160
mrbc_int_t i
Definition value.h:154
printf tiny (mruby/c) version format container.
Definition console.h:47
int16_t width
display width. (e.g. %10d as 10)
Definition console.h:53
int16_t precision
precision (e.g. %5.2f as 2)
Definition console.h:54
unsigned int flag_space
Definition console.h:51
unsigned int flag_zero
Definition console.h:52
unsigned int flag_plus
Definition console.h:49
unsigned int flag_minus
Definition console.h:50
char type
format char. (e.g. 'd','f','x'...)
Definition console.h:48
struct RPrintfFormat fmt
Definition console.h:67
char * p
output buffer write point.
Definition console.h:65
const char * buf_end
output buffer end point.
Definition console.h:64
const char * fstr
format string. (e.g. "%d %03x")
Definition console.h:66
char * buf
output buffer.
Definition console.h:63
void mrbc_separate_nested_symid(mrbc_sym sym_id, mrbc_sym *id1, mrbc_sym *id2)
Definition symbol.c:305
const char * mrbc_symid_to_str(mrbc_sym sym_id)
Definition symbol.c:238
static const char * mrbc_symbol_cstr(const mrbc_value *v)
Definition symbol.h:55
static int mrbc_is_nested_symid(mrbc_sym sym_id)
Definition symbol.h:68
int32_t mrbc_int_t
Definition value.h:45
#define MRBC_PTR_TO_UINT32(p)
Definition value.h:548
#define MRBC_TT_INC_DEC_THRESHOLD
Definition value.h:100
#define mrbc_type(o)
Definition value.h:193
int16_t mrbc_sym
mruby/c symbol ID
Definition value.h:59
@ MRBC_TT_FALSE
FalseClass.
Definition value.h:79
@ MRBC_TT_HANDLE
Definition value.h:74
@ MRBC_TT_SYMBOL
Symbol.
Definition value.h:86
@ MRBC_TT_STRING
String.
Definition value.h:95
@ MRBC_TT_FLOAT
Float.
Definition value.h:85
@ MRBC_TT_INTEGER
Integer.
Definition value.h:83
@ MRBC_TT_EXCEPTION
Exception.
Definition value.h:98
@ MRBC_TT_EMPTY
Definition value.h:77
@ MRBC_TT_PROC
Proc.
Definition value.h:93
@ MRBC_TT_RANGE
Range.
Definition value.h:96
@ MRBC_TT_OBJECT
General instance.
Definition value.h:92
@ MRBC_TT_ARRAY
Array.
Definition value.h:94
@ MRBC_TT_MODULE
Module.
Definition value.h:88
@ MRBC_TT_TRUE
TrueClass.
Definition value.h:82
@ MRBC_TT_NIL
NilClass.
Definition value.h:78
@ MRBC_TT_HASH
Hash.
Definition value.h:97
@ MRBC_TT_CLASS
Class.
Definition value.h:87
struct RObject mrbc_value
Definition value.h:174
uint32_t mrbc_uint_t
Definition value.h:46
Global configuration of mruby/c VM's.