Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

I really really really want constants in cauterize #35

Open
JSchaenzle opened this issue Apr 10, 2014 · 4 comments
Open

I really really really want constants in cauterize #35

JSchaenzle opened this issue Apr 10, 2014 · 4 comments

Comments

@JSchaenzle
Copy link

I want a way to specify a constant thing in cauterize!

@sw17ch
Copy link
Owner

sw17ch commented Apr 10, 2014

To clarify, this would be a type that would always pack and unpack to a constant value?

const(:some_constant) do |t|
    t.value 8192
    t.byte_width 4
end

The previous constant would have a type named some_constant and a pack/unpack value of 8192 always represented in 4 bytes.

This could be included in a composite:

composite(:has_a_const_header) do |t|
    c.field :header, :some_constant
    c.field :payload, :some_buffer_type
end

Sound correct?

@JSchaenzle
Copy link
Author

Well maybe. I was thinking something more like...

fixed_array(:uuid) do |t|
  t.type     :uint8
  t.length  16
end

composite(:car) do |t|
  t.doors  :uint8
  t.seats  :uint8
do    

const(:corvette) do |t|
  t.type :car
  t.value {doors: 2, seats: 2}
end

const(:my_prog_id) do |t|
  t.type :uuid
  t.value [1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8]
end

# or it could be something like...
const(:car, :corvette) do |t|
  t.value {doors: 2, seats: 2}
end

I realize this is quite a bit more work to implement :(

@sw17ch
Copy link
Owner

sw17ch commented Apr 10, 2014

Ah, got it. This makes sense in situations where there's a long, complex, header or footer.

@JSchaenzle
Copy link
Author

@sw17ch I think there could be a valid argument that constants don't belong in cauterize. To get around this problem, we just added a header file to our cauterize-spec project that has macros that return instances of things in the cauterize spec.

#define CORVETTE ((struct car){ .doors = 2, .seats = 2,})

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants