aDotInTheVoid / skate

Skateboard for the mind
Apache License 2.0
2 stars 0 forks source link

Flesh out test suite + BinOp #27

Closed aDotInTheVoid closed 3 years ago

aDotInTheVoid commented 3 years ago

macro_rules! match_num_op {(
    $scrutinee:expr,
    $(
        $name:path => $op:tt
    ),* $(,)?
) => (
    match $scrutinee {
        $(
            ($name, Int(l), Int(r)) => Int(l $op r),
        )*
        (o, l, r) => panic!("Unknown binop {:?}, {:?}, {:?}", l, o, r),
    }
)}

pub fn binop(l: Value, o: BinOp, r: Value) -> Value {
    use Value::*;

    match_num_op! {
        (o, l, r),
        BinOp::Plus => +,
        BinOp::Times => *,
    }
}
aDotInTheVoid commented 3 years ago

We have binops, now we need tests