HPInc / HP-Digital-Microfluidics

HP Digital Microfluidics Software Platform and Libraries
MIT License
3 stars 1 forks source link

Add maybe types to the macro language #151

Closed EvanKirshenbaum closed 8 months ago

EvanKirshenbaum commented 8 months ago

This is simply a matter of allowing, e.g., maybe drop as a parameter or variable type, with Type.DROP.maybe as its corresponding Type. This would allow, e.g., pad.drop to be passed on without dying on the attempt to convert to a drop.

One wrinkle is that in the current implementation, when it is a problem, it's caught at the point at which we know what the object and attribute are and can print a useful value. So we'll probably want to pass along some information that will allow that to happen. If have lvals (#132), we will still be able to do that if the attribute is converted to a drop, but if it's converted to a maybe drop, we'd lose that. This is probably correct, as if we held onto the lval after the value had been converted to an rval maybe drop, it might be the case that by the time we try (and fail) to use it as a drop, the actual source of the missing value is no longer empty.

In order for this to be useful, we'll also want a missing predicate a la:

foo = macro(maybe drop d) {
   if d is missing { ... }
   ...
}

We'd also want missing to be a value you can use as a value.

Ideally, we'd do the same sort of type reasoning that MyPy does, trying to figure out whether the value can (or must) be missing at each point in its scope (including after boolean operators). But that's probably something best left to union types (#152) and for now simply say that you can always try to use the maybe value as a real one, but it might fail.

Migrated from internal repository. Originally created by @EvanKirshenbaum on Jun 05, 2022 at 4:26 PM PDT. Closed on Jan 28, 2023 at 4:33 PM PST.
EvanKirshenbaum commented 8 months ago

This issue was referenced by the following commit before migration:

EvanKirshenbaum commented 8 months ago

Note that if we do this with lvals (#132) we will probably want the lval getter to take the desired type as a parameter and do the conversion. This will allow maybe lvals to pass on a MaybeNotSatisfied if they are none and trying to go to an rval.

Migrated from internal repository. Originally created by @EvanKirshenbaum on Jun 05, 2022 at 4:34 PM PDT.
EvanKirshenbaum commented 8 months ago

As part of splitting the uses of Type.NONE (#223), I took care of this.

Migrated from internal repository. Originally created by @EvanKirshenbaum on Jan 28, 2023 at 4:33 PM PST.