Skip to content

Commit

Permalink
refactor(store): update tightcoder codegen, optimize TightCoder libra…
Browse files Browse the repository at this point in the history
…ry (#1210)

Co-authored-by: alvarius <alvarius@lattice.xyz>
  • Loading branch information
dk1a and alvrs authored Aug 6, 2023
1 parent b6c8f3d commit cc2c8da
Show file tree
Hide file tree
Showing 25 changed files with 944 additions and 1,173 deletions.
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 `getLeftPaddingBits` common codegen helpers
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 getLeftPaddingBits(field: Pick<RenderType, "internalTypeId" | "staticByteLength">): number {
if (isLeftAligned(field)) {
return 0;
} else {
return 256 - field.staticByteLength * 8;
}
}

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

0 comments on commit cc2c8da

Please sign in to comment.