Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing parameters by value #497

Closed
h0nzZik opened this issue Jun 25, 2019 · 1 comment
Closed

Passing parameters by value #497

h0nzZik opened this issue Jun 25, 2019 · 1 comment

Comments

@h0nzZik
Copy link
Contributor

h0nzZik commented Jun 25, 2019

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.

@h0nzZik
Copy link
Contributor Author

h0nzZik commented Jul 1, 2019

-- 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.

h0nzZik added a commit to h0nzZik/c-semantics that referenced this issue Jul 2, 2019
h0nzZik added a commit to h0nzZik/c-semantics that referenced this issue Jul 2, 2019
@h0nzZik h0nzZik closed this as completed in dce53ce Jul 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant