Thoughts about JSON #115
Replies: 4 comments 31 replies
-
I think you'll find that the proposed WIP @titzer can correct me if I'm wrong, but I feel like it should be possible with EDIT: The above is based on the assumption that you know the structure of the JSON data, If you're trying to make a general library for it, then I think |
Beta Was this translation helpful? Give feedback.
-
Actually on second thought -- |
Beta Was this translation helpful? Give feedback.
-
The motivation for not (yet) having reflection has been primarily about memory usage and optimizability of Virgil code. Reflection requires having source-level metadata connected to program values, and that metadata takes a lot of space. It can also prevent a lot of the static analysis the compiler does to optimize and remove dead code. That said, reflection only at compile-time would restrict those problems to a phase that can be completed, after which optimization can happen. That's something I could see as a future feature. Failing that, there are a number of non-reflective things that you can try first.
The above is a bit verbose, but you could:
|
Beta Was this translation helpful? Give feedback.
-
The syntax for
There are routines to parse floats inside the compiler (look for |
Beta Was this translation helpful? Give feedback.
-
I've been thinking about the prerequisites to JSON (de)serialization to/from data structures in virgil. What I would like is a library like serde and serde_json in rust, where data can be deserialized directly into a struct, and serialized directly from a struct.
However, it seems to me that I'm virgil the only way to deserialize from json would be to deserialize into a recursive ADT of hashmaps / arrays / allowed primitives. If I wanted to get the data into (or out of) a well defined data structure though, i would to write additional code to connect the ADT structure to a class (or any other virgil structure).
What this leads me to, is the fact that there is no reflection in virgil, even in compile time code. If it were possible to allow reflection at compile time, I imagine it would open up static metaprogramming such as is necessary for a library like serde. However, I know that reflection is listed as something that virgil lacks, and I would like to know if the reasons for that (I assume performance? Are there also other considerations) also preclude compile time reflection, and if not, whether you would consider adding it to your roadmap. I understand that virgil is in a sense an expiriment (?), and I of course do not wish to imply that there is any onus on you to add a particular feature.
Beta Was this translation helpful? Give feedback.
All reactions