Support better param conversions to/from numeric subclasses.
authorSteve Reinhardt <stever@eecs.umich.edu>
Sun, 3 Dec 2006 06:24:52 +0000 (22:24 -0800)
committerSteve Reinhardt <stever@eecs.umich.edu>
Sun, 3 Dec 2006 06:24:52 +0000 (22:24 -0800)
--HG--
extra : convert_revision : 2ccb75b0912a384789458710fd9bbb65626f839e

src/python/m5/params.py

index 9e5f985c358240cb08e9482d2332b6fff9e235b7..d83d5f73fb13c9295b036ff830fbb15a26693611 100644 (file)
@@ -237,6 +237,12 @@ class NumericParamValue(ParamValue):
     def __float__(self):
         return float(self.value)
 
+    def __long__(self):
+        return long(self.value)
+
+    def __int__(self):
+        return int(self.value)
+
     # hook for bounds checking
     def _check(self):
         return
@@ -308,8 +314,11 @@ class CheckedInt(NumericParamValue):
     def __init__(self, value):
         if isinstance(value, str):
             self.value = convert.toInteger(value)
-        elif isinstance(value, (int, long, float)):
+        elif isinstance(value, (int, long, float, NumericParamValue)):
             self.value = long(value)
+        else:
+            raise TypeError, "Can't convert object of type %s to CheckedInt" \
+                  % type(value).__name__
         self._check()
 
 class Int(CheckedInt):      cxx_type = 'int';      size = 32; unsigned = False