mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[Sol2Yul] Adding support for constructor with parameters
This commit is contained in:
parent
4a7d2e590d
commit
89d5ecdd24
@ -259,11 +259,28 @@ string IRGenerator::constructorCode(ContractDefinition const& _contract)
|
|||||||
|
|
||||||
if (constructor)
|
if (constructor)
|
||||||
{
|
{
|
||||||
solUnimplementedAssert(constructor->parameters().empty(), "");
|
ABIFunctions abiFunctions(m_evmVersion, m_context.revertStrings(), m_context.functionCollector());
|
||||||
|
unsigned paramVars = make_shared<TupleType>(constructor->functionType(false)->parameterTypes())->sizeOnStack();
|
||||||
|
|
||||||
// TODO base constructors
|
Whiskers t(R"X(
|
||||||
|
let programSize := datasize("<object>")
|
||||||
|
let argSize := sub(codesize(), programSize)
|
||||||
|
|
||||||
out << m_context.functionName(*constructor) + "()\n";
|
let memoryDataOffset := <allocate>(argSize)
|
||||||
|
codecopy(memoryDataOffset, programSize, argSize)
|
||||||
|
|
||||||
|
<assignToParams> <abiDecode>(memoryDataOffset, add(memoryDataOffset, argSize))
|
||||||
|
|
||||||
|
<constructorName>(<params>)
|
||||||
|
)X");
|
||||||
|
t("object", creationObjectName(_contract));
|
||||||
|
t("allocate", m_utils.allocationFunction());
|
||||||
|
t("assignToParams", paramVars == 0 ? "" : "let " + suffixedVariableNameList("param_", 0, paramVars) + " := ");
|
||||||
|
t("params", suffixedVariableNameList("param_", 0, paramVars));
|
||||||
|
t("abiDecode", abiFunctions.tupleDecoder(constructor->functionType(false)->parameterTypes(), true));
|
||||||
|
t("constructorName", m_context.functionName(*constructor));
|
||||||
|
|
||||||
|
out << t.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
return out.str();
|
return out.str();
|
||||||
|
15
test/libsolidity/semanticTests/constructor_with_params.sol
Normal file
15
test/libsolidity/semanticTests/constructor_with_params.sol
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
contract C {
|
||||||
|
uint public i;
|
||||||
|
uint public k;
|
||||||
|
|
||||||
|
constructor(uint newI, uint newK) public {
|
||||||
|
i = newI;
|
||||||
|
k = newK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// constructor(): 2, 0 ->
|
||||||
|
// i() -> 2
|
||||||
|
// k() -> 0
|
Loading…
Reference in New Issue
Block a user