mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Type inference draft.
This commit is contained in:
committed by
Nikola Matic
parent
6ec4d3dd98
commit
45f00dda3b
@@ -64,7 +64,7 @@ evmasm::AssemblyItems compileContract(std::shared_ptr<CharStream> _sourceCode)
|
||||
Scoper::assignScopes(*sourceUnit);
|
||||
BOOST_REQUIRE(SyntaxChecker(errorReporter, false).checkSyntax(*sourceUnit));
|
||||
GlobalContext globalContext;
|
||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter);
|
||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter, false);
|
||||
DeclarationTypeChecker declarationTypeChecker(errorReporter, solidity::test::CommonOptions::get().evmVersion());
|
||||
solAssert(!Error::containsErrors(errorReporter.errors()), "");
|
||||
resolver.registerDeclarations(*sourceUnit);
|
||||
|
||||
@@ -127,7 +127,7 @@ bytes compileFirstExpression(
|
||||
GlobalContext globalContext;
|
||||
Scoper::assignScopes(*sourceUnit);
|
||||
BOOST_REQUIRE(SyntaxChecker(errorReporter, false).checkSyntax(*sourceUnit));
|
||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter);
|
||||
NameAndTypeResolver resolver(globalContext, solidity::test::CommonOptions::get().evmVersion(), errorReporter, false);
|
||||
resolver.registerDeclarations(*sourceUnit);
|
||||
BOOST_REQUIRE_MESSAGE(resolver.resolveNamesAndTypes(*sourceUnit), "Resolving names failed");
|
||||
DeclarationTypeChecker declarationTypeChecker(errorReporter, solidity::test::CommonOptions::get().evmVersion());
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
pragma experimental solidity;
|
||||
|
||||
type uint256 = word;
|
||||
|
||||
instantiation uint256: + {
|
||||
function add(x, y) -> uint256 {
|
||||
let a = uint256.rep(x);
|
||||
let b = uint256.rep(y);
|
||||
assembly {
|
||||
a := add(a,b)
|
||||
}
|
||||
return uint256.abs(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
instantiation uint256: * {
|
||||
function mul(x, y) -> uint256 {
|
||||
let a = uint256.rep(x);
|
||||
let b = uint256.rep(y);
|
||||
assembly {
|
||||
a := mul(a,b)
|
||||
}
|
||||
return uint256.abs(a);
|
||||
}
|
||||
}
|
||||
instantiation word: * {
|
||||
function mul(x, y) -> word {
|
||||
let z: word;
|
||||
assembly {
|
||||
z := mul(x,y)
|
||||
}
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
||||
instantiation word: integer {
|
||||
function fromInteger(x:integer) -> word {
|
||||
//x + x;
|
||||
}
|
||||
}
|
||||
|
||||
instantiation word: == {
|
||||
function eq(x, y) -> bool {
|
||||
assembly {
|
||||
x := eq(x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function f(x:uint256->uint256,y:uint256) -> uint256
|
||||
{
|
||||
return x(y);
|
||||
}
|
||||
|
||||
function g(x:uint256) -> uint256
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
contract C {
|
||||
fallback() external {
|
||||
let arg;
|
||||
assembly {
|
||||
arg := calldataload(0)
|
||||
}
|
||||
let x : word;
|
||||
if (bool.abs(arg)) {
|
||||
assembly {
|
||||
x := 0x10
|
||||
}
|
||||
}
|
||||
let w = uint256.abs(x);
|
||||
// w = f(g, w);
|
||||
w = w * w + w;
|
||||
let y : word;
|
||||
let z : (uint256,uint256);
|
||||
assembly { y := 2 }
|
||||
y = uint256.rep(w) * y;
|
||||
assembly {
|
||||
mstore(0, y)
|
||||
return(0, 32)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: true
|
||||
// ----
|
||||
// (): 0 -> 0
|
||||
// (): 1 -> 544
|
||||
@@ -0,0 +1,4 @@
|
||||
function f() pure {
|
||||
uint word; word;
|
||||
uint static_assert; static_assert;
|
||||
}
|
||||
Reference in New Issue
Block a user