Skip to content

Allow calling high-level functions from Yul blocks #265

@mbenke

Description

@mbenke

Simple example

function f() -> word { return 42; }

contract C {
function main() {
  let res: word;
  assembly {
    res := f(42)
  }
  return res;
}

May be more complicated, e.g. f(iszero(iszero(sub(x,1))))

Concept art (see mbenke/callHeaven branch):

specStmt (Asm ys) = do
  ys' <- mapM specYulStmt ys
  pure (Asm ys')
-- specStmt (Asm ys) = Asm ys

specStmt stmt = errors ["specStmt not implemented for: ", show stmt]


specYulStmt :: Yul.YulStmt -> SM Yul.YulStmt
specYulStmt ys = everywhereM (mkM specYulExp) ys

specYulExp :: Yul.YulExp -> SM Yul.YulExp
{-
specYulExp (YCall name args)
    | name `notElem` primYulOps = do
-- result type must be word or () (perhaps the latter only in YExp stmt)
-- arg types must be word (modify typechecker)
-- introduce some variables
-- assign them args (note: Yul probably has righ-to-left eval order)
-- pure (YCall name args')
-}
specYulExp e = pure e

Also need to do something about function renaming, e.g. only rename functions that clash with Yul primOps.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions