Skip to content

feat(dsl): support static value fields on classes#35

Open
spiral-ladder wants to merge 1 commit into
mainfrom
bing/static
Open

feat(dsl): support static value fields on classes#35
spiral-ladder wants to merge 1 commit into
mainfrom
bing/static

Conversation

@spiral-ladder
Copy link
Copy Markdown
Contributor

Unblocks ChainSafe/lodestar#8900

Support was previously added in ChainSafe/lodestar-z#328

but the DSL update removed it

Unblocks ChainSafe/lodestar#8900

Support was previously added in ChainSafe/lodestar-z#328

but the DSL update removed it
Copy link
Copy Markdown
Contributor

@nazarhussain nazarhussain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DSL was deliberately designed so the same declarations describe the type for both the Zig and JS sides; .static = .{ .COMPRESS_SIZE = 48 } breaks that symmetry and introduces a JS-shaped DSL surface that Zig doesn't need.

In Zig, the natural way to express BlsPublicKey.COMPRESS_SIZE already exists as a first-class language feature — namespace-level variables on a container's namespace:

  pub const BlsPublicKey = struct {                                                                           
      pub const COMPRESS_SIZE: u32 = 48;          
      pub const SERIALIZE_SIZE: u32 = 96;                                                                     
                                                                                                              
      bytes: [96]u8,                              
  };

Accessed as BlsPublicKey.COMPRESS_SIZE in Zig, which is exactly the access shape we want on the JS constructor too. So the source of truth can be one decl, not a value duplicated into a .static block.

I would suggest to instead walk @typeInfo(T).@"struct".decls at comptime, filter to supported scalar/string types, attach each as an own property of the constructor.

For reference, we introduced js.prop earlier because there was no Zig analogue for JS shaped getter/setters. But for this feature we already have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants