Fun at work: compiling solidity in elm

383 solint/src/Codec.elm 
364 solint/src/Compiler.elm
35 solint/src/Main.elm
7 solint/src/Ports.elm
70 solint/src/Solidity.elm
22 solint/src/TestData.elm
263 solint/src/TypeInf.elm
145 solint/src/Types.elm
8 solint/src/Util.elm
1297 total
, JD.map3 (\_ base indx -> Array base (Just indx)) 
(JD.field “type” (jdIsValue “array” JD.string))
(JD.field “base” self)
(JD.field “indx” expression)
, JD.map2 (\_ base -> Array base Nothing)
(JD.field “type” (jdIsValue “array” JD.string))
(JD.field “base” self)
jdIsValue : a -> JD.Decoder a -> JD.Decoder a 
jdIsValue v d =
d |> JD.andThen
(\w ->
if w == v then
JD.succeed v
else
JD.fail “no match”
)
, JD.map3 (\_ fromType toType -> Mapping { fromType = fromType, toType = toType }) 
(JD.field “type” (jdIsValue “mapping” JD.string))
(JD.field “from” (JD.string |> (JD.andThen (basicType >> jdResult)) |> JD.map Basic))
(JD.field “to” self)
, JD.map3 (always Struct)
(JD.field “type” (jdIsValue “struct” JD.string))
(JD.field “name” JD.string)
(JD.field “members” (JD.dict (JD.field “kind” self)))
]
typeOfExpression : Program -> Contract -> Expr -> RawType 
typeOfExpression p c e =
case e of
-- ...
FunCall e _ ->
case typeOfExpression p c e of
Function f ->
case f.returns of
[] -> Tuple []
hd :: [] -> Tuple.second hd
hd :: tl -> Tuple (List.map Tuple.second f.returns)
Basic a -> Basic a -- basic type coercion
_ -> Debug.crash "call of non-function"
collectDeclarations p c declarations s = 
case s of
Block (hd :: tl) ->
let decl = collectDeclarations p c declarations hd in
collectDeclarations p c decl (Block tl)
Block [] ->
declarations
IfStmt cond thn (Just els) ->
let afterThen = collectDeclarations p c declarations thn in
collectDeclarations p c afterThen els
-- ...
Simple (InitDecl vals expr) ->
let resultType = typeOfExpression p c expr in
case (vals,resultType) of
(vals,Tuple resultType) ->
let vt = List.map2 (,) vals resultType in
List.foldr
(\(n,d) decls -> Dict.insert n d decls)
declarations
vt
([val],resultType) ->
Dict.insert val resultType declarations
(v,r) ->
Debug.crash ("Wrong association between " ++ (toString v) ++ " and " ++ (toString r))
-- ...
BanyanAsset.prototype.currentBlock = function (msg) { 
/* Dict.fromList [(“$$ret0”,Basic (UIntTy 256)),(“$$ret1”,Basic (UIntTy 256))] */
var $$self = this;

msg = msg === undefined ? new message() : msg;
block = msg.block;
var $$ret0 = storageWord(“0”, “uint256”);

var $$ret1 = storageWord(“0”, “uint256”);

this.withScope(function () {
$$self.addEther(msg);
{
return (function (t) {
$$ret0 = (t.index(storageWord(“0”)));
$$ret1 = (t.index(storageWord(“1”)));
}($$self.storageTuple({
type: “tuple”,
kinds: [ “uint256”, “uint256” ]
}, (block.member(“number”, $$self)), (block.member(“timestamp”, $$self)))));
}
});

return $$self.storageTuple({
type: “tuple”,
kinds: [ “uint256”, “uint256” ]
}, $$ret0, $$ret1);
}
try { 
ba.changeOwnerVote(sw(‘0’), bob, sw(‘100’), new message({sender:owner}));
throw new Error(“We shouldn’t be able to change ownership without second vote when there are two owners”);
} catch (e) {
console.log(“[ok] we couldn’t change owners without two votes”);
}
console.log(‘hacking time!’);
var blockAndTime = ba.currentBlock();
var newTime = blockAndTime[1].add(days(5));
solint.hacktime(newTime);
try {
ba.voteAgainstBill(sw(‘0’), new message({sender: owner}));
throw new Error(“We voted against a locked-in bill”);
} catch (e) {
console.log(“[ok] we shouldn’t be able to veto a locked-in bill”);
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store