Hy reader macros #2649
Replies: 2 comments 11 replies
-
It didn't attach because .hy is not recognised by github (defreader binding
(.slurp-space &reader)
(assert (.peek-and-getc &reader "("))
(setv name (.read_ident &reader))
(.slurp-space &reader)
(setv group None)
(setv binding None)
(setv buffer-type None)
(setv access None)
(setv data-type None)
(while (not (.peek-and-getc &reader ")"))
(setv ident (.read_ident &reader))
(.slurp-space &reader)
(match ident
":group" (setv group (.read_ident &reader))
":binding" (setv binding (.read_ident &reader))
":buffer-type" (setv buffer-type (.read_ident &reader))
":access-mode" (setv access (.read_ident &reader))
":type" (setv data-type (.read_ident &reader)))
(.slurp-space &reader))
f"@group({group}) @binding({binding}) var<{buffer-type}, {access}> {name}: {data-type};\n")
(defreader compute
(.slurp-space &reader)
(setv symbol(.read_ident &reader :just_peeking False))
(.slurp-space &reader)
(assert (.peek-and-getc &reader "["))
(setv workgroup-x (.read_ident &reader :just_peeking False))
(.slurp-space &reader)
(setv workgroup-y (.read_ident &reader :just_peeking False))
(.slurp-space &reader)
(setv workgroup-z (.read_ident &reader :just_peeking False))
(assert (.peek-and-getc &reader "]"))
(.slurp-space &reader)
(assert (.peek-and-getc &reader "["))
(setv bindings "")
(while (not (.peek-and-getc &reader "]"))
(+= bindings (.dispatch &reader "#binding"))
(.slurp-space &reader))
(.slurp-space &reader)
(assert (.peek-and-getc &reader "["))
(setv params (param &reader))
(.slurp-space &reader)
(while (not (.peek-and-getc &reader "]"))
(+= params "," (param &reader))
(.slurp-space &reader))
(.slurp-space &reader)
(setv body (expression &reader))
f"{bindings}@compute @workgroup_size({workgroup-x}, {workgroup-y}, {workgroup-z})\nfn {symbol}({params}){{{body}}}") |
Beta Was this translation helpful? Give feedback.
-
I don't think there's enough training data for LLMs to be very helpful with Hy. To be clear, the methods
It's not broken just because you didn't read the error message. Like it and the documentation says, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I am trying to write a reader macro that converts valid hy into valid WGSL, I was using functions as extensions to the parser but I discovered the reader macro .dispatch and am trying to figure out how to use it correctly. I have had deep conversations with deepseek about this issue but most of its responses are nonsense. Attached is the code the lines to look out for are line 1 and line 75. Line 1 is where I define the reader and line 75 is where I attempt to call it. If anyone could give me some pointers that would be greatly appreciated.
Kind regards,
Cory Patten
Beta Was this translation helpful? Give feedback.
All reactions