@@ -48,6 +48,14 @@ mp_uint_t mp_verbose_flag = 0;
48
48
// Make it larger on a 64 bit machine, because pointers are larger.
49
49
long heap_size = 1024 * 1024 * (sizeof (mp_uint_t ) / 4 );
50
50
51
+ STATIC void stdout_print_strn (void * env , const char * str , size_t len ) {
52
+ (void )env ;
53
+ ssize_t dummy = write (STDOUT_FILENO , str , len );
54
+ (void )dummy ;
55
+ }
56
+
57
+ STATIC const mp_print_t mp_stdout_print = {NULL , stdout_print_strn };
58
+
51
59
STATIC void stderr_print_strn (void * env , const char * str , size_t len ) {
52
60
(void )env ;
53
61
ssize_t dummy = write (STDERR_FILENO , str , len );
@@ -59,7 +67,12 @@ STATIC const mp_print_t mp_stderr_print = {NULL, stderr_print_strn};
59
67
STATIC int compile_and_save (const char * file , const char * output_file , const char * source_file ) {
60
68
nlr_buf_t nlr ;
61
69
if (nlr_push (& nlr ) == 0 ) {
62
- mp_lexer_t * lex = mp_lexer_new_from_file (file );
70
+ mp_lexer_t * lex ;
71
+ if (strcmp (file , "-" ) == 0 ) {
72
+ lex = mp_lexer_new_from_fd (MP_QSTR__lt_stdin_gt_ , STDIN_FILENO , false);
73
+ } else {
74
+ lex = mp_lexer_new_from_file (file );
75
+ }
63
76
64
77
qstr source_name ;
65
78
if (source_file == NULL ) {
@@ -77,17 +90,22 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha
77
90
cm .context = m_new_obj (mp_module_context_t );
78
91
mp_compile_to_raw_code (& parse_tree , source_name , false, & cm );
79
92
80
- vstr_t vstr ;
81
- vstr_init (& vstr , 16 );
82
- if (output_file == NULL ) {
83
- vstr_add_str (& vstr , file );
84
- vstr_cut_tail_bytes (& vstr , 2 );
85
- vstr_add_str (& vstr , "mpy" );
93
+ if (output_file != NULL && strcmp (output_file , "-" ) == 0 ) {
94
+ mp_raw_code_save (& cm , (mp_print_t * )& mp_stdout_print );
86
95
} else {
87
- vstr_add_str (& vstr , output_file );
96
+ vstr_t vstr ;
97
+ vstr_init (& vstr , 16 );
98
+ if (output_file == NULL ) {
99
+ vstr_add_str (& vstr , file );
100
+ vstr_cut_tail_bytes (& vstr , 2 );
101
+ vstr_add_str (& vstr , "mpy" );
102
+ } else {
103
+ vstr_add_str (& vstr , output_file );
104
+ }
105
+
106
+ mp_raw_code_save_file (& cm , vstr_null_terminated_str (& vstr ));
107
+ vstr_clear (& vstr );
88
108
}
89
- mp_raw_code_save_file (& cm , vstr_null_terminated_str (& vstr ));
90
- vstr_clear (& vstr );
91
109
92
110
nlr_pop ();
93
111
return 0 ;
0 commit comments