Hypercosm / HIDL

Hypercosm Interface Description Language
https://hypercosm.dev/HIDL
0 stars 0 forks source link

Expr for flags #19

Open aDotInTheVoid opened 2 years ago

aDotInTheVoid commented 2 years ago

r? @daeken

This is wip, but the core design is ready for review:

    flags Color2(u8) {
        Black   = 0
        Red     = 0b100
        Blue    = 0b010
        Green   = 0b000
        Cyan    = Green | Blue
        Yellow  = Red | Green
        Magenta = Red | Blue
        White   = Red | Blue | Green
    }
[src\hir.rs:100] lower_flags(f) = Flags {
    backing: Unsigned(U8),
    fields: [
        FlagField { name: "Black", expr: Num(0), value: Some(0) },
        FlagField { name: "Red", expr: BNum(4), value: Some(4) },
        FlagField { name: "Blue", expr: BNum(2), value: Some(2) },
        FlagField { name: "Green", expr: BNum(1), value: Some(1) },
        FlagField {
            name: "Cyan",
            expr: BinOp(Ident("Green"), BOr, Ident("Blue")),
            value: Some(3),
        },
        FlagField {
            name: "Yellow",
            expr: BinOp(Ident("Red"), BOr, Ident("Green")),
            value: Some(5),
        },
        FlagField {
            name: "Magenta",
            expr: BinOp(Ident("Red"), BOr, Ident("Blue")),
            value: Some(6),
        },
        FlagField {
            name: "White",
            expr: BinOp(BinOp(Ident("Red"), BOr, Ident("Blue")), BOr, Ident("Green")),
            value: Some(7),
        },
    ],
}

TODO:

Maybe todo