Numworks Epsilon  1.4.1
Graphing Calculator Operating System
objfun.c
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2013, 2014 Damien P. George
7  * Copyright (c) 2014 Paul Sokolovsky
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  */
27 
28 #include <string.h>
29 #include <assert.h>
30 
31 #include "py/objtuple.h"
32 #include "py/objfun.h"
33 #include "py/runtime.h"
34 #include "py/bc.h"
35 #include "py/stackctrl.h"
36 
37 #if MICROPY_DEBUG_VERBOSE // print debugging info
38 #define DEBUG_PRINT (1)
39 #else // don't print debugging info
40 #define DEBUG_PRINT (0)
41 #define DEBUG_printf(...) (void)0
42 #endif
43 
44 // Note: the "name" entry in mp_obj_type_t for a function type must be
45 // MP_QSTR_function because it is used to determine if an object is of generic
46 // function type.
47 
48 /******************************************************************************/
49 /* builtin functions */
50 
51 STATIC mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
52  (void)args;
55  mp_arg_check_num(n_args, n_kw, 0, 0, false);
56  return self->fun._0();
57 }
58 
60  { &mp_type_type },
61  .name = MP_QSTR_function,
62  .call = fun_builtin_0_call,
63  .unary_op = mp_generic_unary_op,
64 };
65 
66 STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
69  mp_arg_check_num(n_args, n_kw, 1, 1, false);
70  return self->fun._1(args[0]);
71 }
72 
74  { &mp_type_type },
75  .name = MP_QSTR_function,
76  .call = fun_builtin_1_call,
77  .unary_op = mp_generic_unary_op,
78 };
79 
80 STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
83  mp_arg_check_num(n_args, n_kw, 2, 2, false);
84  return self->fun._2(args[0], args[1]);
85 }
86 
88  { &mp_type_type },
89  .name = MP_QSTR_function,
90  .call = fun_builtin_2_call,
91  .unary_op = mp_generic_unary_op,
92 };
93 
94 STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
97  mp_arg_check_num(n_args, n_kw, 3, 3, false);
98  return self->fun._3(args[0], args[1], args[2]);
99 }
100 
102  { &mp_type_type },
103  .name = MP_QSTR_function,
104  .call = fun_builtin_3_call,
105  .unary_op = mp_generic_unary_op,
106 };
107 
108 STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
110  mp_obj_fun_builtin_var_t *self = MP_OBJ_TO_PTR(self_in);
111 
112  // check number of arguments
113  mp_arg_check_num(n_args, n_kw, self->n_args_min, self->n_args_max, self->is_kw);
114 
115  if (self->is_kw) {
116  // function allows keywords
117 
118  // we create a map directly from the given args array
119  mp_map_t kw_args;
120  mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
121 
122  return self->fun.kw(n_args, args, &kw_args);
123 
124  } else {
125  // function takes a variable number of arguments, but no keywords
126 
127  return self->fun.var(n_args, args);
128  }
129 }
130 
132  { &mp_type_type },
133  .name = MP_QSTR_function,
134  .call = fun_builtin_var_call,
135  .unary_op = mp_generic_unary_op,
136 };
137 
138 /******************************************************************************/
139 /* byte code functions */
140 
141 qstr mp_obj_code_get_name(const byte *code_info) {
142  code_info = mp_decode_uint_skip(code_info); // skip code_info_size entry
143  #if MICROPY_PERSISTENT_CODE
144  return code_info[0] | (code_info[1] << 8);
145  #else
146  return mp_decode_uint_value(code_info);
147  #endif
148 }
149 
150 #if MICROPY_EMIT_NATIVE
151 STATIC const mp_obj_type_t mp_type_fun_native;
152 #endif
153 
155  const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in);
156  #if MICROPY_EMIT_NATIVE
157  if (fun->base.type == &mp_type_fun_native) {
158  // TODO native functions don't have name stored
159  return MP_QSTR_;
160  }
161  #endif
162 
163  const byte *bc = fun->bytecode;
164  bc = mp_decode_uint_skip(bc); // skip n_state
165  bc = mp_decode_uint_skip(bc); // skip n_exc_stack
166  bc++; // skip scope_params
167  bc++; // skip n_pos_args
168  bc++; // skip n_kwonly_args
169  bc++; // skip n_def_pos_args
170  return mp_obj_code_get_name(bc);
171 }
172 
173 #if MICROPY_CPYTHON_COMPAT
174 STATIC void fun_bc_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
175  (void)kind;
176  mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(o_in);
177  mp_printf(print, "<function %q at 0x%p>", mp_obj_fun_get_name(o_in), o);
178 }
179 #endif
180 
181 #if DEBUG_PRINT
182 STATIC void dump_args(const mp_obj_t *a, size_t sz) {
183  DEBUG_printf("%p: ", a);
184  for (size_t i = 0; i < sz; i++) {
185  DEBUG_printf("%p ", a[i]);
186  }
187  DEBUG_printf("\n");
188 }
189 #else
190 #define dump_args(...) (void)0
191 #endif
192 
193 // With this macro you can tune the maximum number of function state bytes
194 // that will be allocated on the stack. Any function that needs more
195 // than this will try to use the heap, with fallback to stack allocation.
196 #define VM_MAX_STATE_ON_STACK (11 * sizeof(mp_uint_t))
197 
198 // Set this to enable a simple stack overflow check.
199 #define VM_DETECT_STACK_OVERFLOW (0)
200 
201 #if MICROPY_STACKLESS
202 mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
203  MP_STACK_CHECK();
204  mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in);
205 
206  // bytecode prelude: state size and exception stack size
207  size_t n_state = mp_decode_uint_value(self->bytecode);
208  size_t n_exc_stack = mp_decode_uint_value(mp_decode_uint_skip(self->bytecode));
209 
210  // allocate state for locals and stack
211  size_t state_size = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t);
212  mp_code_state_t *code_state;
213  code_state = m_new_obj_var_maybe(mp_code_state_t, byte, state_size);
214  if (!code_state) {
215  return NULL;
216  }
217 
218  code_state->fun_bc = self;
219  code_state->ip = 0;
220  mp_setup_code_state(code_state, n_args, n_kw, args);
221 
222  // execute the byte code with the correct globals context
223  code_state->old_globals = mp_globals_get();
224  mp_globals_set(self->globals);
225 
226  return code_state;
227 }
228 #endif
229 
230 STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
231  MP_STACK_CHECK();
232 
233  DEBUG_printf("Input n_args: " UINT_FMT ", n_kw: " UINT_FMT "\n", n_args, n_kw);
234  DEBUG_printf("Input pos args: ");
235  dump_args(args, n_args);
236  DEBUG_printf("Input kw args: ");
237  dump_args(args + n_args, n_kw * 2);
238  mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in);
239  DEBUG_printf("Func n_def_args: %d\n", self->n_def_args);
240 
241  // bytecode prelude: state size and exception stack size
242  size_t n_state = mp_decode_uint_value(self->bytecode);
243  size_t n_exc_stack = mp_decode_uint_value(mp_decode_uint_skip(self->bytecode));
244 
245 #if VM_DETECT_STACK_OVERFLOW
246  n_state += 1;
247 #endif
248 
249  // allocate state for locals and stack
250  size_t state_size = n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t);
251  mp_code_state_t *code_state = NULL;
252  if (state_size > VM_MAX_STATE_ON_STACK) {
253  code_state = m_new_obj_var_maybe(mp_code_state_t, byte, state_size);
254  }
255  if (code_state == NULL) {
256  code_state = alloca(sizeof(mp_code_state_t) + state_size);
257  state_size = 0; // indicate that we allocated using alloca
258  }
259 
260  code_state->fun_bc = self;
261  code_state->ip = 0;
262  mp_setup_code_state(code_state, n_args, n_kw, args);
263 
264  // execute the byte code with the correct globals context
265  code_state->old_globals = mp_globals_get();
266  mp_globals_set(self->globals);
267  mp_vm_return_kind_t vm_return_kind = mp_execute_bytecode(code_state, MP_OBJ_NULL);
268  mp_globals_set(code_state->old_globals);
269 
270 #if VM_DETECT_STACK_OVERFLOW
271  if (vm_return_kind == MP_VM_RETURN_NORMAL) {
272  if (code_state->sp < code_state->state) {
273  printf("VM stack underflow: " INT_FMT "\n", code_state->sp - code_state->state);
274  assert(0);
275  }
276  }
277  // We can't check the case when an exception is returned in state[n_state - 1]
278  // and there are no arguments, because in this case our detection slot may have
279  // been overwritten by the returned exception (which is allowed).
280  if (!(vm_return_kind == MP_VM_RETURN_EXCEPTION && self->n_pos_args + self->n_kwonly_args == 0)) {
281  // Just check to see that we have at least 1 null object left in the state.
282  bool overflow = true;
283  for (size_t i = 0; i < n_state - self->n_pos_args - self->n_kwonly_args; i++) {
284  if (code_state->state[i] == MP_OBJ_NULL) {
285  overflow = false;
286  break;
287  }
288  }
289  if (overflow) {
290  printf("VM stack overflow state=%p n_state+1=" UINT_FMT "\n", code_state->state, n_state);
291  assert(0);
292  }
293  }
294 #endif
295 
296  mp_obj_t result;
297  if (vm_return_kind == MP_VM_RETURN_NORMAL) {
298  // return value is in *sp
299  result = *code_state->sp;
300  } else {
301  // must be an exception because normal functions can't yield
302  assert(vm_return_kind == MP_VM_RETURN_EXCEPTION);
303  // return value is in fastn[0]==state[n_state - 1]
304  result = code_state->state[n_state - 1];
305  }
306 
307  // free the state if it was allocated on the heap
308  if (state_size != 0) {
309  m_del_var(mp_code_state_t, byte, state_size, code_state);
310  }
311 
312  if (vm_return_kind == MP_VM_RETURN_NORMAL) {
313  return result;
314  } else { // MP_VM_RETURN_EXCEPTION
315  nlr_raise(result);
316  }
317 }
318 
319 #if MICROPY_PY_FUNCTION_ATTRS
320 STATIC void fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
321  if (dest[0] != MP_OBJ_NULL) {
322  // not load attribute
323  return;
324  }
325  if (attr == MP_QSTR___name__) {
326  dest[0] = MP_OBJ_NEW_QSTR(mp_obj_fun_get_name(self_in));
327  }
328 }
329 #endif
330 
332  { &mp_type_type },
333  .name = MP_QSTR_function,
334 #if MICROPY_CPYTHON_COMPAT
335  .print = fun_bc_print,
336 #endif
337  .call = fun_bc_call,
338  .unary_op = mp_generic_unary_op,
339 #if MICROPY_PY_FUNCTION_ATTRS
340  .attr = fun_bc_attr,
341 #endif
342 };
343 
344 mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table) {
345  size_t n_def_args = 0;
346  size_t n_extra_args = 0;
347  mp_obj_tuple_t *def_args = MP_OBJ_TO_PTR(def_args_in);
348  if (def_args_in != MP_OBJ_NULL) {
349  assert(MP_OBJ_IS_TYPE(def_args_in, &mp_type_tuple));
350  n_def_args = def_args->len;
351  n_extra_args = def_args->len;
352  }
353  if (def_kw_args != MP_OBJ_NULL) {
354  n_extra_args += 1;
355  }
357  o->base.type = &mp_type_fun_bc;
358  o->globals = mp_globals_get();
359  o->bytecode = code;
360  o->const_table = const_table;
361  if (def_args != NULL) {
362  memcpy(o->extra_args, def_args->items, n_def_args * sizeof(mp_obj_t));
363  }
364  if (def_kw_args != MP_OBJ_NULL) {
365  o->extra_args[n_def_args] = def_kw_args;
366  }
367  return MP_OBJ_FROM_PTR(o);
368 }
369 
370 /******************************************************************************/
371 /* native functions */
372 
373 #if MICROPY_EMIT_NATIVE
374 
375 STATIC mp_obj_t fun_native_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
376  MP_STACK_CHECK();
377  mp_obj_fun_bc_t *self = self_in;
378  mp_call_fun_t fun = MICROPY_MAKE_POINTER_CALLABLE((void*)self->bytecode);
379  return fun(self_in, n_args, n_kw, args);
380 }
381 
382 STATIC const mp_obj_type_t mp_type_fun_native = {
383  { &mp_type_type },
384  .name = MP_QSTR_function,
385  .call = fun_native_call,
386  .unary_op = mp_generic_unary_op,
387 };
388 
389 mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data, const mp_uint_t *const_table) {
390  mp_obj_fun_bc_t *o = mp_obj_new_fun_bc(def_args_in, def_kw_args, (const byte*)fun_data, const_table);
391  o->base.type = &mp_type_fun_native;
392  return o;
393 }
394 
395 #endif // MICROPY_EMIT_NATIVE
396 
397 /******************************************************************************/
398 /* viper functions */
399 
400 #if MICROPY_EMIT_NATIVE
401 
402 typedef struct _mp_obj_fun_viper_t {
403  mp_obj_base_t base;
404  size_t n_args;
405  void *fun_data; // GC must be able to trace this pointer
406  mp_uint_t type_sig;
407 } mp_obj_fun_viper_t;
408 
409 typedef mp_uint_t (*viper_fun_0_t)(void);
410 typedef mp_uint_t (*viper_fun_1_t)(mp_uint_t);
411 typedef mp_uint_t (*viper_fun_2_t)(mp_uint_t, mp_uint_t);
412 typedef mp_uint_t (*viper_fun_3_t)(mp_uint_t, mp_uint_t, mp_uint_t);
413 typedef mp_uint_t (*viper_fun_4_t)(mp_uint_t, mp_uint_t, mp_uint_t, mp_uint_t);
414 
415 STATIC mp_obj_t fun_viper_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
416  mp_obj_fun_viper_t *self = self_in;
417 
418  mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false);
419 
420  void *fun = MICROPY_MAKE_POINTER_CALLABLE(self->fun_data);
421 
422  mp_uint_t ret;
423  if (n_args == 0) {
424  ret = ((viper_fun_0_t)fun)();
425  } else if (n_args == 1) {
426  ret = ((viper_fun_1_t)fun)(mp_convert_obj_to_native(args[0], self->type_sig >> 4));
427  } else if (n_args == 2) {
428  ret = ((viper_fun_2_t)fun)(mp_convert_obj_to_native(args[0], self->type_sig >> 4), mp_convert_obj_to_native(args[1], self->type_sig >> 8));
429  } else if (n_args == 3) {
430  ret = ((viper_fun_3_t)fun)(mp_convert_obj_to_native(args[0], self->type_sig >> 4), mp_convert_obj_to_native(args[1], self->type_sig >> 8), mp_convert_obj_to_native(args[2], self->type_sig >> 12));
431  } else {
432  // compiler allows at most 4 arguments
433  assert(n_args == 4);
434  ret = ((viper_fun_4_t)fun)(
435  mp_convert_obj_to_native(args[0], self->type_sig >> 4),
436  mp_convert_obj_to_native(args[1], self->type_sig >> 8),
437  mp_convert_obj_to_native(args[2], self->type_sig >> 12),
438  mp_convert_obj_to_native(args[3], self->type_sig >> 16)
439  );
440  }
441 
442  return mp_convert_native_to_obj(ret, self->type_sig);
443 }
444 
445 STATIC const mp_obj_type_t mp_type_fun_viper = {
446  { &mp_type_type },
447  .name = MP_QSTR_function,
448  .call = fun_viper_call,
449  .unary_op = mp_generic_unary_op,
450 };
451 
452 mp_obj_t mp_obj_new_fun_viper(size_t n_args, void *fun_data, mp_uint_t type_sig) {
453  mp_obj_fun_viper_t *o = m_new_obj(mp_obj_fun_viper_t);
454  o->base.type = &mp_type_fun_viper;
455  o->n_args = n_args;
456  o->fun_data = fun_data;
457  o->type_sig = type_sig;
458  return o;
459 }
460 
461 #endif // MICROPY_EMIT_NATIVE
462 
463 /******************************************************************************/
464 /* inline assembler functions */
465 
466 #if MICROPY_EMIT_INLINE_ASM
467 
468 typedef struct _mp_obj_fun_asm_t {
469  mp_obj_base_t base;
470  size_t n_args;
471  void *fun_data; // GC must be able to trace this pointer
472  mp_uint_t type_sig;
473 } mp_obj_fun_asm_t;
474 
475 typedef mp_uint_t (*inline_asm_fun_0_t)(void);
476 typedef mp_uint_t (*inline_asm_fun_1_t)(mp_uint_t);
477 typedef mp_uint_t (*inline_asm_fun_2_t)(mp_uint_t, mp_uint_t);
478 typedef mp_uint_t (*inline_asm_fun_3_t)(mp_uint_t, mp_uint_t, mp_uint_t);
479 typedef mp_uint_t (*inline_asm_fun_4_t)(mp_uint_t, mp_uint_t, mp_uint_t, mp_uint_t);
480 
481 // convert a MicroPython object to a sensible value for inline asm
482 STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
483  // TODO for byte_array, pass pointer to the array
484  if (MP_OBJ_IS_SMALL_INT(obj)) {
485  return MP_OBJ_SMALL_INT_VALUE(obj);
486  } else if (obj == mp_const_none) {
487  return 0;
488  } else if (obj == mp_const_false) {
489  return 0;
490  } else if (obj == mp_const_true) {
491  return 1;
492  } else if (MP_OBJ_IS_TYPE(obj, &mp_type_int)) {
493  return mp_obj_int_get_truncated(obj);
494  } else if (MP_OBJ_IS_STR(obj)) {
495  // pointer to the string (it's probably constant though!)
496  size_t l;
497  return (mp_uint_t)mp_obj_str_get_data(obj, &l);
498  } else {
499  mp_obj_type_t *type = mp_obj_get_type(obj);
500  if (0) {
501 #if MICROPY_PY_BUILTINS_FLOAT
502  } else if (type == &mp_type_float) {
503  // convert float to int (could also pass in float registers)
504  return (mp_int_t)mp_obj_float_get(obj);
505 #endif
506  } else if (type == &mp_type_tuple || type == &mp_type_list) {
507  // pointer to start of tuple (could pass length, but then could use len(x) for that)
508  size_t len;
509  mp_obj_t *items;
510  mp_obj_get_array(obj, &len, &items);
511  return (mp_uint_t)items;
512  } else {
513  mp_buffer_info_t bufinfo;
514  if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_WRITE)) {
515  // supports the buffer protocol, return a pointer to the data
516  return (mp_uint_t)bufinfo.buf;
517  } else {
518  // just pass along a pointer to the object
519  return (mp_uint_t)obj;
520  }
521  }
522  }
523 }
524 
525 STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
526  mp_obj_fun_asm_t *self = self_in;
527 
528  mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false);
529 
530  void *fun = MICROPY_MAKE_POINTER_CALLABLE(self->fun_data);
531 
532  mp_uint_t ret;
533  if (n_args == 0) {
534  ret = ((inline_asm_fun_0_t)fun)();
535  } else if (n_args == 1) {
536  ret = ((inline_asm_fun_1_t)fun)(convert_obj_for_inline_asm(args[0]));
537  } else if (n_args == 2) {
538  ret = ((inline_asm_fun_2_t)fun)(convert_obj_for_inline_asm(args[0]), convert_obj_for_inline_asm(args[1]));
539  } else if (n_args == 3) {
540  ret = ((inline_asm_fun_3_t)fun)(convert_obj_for_inline_asm(args[0]), convert_obj_for_inline_asm(args[1]), convert_obj_for_inline_asm(args[2]));
541  } else {
542  // compiler allows at most 4 arguments
543  assert(n_args == 4);
544  ret = ((inline_asm_fun_4_t)fun)(
545  convert_obj_for_inline_asm(args[0]),
546  convert_obj_for_inline_asm(args[1]),
547  convert_obj_for_inline_asm(args[2]),
548  convert_obj_for_inline_asm(args[3])
549  );
550  }
551 
552  return mp_convert_native_to_obj(ret, self->type_sig);
553 }
554 
555 STATIC const mp_obj_type_t mp_type_fun_asm = {
556  { &mp_type_type },
557  .name = MP_QSTR_function,
558  .call = fun_asm_call,
559  .unary_op = mp_generic_unary_op,
560 };
561 
562 mp_obj_t mp_obj_new_fun_asm(size_t n_args, void *fun_data, mp_uint_t type_sig) {
563  mp_obj_fun_asm_t *o = m_new_obj(mp_obj_fun_asm_t);
564  o->base.type = &mp_type_fun_asm;
565  o->n_args = n_args;
566  o->fun_data = fun_data;
567  o->type_sig = type_sig;
568  return o;
569 }
570 
571 #endif // MICROPY_EMIT_INLINE_ASM
mp_obj_base_t base
Definition: objfun.h:32
size_t len
Definition: objtuple.h:33
intptr_t mp_int_t
Definition: mpconfigport.h:73
#define MP_BUFFER_WRITE
Definition: obj.h:455
mp_obj_dict_t * old_globals
Definition: bc.h:82
uintptr_t mp_uint_t
Definition: mpconfigport.h:74
mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table)
Definition: objfun.c:344
#define INT_FMT
Definition: mpconfigport.h:72
const byte * ip
Definition: bc.h:78
STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objfun.c:94
qstr mp_obj_fun_get_name(mp_const_obj_t fun_in)
Definition: objfun.c:154
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp_obj_t inject_exc)
Definition: vm.c:127
mp_obj_t state[0]
Definition: bc.h:87
const mp_obj_type_t mp_type_float
#define assert(e)
Definition: assert.h:9
#define mp_const_none
Definition: obj.h:614
mp_obj_t extra_args[]
Definition: objfun.h:41
#define MP_OBJ_IS_TYPE(o, t)
Definition: obj.h:254
STATIC const uint8_t attr[]
Definition: unicode.c:51
void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table)
Definition: map.c:86
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in)
Definition: obj.c:530
#define DEBUG_printf(...)
Definition: objfun.c:41
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
Definition: obj.c:512
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
Definition: obj.c:40
#define MP_OBJ_FROM_PTR(p)
Definition: obj.h:233
mp_obj_fun_bc_t * fun_bc
Definition: bc.h:77
STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objfun.c:66
#define MP_OBJ_NEW_QSTR(qst)
Definition: obj.h:92
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
Definition: argcheck.c:32
#define mp_const_true
Definition: obj.h:616
#define VM_MAX_STATE_ON_STACK
Definition: objfun.c:196
qstr mp_obj_code_get_name(const byte *code_info)
Definition: objfun.c:141
#define STATIC
Definition: mpconfig.h:1178
#define MP_OBJ_SMALL_INT_VALUE(o)
Definition: obj.h:86
mp_obj_t items[]
Definition: objtuple.h:34
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in)
Definition: objint.c:361
STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objfun.c:108
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items)
Definition: obj.c:346
mp_vm_return_kind_t
Definition: runtime.h:31
mp_print_kind_t
Definition: obj.h:412
const mp_obj_type_t mp_type_fun_bc
Definition: objfun.c:331
#define m_new_obj_var(obj_type, var_type, var_num)
Definition: misc.h:62
mp_obj_t mp_obj_new_fun_asm(size_t n_args, void *fun_data, mp_uint_t type_sig)
const char * mp_obj_str_get_data(mp_obj_t self_in, size_t *len)
Definition: objstr.c:2105
mp_obj_t(* mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: obj.h:432
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type)
uint64_t mp_const_obj_t
Definition: obj.h:40
#define NULL
Definition: stddef.h:4
#define MP_OBJ_NULL
Definition: obj.h:73
size_t qstr
Definition: qstr.h:48
#define m_del_var(obj_type, var_type, var_num, ptr)
Definition: misc.h:78
mp_uint_t mp_decode_uint_value(const byte *ptr)
Definition: bc.c:61
#define UINT_FMT
Definition: mpconfigport.h:71
mp_obj_t mp_obj_new_fun_viper(size_t n_args, void *fun_data, mp_uint_t type_sig)
const mp_obj_type_t mp_type_fun_builtin_var
Definition: objfun.c:131
#define dump_args(...)
Definition: objfun.c:190
const mp_uint_t * const_table
Definition: objfun.h:35
args
Definition: i18n.py:175
mp_obj_t * sp
Definition: bc.h:79
const byte * bytecode
Definition: objfun.h:34
void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: bc.c:108
const mp_obj_type_t mp_type_fun_builtin_3
Definition: objfun.c:101
Definition: obj.h:356
STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objfun.c:80
unsigned char byte
Definition: misc.h:37
const mp_obj_type_t mp_type_type
Definition: objtype.c:969
mp_code_state_t * mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, size_t n_kw, const mp_obj_t *args)
const mp_obj_type_t mp_type_fun_builtin_1
Definition: objfun.c:73
const mp_obj_type_t mp_type_fun_builtin_0
Definition: objfun.c:59
mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data, const mp_uint_t *const_table)
#define MP_OBJ_TO_PTR(o)
Definition: obj.h:228
const mp_obj_type_t mp_type_tuple
Definition: objtuple.c:220
#define nlr_raise(val)
Definition: nlr.h:89
STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objfun.c:230
STATIC mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objfun.c:51
#define MP_STACK_CHECK()
Definition: stackctrl.h:44
mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type)
#define alloca(size)
Definition: alloca.h:4
qstr name
Definition: obj.h:478
const byte * mp_decode_uint_skip(const byte *ptr)
Definition: bc.c:67
const mp_obj_type_t mp_type_fun_builtin_2
Definition: objfun.c:87
uint64_t mp_obj_t
Definition: obj.h:39
int mp_printf(const mp_print_t *print, const char *fmt,...)
Definition: mpprint.c:380
const mp_obj_type_t mp_type_int
Definition: obj.h:544
#define MP_OBJ_IS_STR(o)
Definition: obj.h:256
#define MICROPY_MAKE_POINTER_CALLABLE(p)
Definition: mpconfigport.h:65
mp_obj_dict_t * globals
Definition: objfun.h:33
#define m_new_obj(type)
Definition: misc.h:60
const mp_obj_type_t mp_type_list
Definition: objlist.c:444
void * memcpy(void *dst, const void *src, size_t n)
Definition: memcpy.c:3
void * buf
Definition: obj.h:446
#define m_new_obj_var_maybe(obj_type, var_type, var_num)
Definition: misc.h:63
#define mp_const_false
Definition: obj.h:615