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

refactor(store): update tightcoder codegen, optimize TightCoder library #1210

Merged
merged 13 commits into from
Aug 6, 2023
9 changes: 9 additions & 0 deletions .changeset/witty-jokes-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@latticexyz/common": patch
"@latticexyz/store": patch
"@latticexyz/world": patch
---

Refactor tightcoder to use typescript functions instead of ejs
Optimize `TightCoder` library
Add `isLeftAligned` and `shiftLeftBits` common codegen helpers
dk1a marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions packages/common/src/codegen/render-solidity/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ export function renderValueTypeToBytes32(name: string, { typeUnwrap, internalTyp
}
}

export function isLeftAligned(field: Pick<RenderType, "internalTypeId">): boolean {
return field.internalTypeId.match(/^bytes\d{1,2}$/) !== null;
}

export function shiftLeftBits(field: Pick<RenderType, "internalTypeId" | "staticByteLength">): number {
dk1a marked this conversation as resolved.
Show resolved Hide resolved
if (isLeftAligned(field)) {
return 0;
} else {
return 256 - field.staticByteLength * 8;
}
}

function internalRenderList<T>(
lineTerminator: string,
list: T[],
Expand Down
Loading