Skip to content

907 Conditions And Dynamic Pins ​

907-conditions-and-dynamic-pins.mc covers default parameters, if, else, conditional attributes, and pins +=. Tutorial first use: 05-dynamic-pins-and-conditions.

Syntax synopsis:

text
component TYPE_NAME(partno::STRING = "BASE")
{
    if (partno == "WIDE")
    {
        pins += [
            io [4:5] = IO[2:3]
        ]
    }

    if (partno == "WIDE")
    {
        package = "5-pin"
    }
    else
    {
        package = "3-pin"
    }
}

The runnable example connects U_WIDE.IO2, proving that a name appended by pins += can be accessed on the selected variant. U_BASE has no IO2 member.

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 90-language-reference/907-conditions-and-dynamic-pins.mc --lib mcode --pass1 --pass2

Source ​

text
// Reference: Conditions And Dynamic Pins
// Focus: default parameters, if/else, conditional attributes, and pins +=.

component REF_VARIANT(partno::STRING = "BASE")
{
    name = "Reference Variant"
    pins = [
        io [1:2] = IO[0:1]
        3 = GND
    ]

    if (partno == "WIDE")
    {
        pins += [
            io [4:5] = IO[2:3]
        ]
    }

    if (partno == "WIDE")
    {
        package = "5-pin"
    }
    else
    {
        package = "3-pin"
    }
}

module main
{
    io BASE_IO0
    io GND
    io WIDE_IO0
    io WIDE_IO2

    REF_VARIANT         U_BASE
    REF_VARIANT("WIDE") U_WIDE

    BASE_IO0 -> U_BASE.IO0
    U_BASE.GND -> GND

    WIDE_IO0 -> U_WIDE.IO0
    // IO2 exists only when the WIDE condition appends pins 4 and 5.
    WIDE_IO2 -> U_WIDE.IO2
    U_WIDE.GND -> GND
}

MCode Bench is the public face of the MCode stack. Closed capabilities are served through the MCode gateway.