Skip to content

✨ Add evm_asm_vec & evm_asm macros#1

Merged
Philogy merged 2 commits intoPhilogy:mainfrom
clabby:cl/evm_asm_macro
Oct 23, 2023
Merged

✨ Add evm_asm_vec & evm_asm macros#1
Philogy merged 2 commits intoPhilogy:mainfrom
clabby:cl/evm_asm_macro

Conversation

@clabby
Copy link
Copy Markdown
Contributor

@clabby clabby commented Oct 23, 2023

Overview

Adds two new macros, evm_asm_vec & evm_asm, which shorthand the process of creating a Vec with Asm variants in it.

Example

use evm_glue::{assembly::{*, Asm::*}, opcodes::{*, Opcode::*}, utils::*, evm_asm, evm_asm_vec};
use hex_literal::hex;

let mut runtime_marks = MarkTracker::new();
let empty_revert = runtime_marks.next();
let push0_var = Asm::Op(PUSH0);

let runtime_macro = evm_asm!(
    // Load x, y
    VAR push0_var,
    CALLDATALOAD,            // x
    PUSH1(hex!("20")),
    CALLDATALOAD,            // x, y
    // Add and check for overflow
    DUP2,                    // x, y, x    
    ADD,                     // x, r       
    DUP1,                    // x, r, r    
    SWAP2,                   // r, r, x    
    GT,                      // r, x > r   
    Asm::mref(empty_revert), // r, x > r, l
    JUMPI,                   // r          
    // Return result.
    MSIZE,
    MSTORE,
    MSIZE,
    PUSH0,
    RETURN,
    // Revert
    Mark(empty_revert),
    JUMPDEST,
    PUSH0,
    PUSH0,
    REVERT,
);

also fixes doctests

@clabby clabby mentioned this pull request Oct 23, 2023
@Philogy
Copy link
Copy Markdown
Owner

Philogy commented Oct 23, 2023

Thanks for the contrib, looks good!

@Philogy Philogy merged commit bf1cced into Philogy:main Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants