File tree Expand file tree Collapse file tree 3 files changed +16
-10
lines changed Expand file tree Collapse file tree 3 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -350,8 +350,8 @@ trait CGenFunctions extends CGenEffect with BaseGenFunctions {
350
350
override def emitNode (sym : Sym [Any ], rhs : Def [Any ]) = rhs match {
351
351
case e@ Lambda (fun, x, y) =>
352
352
val retType = remap(getBlockResult(y).tp)
353
- stream.println( " function<" + retType+ " (" +
354
- remap(x.tp) + " )> " + quote(sym)+
353
+ val retTp = if (cppExplicitFunRet == " true " ) " function<" + retType+ " (" + remap(x.tp) + " )> " else " auto "
354
+ stream.println(retTp + " " + quote(sym)+
355
355
" = [&](" + remap(x.tp)+ " " + quote(x)+ " ) {" )
356
356
emitBlock(y)
357
357
val z = getBlockResult(y)
Original file line number Diff line number Diff line change @@ -384,14 +384,17 @@ trait CGenIfThenElse extends CGenEffect with BaseGenIfThenElse {
384
384
emitBlock(b)
385
385
stream.println(" }" )
386
386
case _ =>
387
- stream.println(" %s %s;" .format(remap(sym.tp),quote(sym)))
388
- stream.println(" if (" + quote(c) + " ) {" )
389
- emitBlock(a)
390
- stream.println(" %s = %s;" .format(quote(sym),quote(getBlockResult(a))))
391
- stream.println(" } else {" )
392
- emitBlock(b)
393
- stream.println(" %s = %s;" .format(quote(sym),quote(getBlockResult(b))))
394
- stream.println(" }" )
387
+ val ten = quote(sym) + " True"
388
+ val fen = quote(sym) + " False"
389
+ def emitCondFun [T : Manifest ](fname : String , block : Block [T ]) {
390
+ stream.println(" auto " + fname + " = [&]() {" );
391
+ emitBlock(block)
392
+ stream.println(" return " + quote(getBlockResult(block)) + " ;" )
393
+ stream.println(" };" )
394
+ }
395
+ emitCondFun(ten, a)
396
+ emitCondFun(fen, b)
397
+ stream.println(" auto " + quote(sym) + " = " + quote(c) + " ? " + ten + " () : " + fen + " ();" )
395
398
}
396
399
/*
397
400
val booll = remap(sym.tp).equals("void")
Original file line number Diff line number Diff line change @@ -8,4 +8,7 @@ trait Config {
8
8
9
9
// memory management type for C++ target (refcnt or gc)
10
10
val cppMemMgr = System .getProperty(" lms.cpp.memmgr" ," malloc" )
11
+
12
+ // explicit return type of lambda functions (allows recursive functions but is less generic)
13
+ val cppExplicitFunRet = System .getProperty(" lms.cpp.explicitFunRet" ," true" )
11
14
}
You can’t perform that action at this time.
0 commit comments