summaryrefslogtreecommitdiff
path: root/py/objfun.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-13 00:30:32 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-13 00:30:32 +0100
commit8721087661ea607ea68d45b4e518e53607cadbd3 (patch)
tree721324e1334330e2c865c2928348f80e4372989f /py/objfun.c
parent82c7b1b1d5c8ce0467bd580a86d20c645cec17df (diff)
py: Big improvements to inline assembler.
Improved the Thumb assembler back end. Added many more Thumb instructions to the inline assembler. Improved parsing of assembler instructions and arguments. Assembler functions can now be passed the address of any object that supports the buffer protocol (to get the address of the buffer). Added an example of how to sum numbers from an array in assembler.
Diffstat (limited to 'py/objfun.c')
-rw-r--r--py/objfun.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/py/objfun.c b/py/objfun.c
index dd4b7347c..4ef92c025 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -422,26 +422,35 @@ STATIC machine_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
// pointer to the string (it's probably constant though!)
uint l;
return (machine_uint_t)mp_obj_str_get_data(obj, &l);
+ } else {
+ mp_obj_type_t *type = mp_obj_get_type(obj);
+ if (0) {
#if MICROPY_ENABLE_FLOAT
- } else if (MP_OBJ_IS_TYPE(obj, &mp_type_float)) {
- // convert float to int (could also pass in float registers)
- return (machine_int_t)mp_obj_float_get(obj);
+ } else if (type == &mp_type_float) {
+ // convert float to int (could also pass in float registers)
+ return (machine_int_t)mp_obj_float_get(obj);
#endif
- } else if (MP_OBJ_IS_TYPE(obj, &mp_type_tuple)) {
- // pointer to start of tuple (could pass length, but then could use len(x) for that)
- uint len;
- mp_obj_t *items;
- mp_obj_tuple_get(obj, &len, &items);
- return (machine_uint_t)items;
- } else if (MP_OBJ_IS_TYPE(obj, &mp_type_list)) {
- // pointer to start of list (could pass length, but then could use len(x) for that)
- uint len;
- mp_obj_t *items;
- mp_obj_list_get(obj, &len, &items);
- return (machine_uint_t)items;
- } else {
- // just pass along a pointer to the object
- return (machine_uint_t)obj;
+ } else if (type == &mp_type_tuple) {
+ // pointer to start of tuple (could pass length, but then could use len(x) for that)
+ uint len;
+ mp_obj_t *items;
+ mp_obj_tuple_get(obj, &len, &items);
+ return (machine_uint_t)items;
+ } else if (type == &mp_type_list) {
+ // pointer to start of list (could pass length, but then could use len(x) for that)
+ uint len;
+ mp_obj_t *items;
+ mp_obj_list_get(obj, &len, &items);
+ return (machine_uint_t)items;
+ } else if (type->buffer_p.get_buffer != NULL) {
+ // supports the buffer protocol, get a pointer to the data
+ buffer_info_t bufinfo;
+ type->buffer_p.get_buffer(obj, &bufinfo, BUFFER_READ);
+ return (machine_uint_t)bufinfo.buf;
+ } else {
+ // just pass along a pointer to the object
+ return (machine_uint_t)obj;
+ }
}
}