diff options
author | Damien George <damien.p.george@gmail.com> | 2014-09-29 22:10:41 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-09-29 22:10:41 +0100 |
commit | e9dac3b4d039997f446b6a615d580d284497d59b (patch) | |
tree | 3ffda8af59c5c5008883d52c54264057b1c49392 /py/nativeglue.c | |
parent | 44c96b2314f5519643f5c8baa1c05f4f5ce6ff7c (diff) | |
download | micropython-e9dac3b4d039997f446b6a615d580d284497d59b.tar.gz micropython-e9dac3b4d039997f446b6a615d580d284497d59b.zip |
py: Add casting to viper; add native mem stores to viper.
Viper can now do the following:
def store(p:ptr8, c:int):
p[0] = c
This does a store of c to the memory pointed to by p using a machine
instructions inline in the code.
Diffstat (limited to 'py/nativeglue.c')
-rw-r--r-- | py/nativeglue.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/py/nativeglue.c b/py/nativeglue.c index 235c4a4dbe..05fadb7b0d 100644 --- a/py/nativeglue.c +++ b/py/nativeglue.c @@ -51,8 +51,16 @@ mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) { switch (type & 3) { case MP_NATIVE_TYPE_OBJ: return (mp_uint_t)obj; case MP_NATIVE_TYPE_BOOL: - case MP_NATIVE_TYPE_INT: - case MP_NATIVE_TYPE_UINT: return mp_obj_get_int(obj); + case MP_NATIVE_TYPE_INT: return mp_obj_get_int(obj); + case MP_NATIVE_TYPE_UINT: { + mp_buffer_info_t bufinfo; + if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_RW)) { + return (mp_uint_t)bufinfo.buf; + } else { + // TODO should be mp_obj_get_uint_truncated or something + return mp_obj_get_int(obj); + } + } default: assert(0); return 0; } } |