py: Implement bool unary op; tidy up unary op dispatch.
diff --git a/py/objbool.c b/py/objbool.c
index 729ffb4..53b2bf8 100644
--- a/py/objbool.c
+++ b/py/objbool.c
@@ -6,6 +6,7 @@
 #include "mpconfig.h"
 #include "qstr.h"
 #include "obj.h"
+#include "runtime0.h"
 #include "runtime.h"
 
 typedef struct _mp_obj_bool_t {
@@ -32,11 +33,24 @@
     }
 }
 
+static mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
+    machine_int_t value = ((mp_obj_bool_t*)o_in)->value;
+    switch (op) {
+        case RT_UNARY_OP_NOT: if (value) { return mp_const_false; } else { return mp_const_true; }
+        case RT_UNARY_OP_POSITIVE: return MP_OBJ_NEW_SMALL_INT(value);
+        case RT_UNARY_OP_NEGATIVE: return MP_OBJ_NEW_SMALL_INT(-value);
+        case RT_UNARY_OP_INVERT:
+        default: // no other cases
+            return MP_OBJ_NEW_SMALL_INT(~value);
+    }
+}
+
 const mp_obj_type_t bool_type = {
     { &mp_const_type },
     "bool",
     .print = bool_print,
     .make_new = bool_make_new,
+    .unary_op = bool_unary_op,
 };
 
 static const mp_obj_bool_t false_obj = {{&bool_type}, false};
diff --git a/py/objstr.c b/py/objstr.c
index 337b42e..82e97c0 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -447,7 +447,7 @@
         if (l1 != l2) {
             return false;
         }
-        return strncmp((const char*)d1, (const char*)d2, l1) == 0;
+        return memcmp(d1, d2, l1) == 0;
     }
 }
 
diff --git a/py/qstr.c b/py/qstr.c
index 6ce9e8b..268b3ba 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -106,7 +106,7 @@
     // search pools for the data
     for (qstr_pool_t *pool = last_pool; pool != NULL; pool = pool->prev) {
         for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
-            if (Q_GET_HASH(*q) == str_hash && Q_GET_LENGTH(*q) == str_len && strncmp((const char*)Q_GET_DATA(*q), (const char*)str, str_len) == 0) {
+            if (Q_GET_HASH(*q) == str_hash && Q_GET_LENGTH(*q) == str_len && memcmp(Q_GET_DATA(*q), str, str_len) == 0) {
                 return pool->total_prev_len + (q - pool->qstrs);
             }
         }
diff --git a/py/runtime.c b/py/runtime.c
index d6b2bf7..0d9906e 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -479,16 +479,16 @@
             return MP_OBJ_NEW_SMALL_INT(val);
         }
         return mp_obj_new_int(val);
-    } else { // will be an object (small ints are caught in previous if)
-        mp_obj_base_t *o = arg;
-        if (o->type->unary_op != NULL) {
-            mp_obj_t result = o->type->unary_op(op, arg);
+    } else {
+        mp_obj_type_t *type = mp_obj_get_type(arg);
+        if (type->unary_op != NULL) {
+            mp_obj_t result = type->unary_op(op, arg);
             if (result != NULL) {
                 return result;
             }
         }
         // TODO specify in error message what the operator is
-        nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "bad operand type for unary operator: '%s'", o->type->name));
+        nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "bad operand type for unary operator: '%s'", type->name));
     }
 }