Skip to content

Commit 54b6bc1

Browse files
committed
Merge pull request #81 from afernandez90/develop
C++11 lambda expressions support
2 parents 2f7c0d1 + cb54dfd commit 54b6bc1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/common/Functions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ trait CGenTupledFunctions extends CGenFunctions with GenericGenUnboxedTupleAcces
376376

377377
override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match {
378378
case Lambda(fun, UnboxedTuple(xs), y) =>
379-
stream.println(remap(y.tp)+" "+quote(sym)+"("+xs.map(s=>remap(s.tp)+" "+quote(s)).mkString(",")+") {")
379+
stream.println("auto "+quote(sym)+" = [&]("+xs.map(s=>remap(s.tp)+" "+quote(s)).mkString(",")+") {")
380380
emitBlock(y)
381381
val z = getBlockResult(y)
382382
if (remap(z.tp) != "void")
383383
stream.println("return " + quote(z) + ";")
384-
stream.println("}")
384+
stream.println("};")
385385
case Apply(fun, UnboxedTuple(args)) =>
386386
emitValDef(sym, quote(fun) + args.map(quote).mkString("(", ",", ")"))
387387
case _ => super.emitNode(sym,rhs)

test-out/epfl/test14-cgen2.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int32_t main(int32_t);
88
#include <string.h>
99
#include <stdbool.h>
1010
int32_t main(int32_t x0) {
11-
int32_t x1(int32_t x2,int32_t x3) {
11+
auto x1 = [&](int32_t x2,int32_t x3) {
1212
int32_t x4 = x2;
1313
bool x6 = x4 == 0;
1414
int32_t x12;
@@ -22,7 +22,7 @@ int32_t x10 = x4 * x9;
2222
x12 = x10;
2323
}
2424
return x12;
25-
}
25+
};
2626
int32_t x15 = x1(4,0);
2727
printf(string("Hello, world! %d\n").c_str(),x15);
2828
return 0;

0 commit comments

Comments
 (0)