-
Notifications
You must be signed in to change notification settings - Fork 1
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
[lang-model]: const-enum
Format (simple
, common
, sem
)
#192
Comments
Could the proposed |
It would require a fair bit of boilerplate, I should expect. |
But technically achievable. |
Having thought about this a bit more, it may be difficult to actually get this working using existing primitives for the following reason: Once the It may be appropriate to include, in any change-set that adds pub enum Value {
/* ... */
NamedConst(Label, Box<Value>),
} that we can pattern-match either using the Label or the inner value, but otherwise will be implicitly converted to the inner Value prior to any arithmetic or IntRel operations. |
I'd be reluctant to add C-style enums (that can be used interchangeably with integers) without a good reason, do we have examples of enum values that we also need to perform arithmetic on? |
Good question. A common pattern we might want to apply is |
(Since |
We could add in a notion of structural-equality and -inequality, but that might be best achieved using Expr->Pattern conversions that then do a trivial |
we could have a helper: /// Expression that evaluates to `true` if the given Expr is any Variant with name `varname`, `false` otherwise.
pub fn is_variant(x: Expr, varname: impl IntoLabel) -> Expr {
Expr::Match(x,
vec![
(Pattern::Variant(varname.into(), Pattern::Wildcard), Expr::Bool(true)),
(Pattern::Wildcard, Expr::Bool(false)),
]
)
} |
Yep that's a good approach I think. |
Even without necessarily generating const-enum definitions in generated code, we may want to start signalling the semantics of the expected values of a given numeric format-token with strings or identifiers at the output layer; similar to the proposal for a type-preserving wrapper that merely attaches content of a given type (whether string or enum) to a Value as it is processed, we could have type-erased annotations that augment the display output without disrupting the computation model. |
While achievable through a modest amount of boilerplating with our current model, it may be useful going forward to have a first-class Format-variant for
const enum
values: an ad-hoc type consisting of nullary (C-Style enum) variants that are each associated with a specific non-negative integer constant.This proposal is for something of the form:
where the first argument specifies the 'raw' parsing of the integer value, and
the BTreeMap encapsulates the associations between each valid integer value
and the name of the variant to be constructed in-place the
Value
-level stand-in for the raw magic number.To provide an easier API, we propose the following helper-function:
Usage Example (from WIP ELF):
The intended interpretation of this primitive is that it should adhere to the rough operational semantics illustrated below:
The text was updated successfully, but these errors were encountered: