@@ -74,7 +74,7 @@ mp_raw_code_t *mp_emit_glue_new_raw_code(void) {
7474}
7575
7676void mp_emit_glue_assign_bytecode (mp_raw_code_t * rc , byte * code , uint len , uint n_pos_args , uint n_kwonly_args , qstr * arg_names , uint scope_flags ) {
77- rc -> kind = MP_CODE_BYTE ;
77+ rc -> kind = MP_CODE_BYTECODE ;
7878 rc -> scope_flags = scope_flags ;
7979 rc -> n_pos_args = n_pos_args ;
8080 rc -> n_kwonly_args = n_kwonly_args ;
@@ -104,40 +104,15 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, byte *code, uint len, uint
104104#endif
105105}
106106
107- void mp_emit_glue_assign_native_code (mp_raw_code_t * rc , void * fun , uint len , int n_args ) {
108- rc -> kind = MP_CODE_NATIVE ;
107+ void mp_emit_glue_assign_native (mp_raw_code_t * rc , mp_raw_code_kind_t kind , void * fun , uint len , int n_args ) {
108+ assert (kind == MP_CODE_NATIVE_PY || kind == MP_CODE_NATIVE_VIPER || kind == MP_CODE_NATIVE_ASM );
109+ rc -> kind = kind ;
109110 rc -> scope_flags = 0 ;
110111 rc -> n_pos_args = n_args ;
111112 rc -> u_native .fun = fun ;
112113
113114#ifdef DEBUG_PRINT
114- DEBUG_printf ("assign native code: fun=%p len=%u n_args=%d\n" , fun , len , n_args );
115- byte * fun_data = (byte * )(((machine_uint_t )fun ) & (~1 )); // need to clear lower bit in case it's thumb code
116- for (int i = 0 ; i < 128 && i < len ; i ++ ) {
117- if (i > 0 && i % 16 == 0 ) {
118- DEBUG_printf ("\n" );
119- }
120- DEBUG_printf (" %02x" , fun_data [i ]);
121- }
122- DEBUG_printf ("\n" );
123-
124- #ifdef WRITE_CODE
125- if (fp_write_code != NULL ) {
126- fwrite (fun_data , len , 1 , fp_write_code );
127- fflush (fp_write_code );
128- }
129- #endif
130- #endif
131- }
132-
133- void mp_emit_glue_assign_inline_asm_code (mp_raw_code_t * rc , void * fun , uint len , int n_args ) {
134- rc -> kind = MP_CODE_INLINE_ASM ;
135- rc -> scope_flags = 0 ;
136- rc -> n_pos_args = n_args ;
137- rc -> u_inline_asm .fun = fun ;
138-
139- #ifdef DEBUG_PRINT
140- DEBUG_printf ("assign inline asm code: fun=%p len=%u n_args=%d\n" , fun , len , n_args );
115+ DEBUG_printf ("assign native: kind=%d fun=%p len=%u n_args=%d\n" , kind , fun , len , n_args );
141116 byte * fun_data = (byte * )(((machine_uint_t )fun ) & (~1 )); // need to clear lower bit in case it's thumb code
142117 for (int i = 0 ; i < 128 && i < len ; i ++ ) {
143118 if (i > 0 && i % 16 == 0 ) {
@@ -169,14 +144,15 @@ mp_obj_t mp_make_function_from_raw_code(mp_raw_code_t *rc, mp_obj_t def_args, mp
169144 // make the function, depending on the raw code kind
170145 mp_obj_t fun ;
171146 switch (rc -> kind ) {
172- case MP_CODE_BYTE :
147+ case MP_CODE_BYTECODE :
173148 fun = mp_obj_new_fun_bc (rc -> scope_flags , rc -> arg_names , rc -> n_pos_args , rc -> n_kwonly_args , def_args , rc -> u_byte .code );
174149 break ;
175- case MP_CODE_NATIVE :
150+ case MP_CODE_NATIVE_PY :
176151 fun = mp_make_function_n (rc -> n_pos_args , rc -> u_native .fun );
177152 break ;
178- case MP_CODE_INLINE_ASM :
179- fun = mp_obj_new_fun_asm (rc -> n_pos_args , rc -> u_inline_asm .fun );
153+ case MP_CODE_NATIVE_VIPER :
154+ case MP_CODE_NATIVE_ASM :
155+ fun = mp_obj_new_fun_asm (rc -> n_pos_args , rc -> u_native .fun );
180156 break ;
181157 default :
182158 // raw code was never set (this should not happen)
0 commit comments