rems-project / sail

Sail architecture definition language
Other
590 stars 103 forks source link

Enum_function's syntax #629

Closed trdthg closed 2 months ago

trdthg commented 2 months ago

I'm doing some test on enum

I've checked the manual

image

I think the following sail code should be ok:

enum func_two_id with fti -> int,
                      fti2 -> int, = {
    fti => {
        1
    },
    fti2 => {
        1
    },
}

But there is the error msg:

$ ./sail ./test/format/bitfield.sail  // please ignore the filename, just a demo
Error:
./test/format/bitfield.sail:46.11-48.5:
46 |    fti => {
   |           ^
48 |    },
   |----^
   | Each enumeration clause for func_two_id must define exactly 2 expressions for the functions fti, fti2
   | Too few expressions have been given here

I checked the related source code(please ignore the changes here):

image

And the following code is ok:

fti2 -> int, = {
    fti => (
        {
            1
        },
        {
            1
        },
    ),
    fti2 => (
        {
            1
        },
        {
            1
        },
    ),
}

So, is this the correct syntax? Or is there something wrong with initial_check?

If this is a bug, I can help to fix

Alasdair commented 2 months ago
enum func_two_id with f -> int, g -> int, = {
    fti => (1, 2),
    fti2 => (3, 4),
}

The way it's intended to work is that this will generate two functions f and g that convert the enumeration members into integers, so for the above you would have:

f(fti) == 1
f(fti2) == 3
g(fti) == 2
g(fti2) == 4

Hopefully that makes sense?

trdthg commented 2 months ago

Thanks, then there's no problem :D. (Looking forward to adding it to the docs in the future)