mirror of
https://github.com/myhdl/myhdl.git
synced 2025-01-24 21:52:56 +08:00
add string_types to _compat
This commit is contained in:
parent
9e756bfbf9
commit
9887ad3427
@ -4,10 +4,12 @@ PY2 = sys.version_info[0] == 2
|
|||||||
|
|
||||||
|
|
||||||
if not PY2:
|
if not PY2:
|
||||||
|
string_types = (str, unicode)
|
||||||
integer_types = (int,)
|
integer_types = (int,)
|
||||||
long = int
|
long = int
|
||||||
import builtins
|
import builtins
|
||||||
else:
|
else:
|
||||||
|
str_types = (str,)
|
||||||
integer_types = (int, long)
|
integer_types = (int, long)
|
||||||
long = long
|
long = long
|
||||||
import __builtin__ as builtins
|
import __builtin__ as builtins
|
||||||
|
@ -23,10 +23,9 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
|
||||||
from types import StringType
|
|
||||||
|
|
||||||
from myhdl._bin import bin
|
from myhdl._bin import bin
|
||||||
from myhdl._Signal import _Signal
|
from myhdl._Signal import _Signal
|
||||||
|
from myhdl._compat import string_types
|
||||||
|
|
||||||
class EnumType(object):
|
class EnumType(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -53,7 +52,7 @@ def enum(*names, **kwargs):
|
|||||||
codedict = {}
|
codedict = {}
|
||||||
i = 0
|
i = 0
|
||||||
for name in names:
|
for name in names:
|
||||||
if not isinstance(name, StringType):
|
if not isinstance(name, string_types):
|
||||||
raise TypeError()
|
raise TypeError()
|
||||||
if codedict.has_key(name):
|
if codedict.has_key(name):
|
||||||
raise ValueError("enum literals should be unique")
|
raise ValueError("enum literals should be unique")
|
||||||
|
@ -22,10 +22,9 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
maxint = sys.maxint
|
maxint = sys.maxint
|
||||||
from types import StringType
|
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
from myhdl._compat import long, integer_types
|
from myhdl._compat import long, integer_types, string_types
|
||||||
from myhdl._compat.builtins import max as maxfunc
|
from myhdl._compat.builtins import max as maxfunc
|
||||||
from myhdl._bin import bin
|
from myhdl._bin import bin
|
||||||
|
|
||||||
@ -51,7 +50,7 @@ class intbv(object):
|
|||||||
_nrbits = maxfunc(len(bin(max-1))+1, len(bin(min)))
|
_nrbits = maxfunc(len(bin(max-1))+1, len(bin(min)))
|
||||||
if isinstance(val, integer_types):
|
if isinstance(val, integer_types):
|
||||||
self._val = val
|
self._val = val
|
||||||
elif isinstance(val, StringType):
|
elif isinstance(val, string_types):
|
||||||
mval = val.replace('_', '')
|
mval = val.replace('_', '')
|
||||||
self._val = long(mval, 2)
|
self._val = long(mval, 2)
|
||||||
_nrbits = len(mval)
|
_nrbits = len(mval)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user