Commits

Anonymous committed 4f60f3e

Boolean and None are no longer subclasses of Integer.

Comments (0)

Files changed (3)

         Among other things Arana uses tagged integers.  The
         assumption is that the system will only use even numbers
         for memory addresses so the odd can be used to store
-        integers.  Additionally the first 3 integers and 0 are
-        used to represent different values:
-
-        === ===============================================
-        0   this value represents AR_NULL which is the
-            equivalent of NULL in C and used to signal
-            errors and other things.
-        1   AR_NONE.  This is equivalent to Python's None
-            or Ruby's nil and use to represent missing
-            values in Arana.
-        3   AR_FALSE.  This value represents boolean false.
-        5   AR_TRUE.  This value represents boolen true.
-        === ===============================================
+        integers.
 
         When a conversion from a C integer into a tagged Arana
-        integer happens the value is left shifted by one and 7
-        is added to make the number odd and skip the special
-        constants.  The reverse operation is translating all
-        special constants but AR_TRUE to 0, AR_TRUE to 1.  If
-        none of the special constants worked right shift by one
-        and subtract 3 to get the correct value again.
+        integer happens the value is left shifted by one and 1
+        is added to make the number odd.  The reverse operation
+	is right shifting by one.
 
     / Arana Signature Functions /
 

arana/primitives.c

 ArObjectType ArBooleanType = {
     .name = "Boolean",
     .flags = AR_TYPE_FAKE,
-    .parent = &ArIntegerType
+    .parent = &ArTypeType
 };
 
 ArObjectType ArNoneType = {
     .name = "NoneType",
     .flags = AR_TYPE_FAKE,
-    .parent = &ArIntegerType
+    .parent = &ArTypeType
 };
 
 AR

arana/primitives.h

 #define AR_BOOLEAN(x) ((x) ? AR_TRUE : AR_FALSE)
 #define AR_INTEGER(x) (AR)((((long)(x)) << 1) + 1)
 
-#define AR_AS_LONG(x) _arana_integer_to_long(x)
-#define AR_AS_SIZET(x) _arana_integer_to_sizet(x)
+#define AR_AS_LONG(x) (long)(x >> 1)
+#define AR_AS_SIZET(x) (Ar_size_t)(x >> 1)
 
 AR_API_DATA(ArObjectType) ArBooleanType;
 AR_API_DATA(ArObjectType) ArNoneType;
 AR_API_FUNC(AR) arana_create_boolean_type(AR_SIG);
 AR_API_FUNC(AR) arana_create_none_type(AR_SIG);
 
-#define _AR_INT_CONV(n, t)                      \
-    static inline long n(AR self) {             \
-        switch (self) {                         \
-        case AR_NULL:                           \
-        case AR_NONE:                           \
-        case AR_FALSE:                          \
-            return 0;                           \
-        case AR_TRUE:                           \
-            return 1;                           \
-        default:                                \
-            return (t)self >> 1;                \
-        }                                       \
-    }
-
-_AR_INT_CONV(_arana_integer_to_long, long)
-_AR_INT_CONV(_arana_integer_to_sizet, Ar_size_t)
 
 #endif /* _ARANA_PRIMITIVES_H */