onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://cadence-lang.org
Apache License 2.0
534 stars 138 forks source link

Refactor interpreter package so we can reuse built-in operations in VM #3693

Open turbolent opened 4 days ago

turbolent commented 4 days ago

We are evaluating how Cadence programs can be executed using an alternative approach, namely compilation (code generation). Programs executed using the alternative approach must behave exactly like the current approach, interpretation using the interpreter.

Currently the implementation of the majority of the built-in functionality of Cadence is part of the package implementing the interpreter, interpreter. The implementation is also tightly coupled to the interpreter.

If we can find a way to decouple the built-in functionality from the interpreter, we can reuse it for the alternative execution approach, and do not have to re-implement the functionality, which is a lot of work, and very difficult to get correct, as it must function exactly like the existing solution.

Decouple and define (an) interface(s) for the following components, so they can be reused outside of the interpreter:

This is difficult, as values are tightly coupled to the interpreter (most functions of the values get passed the full interpreter).

We might want to refactor the code gradually instead of all parts all at once.

interpreter.Value methods depend on the Interpreter for the following categories of operations, for example: