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

Accepting labels as macros' arguments #126

Open
shayanh opened this issue May 12, 2021 · 1 comment
Open

Accepting labels as macros' arguments #126

shayanh opened this issue May 12, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@shayanh
Copy link
Contributor

shayanh commented May 12, 2021

PlusCal and MPCal don't accept labels as macros' arguments. Input labels in macros can be used in goto statements. For example, by having this we can define the following macro, which is useful for defining failure:

macro mayFail(fLabel) {
    if (EXPLORE_FAIL) {
        either {
            skip;
        } or {
            goto fLabel;
        };
    };
};

I think we can extend macros behavior in MPCal by substituting goto labels with the arguments values if the labels are present in the macro's arguments.

Finn's comment:

straw-man syntax, if I remember: label fLabel as an argument, to distinguish

@shayanh shayanh added the enhancement New feature or request label May 12, 2021
@shayanh
Copy link
Contributor Author

shayanh commented Aug 4, 2021

More precise description:

label type

In PlusCal and MPCal labels are static names and a variable cannot store a label. We propose a new type of variable that stores labels. As a result we can pass labels to macros and procedures(?) as their arguments.

archetype Foo()
label myLabel;
{
    l1: skip;
    l2: myLabel := l1;
}

Motivation

For simulating failure behavior, being able to pass labels as macros' arguments helps to avoid code duplication (DRY principle). For instance, the following macro is really helpful for the failure behavior simulation:

macro mayFail(label fLabel) {
    either { skip; } or {
        goto fLabel;
    }
}

@fhackett fhackett self-assigned this Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants