Skip to content

Commit

Permalink
Remove WGSLCompoundTrait (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhawryluk authored Jul 10, 2024
1 parent f01dcc4 commit 5507df0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 33 deletions.
8 changes: 0 additions & 8 deletions packages/wigsill/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ export interface WGSLBindableTrait<TBinding> extends WGSLItem {

export type WGSLBindPair<T> = [WGSLBindableTrait<T>, T];

export interface WGSLCompoundTrait extends WGSLItem {
getChildren(ctx: IResolutionCtx): WGSLItem[];
}

export function hasCompoundTrait<T>(value: T): value is T & WGSLCompoundTrait {
return !!value && typeof value === 'object' && 'getChildren' in value;
}

export interface WGSLMemoryTrait extends WGSLItem {
readonly size: number;
readonly baseAlignment: number;
Expand Down
14 changes: 2 additions & 12 deletions packages/wigsill/src/wgslCode.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import {
IResolutionCtx,
WGSLCompoundTrait,
WGSLItem,
WGSLSegment,
isWGSLItem,
} from './types';
import { IResolutionCtx, WGSLItem, WGSLSegment, isWGSLItem } from './types';

export class WGSLCode implements WGSLItem, WGSLCompoundTrait {
export class WGSLCode implements WGSLItem {
constructor(public readonly segments: WGSLSegment[]) {}

getChildren(): WGSLItem[] {
return this.segments.filter(isWGSLItem);
}

resolve(ctx: IResolutionCtx) {
let code = '';

Expand Down
14 changes: 1 addition & 13 deletions packages/wigsill/src/wgslPlaceholder.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {
IResolutionCtx,
WGSLBindableTrait,
WGSLCompoundTrait,
WGSLItem,
WGSLSegment,
hasCompoundTrait,
} from './types';

export class WGSLPlaceholder
implements WGSLItem, WGSLBindableTrait<WGSLSegment>, WGSLCompoundTrait
implements WGSLItem, WGSLBindableTrait<WGSLSegment>
{
__bindingType!: WGSLSegment;
public debugLabel?: string | undefined;
Expand All @@ -28,16 +26,6 @@ export class WGSLPlaceholder
return ctx.requireBinding(this);
}

getChildren(ctx: IResolutionCtx): WGSLItem[] {
const segment = this.getSegment(ctx);

if (hasCompoundTrait(segment)) {
return segment.getChildren(ctx);
}

return [];
}

resolve(ctx: IResolutionCtx): string {
return ctx.resolve(this.getSegment(ctx));
}
Expand Down

0 comments on commit 5507df0

Please sign in to comment.