-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: initializing conditional stack opcodes #32
base: main
Are you sure you want to change the base?
Conversation
if (self.stack.items.len == 0) { | ||
return ConditionalStackError.EmptyConditionalStack; | ||
} | ||
_ = self.stack.pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you return the value?
Should it be named delete then? Not pop
@okhaimie-dev don't forget to ask for a new review when you are finished pushing your changes |
src/script/cond_stack.zig
Outdated
/// | ||
/// Returns: | ||
/// The popped value (u8) if the stack is not empty | ||
/// ConditionalStackError.EmptyConditionalStack if the stack is empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we know what pop return. You can remove this long comment
src/script/cond_stack.zig
Outdated
/// Push a conditional value onto the stack | ||
/// | ||
/// Args: | ||
/// value: The conditional value to push (typically 0, 1, or 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be something else than 0, 1 or 2? You comment suggest it can
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can you define an enum for more readability
OpCondFalse = 0
OpCondTrue = 1
OpCondSkip = 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be something else than 0, 1 or 2? You comment suggest it can
Reading other implementations it looks like it cannot. So please change your comment to not mean that it could
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And ofcourse use those OpCond enum in your tests rather than 1, 2, 3
if (self.stack.items.len == 0) { | ||
return ConditionalStackError.UnbalancedConditional; | ||
} | ||
_ = self.stack.pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you want to return the poped value?
@@ -391,3 +391,27 @@ pub fn isUnnamedPushNDataOpcode(opcode: Opcode) ?u8 { | |||
const opcodeByte = opcode.toBytes(); | |||
return if (opcodeByte > 0x00 and opcodeByte <= 0x4b) opcodeByte else null; | |||
} | |||
|
|||
/// Conditional execution constants for script operations. | |||
pub const OpConditional = enum(u8) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are not Opcodes so I don't like the name.
What about "CondStackValue" ?
/// | ||
/// Returns: | ||
/// Possible error if allocation fails | ||
pub fn push(self: *Self, value: u8) !void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if values are strictly limited, change the signature to reflect that:
pub fn push(self: *Self, value: CondStackValue) !void
const Self = @This(); | ||
|
||
/// Dynamic array to store conditional values | ||
stack: std.ArrayList(u8), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std.ArrayList(CondStackValue) is more restrictive and more expressive
@okhaimie-dev are you still working on this? |
I'll send a fix tomorrow, I have been traveling |
Implement conditional opcodes and wip to enhance script code structure
Added the following opcodes with corresponding tests:
opIf
opNotIf
opElse
opEndIf
Others
opReserved
opVer
Improvements:
cond_stack
for managing conditional executionThis commit addresses issue #29