Skip to content

Commit 56be2bf

Browse files
author
Alexey Romanov
committed
Add an option to emit explicit types for vals in ScalaCodegen
1 parent ae74c7d commit 56be2bf

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/internal/Config.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ trait Config {
55
val verbosity = System.getProperty("lms.verbosity","0").toInt
66
val sourceinfo = System.getProperty("lms.sourceinfo","0").toInt
77
val addControlDeps = System.getProperty("lms.controldeps","true").toBoolean
8+
9+
val scalaExplicitTypes = System.getProperty("lms.scala.explicitTypes","false").toBoolean
810

911
// memory management type for C++ target (refcnt or gc)
1012
val cppMemMgr = System.getProperty("lms.cpp.memmgr","malloc")

src/internal/ScalaCodegen.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,16 @@ trait ScalaCodegen extends GenericCodegen with Config {
9999
}
100100

101101
def emitValDef(sym: Sym[Any], rhs: String): Unit = {
102-
stream.println("val " + quote(sym) + " = " + rhs + valDefExtra(sym))
102+
if (scalaExplicitTypes)
103+
emitTypedValDef(sym, rhs)
104+
else
105+
stream.println(src"val $sym = $rhs" + valDefExtra(sym))
103106
}
104107

105108
def emitTypedValDef(sym: Sym[Any], rhs: String): Unit = {
106109
stream.println(src"val $sym: ${sym.tp} = $rhs" + valDefExtra(sym))
107110
}
108-
111+
109112
def emitVarDef(sym: Sym[Variable[Any]], rhs: String): Unit = {
110113
stream.println("var " + quote(sym) + ": " + remap(sym.tp) + " = " + rhs)
111114
}

0 commit comments

Comments
 (0)