inline_assembly.rst 1.7 KB

123456789101112131415161718192021222324252627282930313233
  1. Inline Assembly
  2. ===============
  3. In Solidity functions, developers are allowed to write assembly blocks containing Yul code. For more information about
  4. the Yul programming language, please refer to the :ref:`yul section <yul_section>`.
  5. In an assembly block, you can access solidity local variables freely and modify them as well. Bear in mind, however,
  6. that reference types like strings, vectors and structs are memory addresses in yul, so manipulating them can be unsafe
  7. unless done correctly. Any assignment to those variables will change the address the reference points to and
  8. may cause the program to crash if not managed correctly.
  9. .. include:: ../examples/inline_assembly.sol
  10. :code: solidity
  11. Storage variables cannot be accessed nor assigned directly. You must use the ``.slot`` and ``.offset`` suffix to use storage
  12. variables. Storage variables should be read with the ``sload`` and saved with ``sstore`` builtins, but they are not implemented yet.
  13. Solang does not implement offsets for storage variables, so the ``.offset`` suffix will always return zero.
  14. Assignments to the offset are only allowed to Solidity local variables that are a reference to the storage.
  15. .. include:: ../examples/inline_assembly_storage.sol
  16. :code: solidity
  17. Dynamic calldata arrays should be accessed with the ``.offset`` and ``.length`` suffixes. The offset suffix returns the
  18. array's memory address. Assignments to ``.length`` are not yet implemented.
  19. .. include:: ../examples/inline_assembly_calldata.sol
  20. :code: solidity
  21. External functions in Yul can be accessed and modified with the ``.selector`` and ``.address`` suffixes. The assignment
  22. to those values, however, are not yet implemented.
  23. .. include:: ../examples/inline_assembly_external_functions.sol
  24. :code: solidity