B-Lang-org/bsc

Syntax for enum encodings in BH/Classic

开放

#292 创建于 2021年1月14日

 (0 条评论) (0 个反应) (0 位负责人)Haskell (178 个派生)batch import
good first issue

仓库指标

星标
 (1,108 个星标)
PR 合并指标
 (平均合并 17天 1小时) (30 天内合并 18 个 PR)

描述

BSV allows the user to specify a custom encoding for the derived Bits of an enum. For example, from bsc.bluetcl/commands/Test.bsv in the testsuite:

typedef enum { Red2 = 1, Yellow2, Blue2 } BarSet deriving(Bits);

This is handled by pEnumTag in Parser/BSV/CVParser.lhs (where it fills in the fields like cos_tag_encoding). In the BH/Classic parser (Parser/Classic/CParser.hs) the function pDataB just fills in integers starting from zero ([0..]).

It might be worth creating a BH/Classic syntax for specifying a custom encoding. (It could perhaps be an attribute, if that's easier.) This is part of the larger issue that BSV was the only supported syntax for a long time, so there are some things that can be specified in that syntax but not in BH/Classic. See, for example, issue #224. I don't personally have a need for custom encodings in BH/Classic, but I thought it was worth recording the difference in the Issues database. (Should we have an open Issue for listing all of the known differences? or perhaps this a good use for the new Discussions area?)

Implementing the syntax should be simple, so I'm tagging this as a "good first issue", but we'd need to decide on the syntax first.

贡献者指南