I try to generate the verilog code from chisel
My code is:
class RegFifo[T <: Data](gen:T, depth:Int) extends Fifo(gen:T, depth:Int){
def counter(depth: Int, incr: Bool): (UInt, UInt)= {
val cntReg = RegInit(0.U(log2Ceil(depth).W))
val nextVal = Mux(cntReg === (depth-1).U, 0.U, cntReg+1.U)
when (incr){
cntReg := nextVal
}
(cntReg, nextVal)
}
.
.
.
}
object RegFifoDriver extends App {
(new chisel3.stage.ChiselStage).emitVerilog(new RegFifo(args, args), args)//, depth)//, args)
}
I got the error message is:
[error] found : Array[String]
[error] required: Int
[error] (new chisel3.stage.ChiselStage).emitVerilog(new RegFifo(args, args), args)//, depth)//, args)
[error] ^
[error] one error found
I know the error because of the 'emitVerilog(new RegFifo(args, args)' but how can I fix it? THX.
Related
MUnit is a new Scala testing library with rich filtering capabilities.
Here's the example on the website that I cannot get working:
import scala.util.Properties
import munit._
object Windows213 extends Tag("Windows213")
class MySuite extends FunSuite {
// reminder: type Test = GenericTest[Any]
override def munitNewTest(test: Test): Test = {
val isIgnored =
options.tags(Windows213) && !(
Properties.isWin &&
Properties.versionNumberString.startsWith("2.13")
)
if (isIgnored) test.withBody(() => Ignore)
else test
}
test("windows-213".tag(Windows213)) {
// Only runs when operating system is Windows and Scala version is 2.13
}
test("normal test") {
// Always runs like a normal test.
}
}
Changing from options.tags to test.tags solves one of the errors.
The if (isIgnored) test.withBody(() => Ignore) line is still erroring out with this message:
[error] /Users/powers/Documents/code/my_apps/munit-example/src/test/scala/com/github/mrpowers/munit/example/RichFiltersSpec.scala:16:40: type mismatch;
[error] found : munit.Tag
[error] required: MySuite.this.TestValue
[error] (which expands to) scala.concurrent.Future[Any]
[error] if (isIgnored) test.withBody(() => Ignore)
[error] ^
[error] one error found
[error] (Test / compileIncremental) Compilation failed
Update
The feature is currently broken but is scheduled to be fixed.
Will report back with an update when the example is fixed.
This has been fixed as of version 0.6.0-M1.
This is the new syntax.
This code works as expected:
package com.github.mrpowers.munit.example
import scala.util.Properties
import munit._
object Windows213 extends Tag("Windows213")
class MySuite extends FunSuite {
override def munitTestTransforms = super.munitTestTransforms ++ List(
new TestTransform("Windows213", { test =>
val isIgnored =
test.tags(Windows213) && !(
Properties.isWin &&
Properties.versionNumberString.startsWith("2.13")
)
if (isIgnored) test.tag(Ignore)
else test
})
)
test("windows-213".tag(Windows213)) {
assertEquals(2, 3)
}
test("normal test") {
assertEquals(2, 2)
}
}
I'm not sure what is wrong here.
The following code block is throwing error:
(for {
(e,r) <- tblDetail.joinLeft(tblMaster).on((e,r) => r.col1 === e.col3)
} yield (e.id)
Error
No matching Shape found.
[error] Slick does not know how to map the given types.
[error] Possible causes: T in Table[T] does not match your * projection,
[error] you use an unsupported type in a Query (e.g. scala List),
[error] or you forgot to import a driver api into scope.
[error] Required level: slick.lifted.FlatShapeLevel
[error] Source type: (slick.lifted.Rep[Int], slick.lifted.Rep[String],...)
[error] Unpacked type: T
[error] Packed type: G
[error] (e,r) <- tblDetail.joinLeft(tblMaster).on((e,r) => r.col1 === e.col3)
I checked the Slick Tables for tblDetail and tblMaster they seemed to be fine.
tblMaster
class TblMaster(tag:Tag)
extends Table[(Int,String,...)](tag, "tbl_master") {
def id = column[Int]("id")
def col3 = column[String]("col3")
def * = (id,col3)
}
tblDetail
class TblDetail(tag:Tag)
extends Table[Entity](tag, "tbl_detail") {
def id = column[Int]("id")
def col1 = column[String]("col1")
def * : ProvenShape[Entity] = (id,col1) <>
((Entity.apply _).tupled, Entity.unapply)
}
Any help would be appreciable.
I have a trait that I want to mock and use that mocked Trait in another Service during testing. The problem is, that I receive a Nullpointerexception when I try to mock the return value of the indexDocuments function.
Testmethod:
"createDemand must return None if writing to es fails" in new WithApplication {
val demandDraft = DemandDraft(UserId("1"), "socken bekleidung wolle", Location(Longitude(52.468562), Latitude(13.534212)), Distance(30), Price(25.0), Price(77.0))
val es = mock[ElasticsearchClient]
val sphere = mock[SphereClient]
val productTypes = mock[ProductTypes]
sphere.execute(any[ProductCreateCommand]) returns Future.successful(product)
productTypes.demand returns ProductTypeBuilder.of("demand", ProductTypeDrafts.demand).build()
// this line throws the nullpointer exception
es.indexDocument(any[IndexName], any[TypeName], any[JsValue]) returns Future.failed(new RuntimeException("test exception"))
val demandService = new DemandService(es, sphere, productTypes)
demandService.createDemand(demandDraft) must be (Option.empty[Demand]).await
}
Trait:
sealed trait ElasticsearchClient {
implicit def convertListenableActionFutureToScalaFuture[T](x: ListenableActionFuture[T]): Future[T] = {
val p = Promise[T]()
x.addListener(new ActionListener[T] {
def onFailure(e: Throwable) = p.failure(e)
def onResponse(response: T) = p.success(response)
})
p.future
}
lazy val client = createElasticsearchClient()
def close(): Unit
def createElasticsearchClient(): Client
def indexDocument(esIndex: IndexName, esType: TypeName, doc: JsValue): Future[IndexResponse] =
client.prepareIndex(esIndex.value, esType.value).setSource(doc.toString()).execute()
def search(esIndex: IndexName, esType: TypeName, query: QueryBuilder): Future[SearchResponse] =
client.prepareSearch(esIndex.value).setTypes(esType.value).setQuery(query).execute()
}
Exception
[error] NullPointerException: (DemandServiceSpec.scala:89)
[error] services.DemandServiceSpec$$anonfun$1$$anonfun$apply$8$$anon$2$$anonfun$8.apply(DemandServiceSpec.scala:89)
[error] services.DemandServiceSpec$$anonfun$1$$anonfun$apply$8$$anon$2$$anonfun$8.apply(DemandServiceSpec.scala:89)
[error] services.DemandServiceSpec$$anonfun$1$$anonfun$apply$8$$anon$2.delayedEndpoint$services$DemandServiceSpec$$anonfun$1$$anonfun$apply$8$$anon$2$1(DemandServiceSpec.scala:89)
[error] services.DemandServiceSpec$$anonfun$1$$anonfun$apply$8$$anon$2$delayedInit$body.apply(DemandServiceSpec.scala:81)
[error] play.api.test.WithApplication$$anonfun$around$1.apply(Specs.scala:23)
[error] play.api.test.WithApplication$$anonfun$around$1.apply(Specs.scala:23)
[error] play.api.test.PlayRunners$class.running(Helpers.scala:49)
[error] play.api.test.Helpers$.running(Helpers.scala:403)
[error] play.api.test.WithApplication.around(Specs.scala:23)
[error] play.api.test.WithApplication.delayedInit(Specs.scala:20)
[error] services.DemandServiceSpec$$anonfun$1$$anonfun$apply$8$$anon$2.<init>(DemandServiceSpec.scala:81)
[error] services.DemandServiceSpec$$anonfun$1$$anonfun$apply$8.apply(DemandServiceSpec.scala:81)
[error] services.DemandServiceSpec$$anonfun$1$$anonfun$apply$8.apply(DemandServiceSpec.scala:81)
Please let me know if you need additional information.
I found out that the any[] Matchers in the indexDocuments call are the problem. When I replace them with the actual values it works:
"createDemand must return None if writing to es fails and deleteDemand should be called once with correct parameters" in new WithApplication {
val demandDraft = DemandDraft(UserId("1"), "socken bekleidung wolle", Location(Longitude(52.468562), Latitude(13.534212)), Distance(30), Price(25.0), Price(77.0))
val es = mock[ElasticsearchClient]
val sphere = mock[SphereClient]
val productTypes = mock[ProductTypes]
sphere.execute(any[ProductCreateCommand]) returns Future.successful(product)
sphere.execute(any[ProductDeleteByIdCommand]) returns Future.successful(product)
productTypes.demand returns ProductTypeBuilder.of("demand", ProductTypeDrafts.demand).build()
es.indexDocument(IndexName("demands"), TypeName("demands"), Json.toJson(demand)) returns Future.failed(new RuntimeException("test exception"))
val demandService = new DemandService(es, sphere, productTypes)
demandService.createDemand(demandDraft) must be (Option.empty[Demand]).await
}
I've had this happen a whole bunch and work around it by creating a class (rather than a trait) to feed to mock:
trait SomeTraitYouWantToMock {
…
}
class MockableSomeTraitYouWantToMock extends SomeTraitYouWantToMock
val whatever = mock[MockableSomeTraitYouWantToMock]
The following code snippet shows how to save an uploaded file into MongoDB directly:
object MyController extends Controller {
...
def saveImage = Action.async(fsBodyParser) { implicit request =>
val result = for { file <- request.body.files.head.ref
update <- {
fsService.update(
file.id,
Json.obj("metadata" -> Json.obj("category" -> "image"))
)
}
} yield update
result.map { _ =>
Created(success).withHeaders(LOCATION -> s"${localHost.baseUrl}${request.uri}")
}
}
private def fsBodyParser()(
implicit fsService: FsServiceComponent#FsService
): BodyParser[MultipartFormData[Future[MetaFile]]] = {
import BodyParsers.parse._
multipartFormData(Multipart.handleFilePart {
case Multipart.FileInfo(partName, filename, contentType) =>
fsService.iteratee(filename, contentType)
})
}
}
The code above compiles and works correctly up to Play 2.3.x... while if I try to compile it with Play 2.4.x I always get the following error messages:
[error] /home/j3d/Projects/test/app/controllers/MyController.scala:71: not found: value handleFilePart
[error] multipartFormData(handleFilePart {
[error] ^
[error] /home/j3d/Projects/test/app/controllers/MyController:72: not found: value FileInfo
[error] case FileInfo(partName, filename, contentType) =>
[error] ^
[error] (compile:compile) Compilation failed
[error] Total time: 2 s, completed Jan 3, 2015 2:11:47 PM
Look at the latest version of Multipart.scala... Multipart.handleFilePart is private now, and it looks like there is no other option than handleFilePartAsTemporaryFile. Why? Is there a workaround?
I try to write example code to combine akka and actor. But I got the error message when compile the code.
The code is really simple as showed below.
So, What have I got wrong?
[error] /home/qos/workspaces/actors/actors.scala:20: type mismatch;
[error] found : Unit
[error] required: scala.sys.process.ProcessLogger
[error] execute(cmd)
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
The code is
import scala.sys.process._
import akka.actor._
object TryActor {
def main(args: Array[String]) {
val akkaSystem = ActorSystem("akkaSystem")
val worker = akkaSystem.actorOf(Props[Worker], name = "work0")
worker ! Command("ls")
}
case class Command(cmd: String)
class Worker extends Actor {
def receive = {
case Command(cmd) => {
println(cmd)
"echo recieve message from someone" !
execute(cmd.toString)
}
}
def execute(cmd: String) {
val process = Process(cmd.toString)
process ! ProcessLogger(_ => {})
}
}
}
It's interpreting execute(cmd.toString) as the argument to !, because newlines don't necessarily end statements. To fix this, don't use postfix syntax, which is deprecated for a reason:
def receive = {
case Command(cmd) => {
println(cmd)
"echo recieve message from someone".!
execute(cmd.toString)
}
}