Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class writing move to ByteCode #283

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

bogatykh
Copy link
Contributor

@bogatykh bogatykh commented Feb 6, 2023

No description provided.

@bogatykh
Copy link
Contributor Author

bogatykh commented Feb 6, 2023

@wasabii this is work in progress and is not complete. Creating PR to inform you about ongoing work.

@wasabii
Copy link
Contributor

wasabii commented Feb 6, 2023

Wow dude. It'll take me a bit to go over this one. But awesome. I didn't expect anybody else to go for this.

@bogatykh
Copy link
Contributor Author

bogatykh commented Feb 6, 2023

@wasabii can you please suggest me Writer class design? I was using your Reader classes design as a reference and can't come up with a good design. How would you design, for example FieldWriter for FieldRecord?

@wasabii
Copy link
Contributor

wasabii commented Feb 6, 2023

One of the things I was going to do was introduce a Builder pattern over the records.

@wasabii
Copy link
Contributor

wasabii commented Feb 6, 2023

I hadn't even decided yet whether to name them Writers to be inline with Readers, or Builders, because lots of other projects use that terminology. But I had thought that modeling it sort of like System.Metadata.Reflection would be beneficial.

@wasabii
Copy link
Contributor

wasabii commented Feb 6, 2023

https://learn.microsoft.com/en-us/dotnet/api/system.reflection.metadata.ecma335.metadatabuilder?view=net-5.0

Obviously different concepts.

But they create a MetadataBuilder. Then invoke Add* methods on it. And metadata provides a few basic classes for data allocation, which we would use for Constant pool allocation. Like GetOrAddString(), etc. Which return "handles" that represent the various elements. And the GetOrAdd* pattern lets us deduplicate constants early. But still let the user create duplicate constants if he so desires.

A very basic surface API, only exposing the Core concepts. And then other extension methods on top of that, for instance, to add a field the Core API would have AddField(Utf8ConstantHandle, etc). Forcing the user to call GetOrAddUtf8Constant() to get a Utf8ConstantHandle to pass. But we would also provide extension method versions of AddField that took strings as args and called GetOrAdd* itself, etc.

@wasabii
Copy link
Contributor

wasabii commented Feb 6, 2023

At the end of the process, our ClassBuilder would have a Build() method which returned a ClassRecord. Which was immutable. And could then be written to a ClassFormatWriter.

@wasabii
Copy link
Contributor

wasabii commented Feb 6, 2023

I also wanted to provide a parser over some common string formats, like Descriptors. And then associated builders.

@wasabii
Copy link
Contributor

wasabii commented Feb 6, 2023

@bogatykh also to make you aware, one of the users of this will be #284

@bogatykh
Copy link
Contributor Author

bogatykh commented Feb 6, 2023

One of the things I was going to do was introduce a Builder pattern over the records.

That's a good idea. I have implemented some builder class. Could you please comment if we go this way or like System.Reflection Ecma builder?

@wasabii
Copy link
Contributor

wasabii commented Feb 6, 2023

I would start with modeling it on System.Reflection.Metadata.Ecma. That's the type of structure that seems the most logical to start with to me. Makes it most familiar for people working in this space in .NET.

wasabii added a commit that referenced this pull request Jun 2, 2023
Related Work Items: #283
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.

None yet

2 participants