Skip to content

Commit

Permalink
Merge pull request #130 from jck/py35
Browse files Browse the repository at this point in the history
Python 3 fixes, test improvements
  • Loading branch information
jandecaluwe committed Oct 7, 2015
2 parents ddcc815 + ba99b90 commit bd0cfba
Show file tree
Hide file tree
Showing 50 changed files with 174 additions and 139 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ python:
- "2.7"
- "pypy"
- "3.4"
- "3.5"

addons:
apt:
Expand All @@ -30,6 +31,10 @@ matrix:
env: CI_TARGET=iverilog
- python: "3.4"
env: CI_TARGET=ghdl
- python: "3.5"
env: CI_TARGET=iverilog
- python: "3.5"
env: CI_TARGET=ghdl

script: ./scripts/ci.sh

Expand Down
3 changes: 3 additions & 0 deletions myhdl/_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def __repr__(self):

__str__ = __repr__

def __int__(self):
return int(self._val, 2)

def __hex__(self):
return hex(int(self._val, 2))

Expand Down
20 changes: 17 additions & 3 deletions myhdl/conversion/_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ def visit_List(self, node):
self.raiseError(node, _error.NotSupported, "list")
def visitSliceObj(self, node):
self.raiseError(node, _error.NotSupported, "slice object")

# All try blocks from python 3.3+
def visit_Try(self, node):
self.raiseError(node, _error.NotSupported, "try statement")

# Legacy try blocks
def visit_TryExcept(self, node):
self.raiseError(node, _error.NotSupported, "try-except statement")
def visit_TryFinally(self, node):
Expand All @@ -257,11 +263,19 @@ def visit_Assign(self, node):
self.visit(node.value)

def visit_Call(self, node):
if node.starargs:
# ast.Call signature changed in python 3.5
# http://greentreesnakes.readthedocs.org/en/latest/nodes.html#Call
if sys.version_info >= (3, 5):
starargs = any(isinstance(arg, ast.Starred) for arg in node.args)
kwargs = any(kw.arg is None for kw in node.keywords)
else:
starargs = node.starargs is not None
kwargs = node.kwargs is not None

if starargs:
self.raiseError(node, _error.NotSupported, "extra positional arguments")
if node.kwargs:
if kwargs:
self.raiseError(node, _error.NotSupported, "extra named arguments")
# f = eval(_unparse(node.node), self.tree.symdict)
self.generic_visit(node)

def visit_Compare(self, node):
Expand Down
1 change: 0 additions & 1 deletion myhdl/test/__init__.py

This file was deleted.

Empty file added myhdl/test/bugs/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions myhdl/test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys

import py
import pytest

Expand All @@ -8,6 +10,9 @@

all_sims = list(_simulators)

if sys.version_info[0] > 2:
collect_ignore = ['conversion/toVerilog/test_not_supported_py2.py']

def pytest_addoption(parser):
parser.addoption("--sim", action="store", choices=all_sims,
help="HDL Simulator")
Expand Down
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions myhdl/test/conversion/toVHDL/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ def logic():
expect = 0
yield reset.posedge
# assert count == expect
print count
print(count)
while 1:
yield clock.posedge
if enable:
expect = (expect + 1) % n
yield delay(1)
# print "%d count %s expect %s count_v %s" % (now(), count, expect, count_v)
# assert count == expect
print count
print(count)
return logic


Expand Down
10 changes: 5 additions & 5 deletions myhdl/test/conversion/toVHDL/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ def stimulus():
a.next = 0xaa
b.next = 0x55
yield clock.posedge
print 'a=%s b=%s' % (a, b)
print('a=%s b=%s' % (a, b))

op.next = bitwise_op.BW_AND
yield clock.posedge
print c
print(c)

op.next = bitwise_op.BW_ANDN
yield clock.posedge
print c
print(c)

op.next = bitwise_op.BW_OR
yield clock.posedge
print c
print(c)

op.next = bitwise_op.BW_XOR
yield clock.posedge
print c
print(c)

raise StopSimulation

Expand Down
2 changes: 1 addition & 1 deletion myhdl/test/conversion/toVHDL/test_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def stimulus():
for i in range(100):
a.next = data[i]
yield delay(10)
print z
print(z)

return stimulus, looptest_inst

Expand Down
4 changes: 2 additions & 2 deletions myhdl/test/conversion/toVHDL/test_newcustom.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ def logic():
expect = 0
yield reset.posedge
# assert count == expect
print count
print(count)
while 1:
yield clock.posedge
if enable:
expect = (expect + 1) % n
yield delay(1)
# print "%d count %s expect %s count_v %s" % (now(), count, expect, count_v)
# assert count == expect
print count
print(count)
return logic


Expand Down
70 changes: 35 additions & 35 deletions myhdl/test/conversion/toVHDL/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,27 @@ def check():
yield left, right
yield delay(1)

print Bitand
print Bitor
print Bitxor
print FloorDiv
print LeftShift
print(Bitand)
print(Bitor)
print(Bitxor)
print(FloorDiv)
print(LeftShift)

# print Pow, Pow_v

print Modulo
print RightShift
print Mul
print Sub
print Sum
print int(EQ)
print int(NE)
print int(LT)
print int(GT)
print int(LE)
print int(GE)
print int(Booland)
print int(Boolor)
print(Modulo)
print(RightShift)
print(Mul)
print(Sub)
print(Sum)
print(int(EQ))
print(int(NE))
print(int(LT))
print(int(GT))
print(int(LE))
print(int(GE))
print(int(Booland))
print(int(Boolor))

return binops, stimulus, check

Expand Down Expand Up @@ -253,11 +253,11 @@ def check():
yield argm, argn, argp
yield delay(1)

print Bitand
print Bitor
print Bitxor
print int(Booland)
print int(Boolor)
print(Bitand)
print(Bitor)
print(Bitxor)
print(int(Booland))
print(int(Boolor))

return multiops, stimulus, check

Expand Down Expand Up @@ -315,8 +315,8 @@ def check():
while 1:
yield arg
yield delay(1)
print int(Not_kw)
print Invert
print(int(Not_kw))
print(Invert)
# check unary operator support in vhdl
# print UnaryAdd
# print UnarySub
Expand Down Expand Up @@ -449,16 +449,16 @@ def check():
while True:
yield left, right
yield delay(1)
print Bitand
print Bitor
print Bitxor
print Sub
print Sum
print FloorDiv
print LeftShift
print Modulo
print Mul
print RightShift
print(Bitand)
print(Bitor)
print(Bitxor)
print(Sub)
print(Sum)
print(FloorDiv)
print(LeftShift)
print(Modulo)
print(Mul)
print(RightShift)

return augmops, stimulus, check

Expand Down
50 changes: 25 additions & 25 deletions myhdl/test/conversion/toVHDL/test_signed.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,24 @@ def check():
## self.assertEqual(Bitor, Bitor_v)
## self.assertEqual(Bitxor, Bitxor_v)
## ## self.assertEqual(FloorDiv, FloorDiv_v)
print LeftShift
print(LeftShift)
# print Modulo
print Mul
print(Mul)
# self.assertEqual(Pow, Pow_v)
print RightShift
print Sub
print Sum
print Sum1
print Sum2
print Sum3
print int(EQ)
print int(NE)
print int(LT)
print int(GT)
print int(LE)
print int(GE)
print int(BoolAnd)
print int(BoolOr)
print(RightShift)
print(Sub)
print(Sum)
print(Sum1)
print(Sum2)
print(Sum3)
print(int(EQ))
print(int(NE))
print(int(LT))
print(int(GT))
print(int(LE))
print(int(GE))
print(int(BoolAnd))
print(int(BoolOr))

return binops, stimulus, check

Expand Down Expand Up @@ -255,9 +255,9 @@ def check():
yield arg
yield delay(1)
# print BoolNot
print Invert
print(Invert)
# print UnaryAdd
print UnarySub
print(UnarySub)


return unaryops, stimulus, check
Expand Down Expand Up @@ -399,12 +399,12 @@ def check():
## self.assertEqual(Bitor, Bitor_v)
## self.assertEqual(Bitxor, Bitxor_v)
## self.assertEqual(FloorDiv, FloorDiv_v)
print LeftShift
print(LeftShift)
## self.assertEqual(Modulo, Modulo_v)
print Mul
print RightShift
print Sub
print Sum
print(Mul)
print(RightShift)
print(Sub)
print(Sum)

return augmops, stimulus, check

Expand Down Expand Up @@ -488,8 +488,8 @@ def check():
while 1:
yield clk.posedge
yield delay(1)
print int(a)
print int(b)
print(int(a))
print(int(b))

@instance
def clkgen():
Expand Down
Empty file.
6 changes: 3 additions & 3 deletions myhdl/test/conversion/toVerilog/test_GrayInc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

from myhdl import *

from test_bin2gray import bin2gray
from test_inc import inc
from .test_bin2gray import bin2gray
from .test_inc import inc

from util import setupCosimulation
from .util import setupCosimulation

ACTIVE_LOW, INACTIVE_HIGH = 0, 1

Expand Down
27 changes: 0 additions & 27 deletions myhdl/test/conversion/toVerilog/test_NotSupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,6 @@ def logic():
return logic
self.check(g, z, a)

def testBackquote(self):
a = Signal(bool())
z = Signal(bool())
def g(z, a):
@instance
def logic():
while 1:
yield a
z.next = 1
`a`
return logic
self.check(g, z, a)


def testClass(self):
a = Signal(bool())
z = Signal(bool())
Expand Down Expand Up @@ -102,19 +88,6 @@ def logic():
return logic
self.check(g, z, a)

def testExec(self):
a = Signal(bool())
z = Signal(bool())
def g(z, a):
@instance
def logic():
while 1:
yield a
z.next = 1
exec "1 + 2" in globals , locals
return logic
self.check(g, z, a)

def testFrom(self):
a = Signal(bool())
z = Signal(bool())
Expand Down

0 comments on commit bd0cfba

Please sign in to comment.