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

Implement serialize #137

Open
wants to merge 4 commits into
base: pz-write-tags
Choose a base branch
from
Open

Implement serialize #137

wants to merge 4 commits into from

Conversation

peterzhu2118
Copy link
Member

Based on #136.

This PR implements BlockBody#dump that dumps the block body to a string. The block body dumps the instructions, writes the tag markups to the buffer, and marshal dumps the constants into a single string that is returned.

VALUE str = rb_str_buf_new(sizeof(document_body_header_t) + buffer_len + constants_len);

document_body_header_t header = {
.entrypoint_block_index = entrypoint_block_index,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a bytecode/serialization version at the top? In case we need to make some backward incompatible changes to the bytecode.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. I suggested this in the deserialize PR here https://github.com/Shopify/liquid-c/pull/138/files#r551963712

@@ -28,6 +28,14 @@ typedef struct document_body {
c_buffer_t buffer;
} document_body_t;

typedef struct document_body_header {
uint32_t entrypoint_block_index;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see it's called index here, but it ends up being used as an offset here: https://github.com/Shopify/liquid-c/pull/138/files#diff-d25b9c9a1b16f1935c261f8232ea43e790513f022f33b7c8de117016cd76f130R188 correct?

Should this be renamed to _offset or the code is wrong in #138?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, it is an offset. There isn't currently a block table to index into.

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.

3 participants