Skip to content
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

New operator refactor #38

Merged
merged 5 commits into from
Jan 4, 2024
Merged

New operator refactor #38

merged 5 commits into from
Jan 4, 2024

Conversation

Lydxn
Copy link
Collaborator

@Lydxn Lydxn commented Jan 2, 2024

No description provided.

@Lydxn Lydxn requested a review from JayXon January 3, 2024 23:04
@@ -122,16 +121,31 @@ fn find_binary_operators(
}
seq!(idx in 0..100 {
if let Some(&op) = BINARY_OPERATORS.get(idx) {
let op_idx: OpIndex = OpIndex::new(idx + UNARY_OPERATORS.len());
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need to specify the type here, especially we are using OpIndex::new so the type is very clear

Suggested change
let op_idx: OpIndex = OpIndex::new(idx + UNARY_OPERATORS.len());
let op_idx = OpIndex::new(idx + UNARY_OPERATORS.len());

if let Some(&op) = UNARY_OPERATORS.get(op_idx) {
seq!(idx in 0..10 {
if let Some(&op) = UNARY_OPERATORS.get(idx) {
let op_idx: OpIndex = OpIndex::new(idx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
let op_idx: OpIndex = OpIndex::new(idx);
let op_idx = OpIndex::new(idx);

name: "<",
prec: 5,
apply: apply_lt,
can_apply: can_apply_binary_always,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can either implement a Default trait for BinaryOp, or define a OP_EMPTY constant, and then we can do ..OP_EMPTY, instead of having to specify can_apply_binary_always and the bool flags in every struct.

commutative: false,
right_assoc: false,
};
pub const OP_BIT_SHL_WRAP: BinaryOp = BinaryOp {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could just be

pub const OP_BIT_SHL_WRAP: BinaryOp = BinaryOp {
    apply: apply_bit_shl_wrap,
    ..OP_BIT_SHL,
};

@@ -50,46 +44,46 @@ pub const LITERALS: &[Num] = &[
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
];
/// If not 0, include all numbers in 1..=MAX_LITERAL in addition to LITERALS.
pub const MAX_LITERAL: Num = 0;
pub const MAX_LITERAL: Num = 4;
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this an intentional change?

Copy link
Collaborator Author

@Lydxn Lydxn Jan 4, 2024

Choose a reason for hiding this comment

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

No, my bad, I didn't see that I changed it (will address the changes in the next PR).

@Lydxn Lydxn merged commit e1a38ea into lynn:main Jan 4, 2024
1 check passed
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