Skip to content

Conversation

@devtooligan
Copy link

Worked on this with a lot of help from ChatGPT. Still not working though.

Please let me know if this is the correct approach or what would be a good way to do this, I can work on it more later.

@shafu0x
Copy link
Owner

shafu0x commented Sep 24, 2023

Cool! This is a perfectly valid approach.
The only thing one could think about is making it more general so you don't explicitly need to check for each DUP and SWAP type (its a lot of duplicated code). If you want to see how one could deal with this check out this example https://github.com/shafu0x/halstead-bytecode-complexity/blob/26e60b3638025347e91dfe6453b0161e94394df1/src/opcode.rs#L283

On the other hand I really like the simplicity of this!
So if you can make this work, we can think about refactoring this later.

pub pops: usize,
pub pushes: usize,
pub swap: usize,
pub dupe: usize,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small detail, but I would call this dup

let second = &mut rest[index - 1];
std::mem::swap(&mut first[0], second);
} else {
// Handle out of bounds
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just panic here

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