Skip to content

Commit 999adf3

Browse files
committed
C++ lambda expression generation: Passing parameters by reference to match Scala semantics
1 parent de18c52 commit 999adf3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/common/Functions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ trait CGenFunctions extends CGenEffect with BaseGenFunctions {
349349
// Case for functions with a single argument (therefore, not tupled)
350350
override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match {
351351
case e@Lambda(fun, x, y) =>
352-
stream.println("auto "+quote(sym)+" = [&]("+remap(x.tp)+" "+quote(x)+") {")
352+
stream.println("auto "+quote(sym)+" = [&]("+remap(x.tp)+"& "+quote(x)+") {")
353353
emitBlock(y)
354354
val z = getBlockResult(y)
355355
if (remap(z.tp) != "void")
@@ -374,7 +374,7 @@ trait CGenTupledFunctions extends CGenFunctions with GenericGenUnboxedTupleAcces
374374

375375
override def emitNode(sym: Sym[Any], rhs: Def[Any]) = rhs match {
376376
case Lambda(fun, UnboxedTuple(xs), y) =>
377-
stream.println("auto "+quote(sym)+" = [&]("+xs.map(s=>remap(s.tp)+" "+quote(s)).mkString(",")+") {")
377+
stream.println("auto "+quote(sym)+" = [&]("+xs.map(s=>remap(s.tp)+"& "+quote(s)).mkString(",")+") {")
378378
emitBlock(y)
379379
val z = getBlockResult(y)
380380
if (remap(z.tp) != "void")

test-out/epfl/test14-cgen2.check

Lines changed: 1 addition & 1 deletion
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-
auto 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;

0 commit comments

Comments
 (0)