Passing parameters by value
Closed this issue · 1 comments
The program
struct A {};
void foo(A a) {}
int main() {
A a;
foo(a);
}
get stuck at execution time, with :=init
on top of the K cell. The RHS of :=init
is:
prv(loc(obj(#token("4","Int"),#token("1","Int"),auto(#token("0","Int"))),#token("0","Int")),`noTrace_CPP-TRACE-SYNTAX`(.KList),tcpp(quals(`.Set`(.KList)),`.Set`(.KList),classType(classId(`GlobalNamespace`(.KList),classSpecifier(`Struct`(.KList),`Identifier`(#token("\"A\"","String")),`.List{"_,__CPP-DYNAMIC-OTHER-SORTS"}`(.KList))))))
I guess that the source of the problem is in that that bindParam
is implemented in the execution semantics ( execution/expr/function-call.k
). That may also be the source of problems for #496.
See also expr.call/7.
-- Draft
Some notes:
In translation semantics, an argument of a function call is turned into initializer in bindParams - the call to figureInit
. For the example above, the initializer is a compoundInit
of beginConstruction
, a call to A::A(A const &)
, and endConstruction
.
In execution semantics,
TODO The initializer internally refers to the object being initialized, is that true? But in the function being called, the 'handle' to the parameter is different (ExecName
). The two handles need to be united - that happens in the bind
part of application
, and in bindParam
. TODO may we bind parameters more directly, without the need for refenrece binding or a copy? The initializer executes (in evalArgs
) with some object being initialized - we do not need to allocate any new object using allocObject
in declareNonStaticObjectExec
. It may be enough to simply addToExecEnv
the object that is used by the initializer.
TODO why bindReference
returns its LHS? What would break if it returned nothing (.K
)?
Related: the third parameter of bindParam
is (at least sometimes) a value denoting the temporary object - even if it is a prv
.