Skip to content

Commit

Permalink
fix(shader-ast-js): op2 type hint interpretation
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 2, 2019
1 parent 1412f71 commit fdaac1f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/shader-ast-js/src/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,6 @@ export const targetJS = () => {
"--": "dec",
"||": "or",
"&&": "and",
// TODO below
"|": "bitor",
"&": "bitand",
"^": "bitxor",
Expand All @@ -912,9 +911,9 @@ export const targetJS = () => {
"ivec2",
"ivec3",
"ivec4",
// "uvec2",
// "uvec3",
// "uvec4",
"uvec2",
"uvec3",
"uvec4",
"mat2",
"mat3",
"mat4",
Expand Down Expand Up @@ -1036,22 +1035,25 @@ export const targetJS = () => {
}
},

// TODO mat-vec multiply special case
op2: (t) => {
const { l, r } = t;
const vec = isVec(l) || isMat(l) || isVec(r) || isMat(r);
const int =
!vec &&
(isInt(l) ||
isUint(l) ||
isInt(r) ||
isUint(r) ||
isBool(l) ||
isBool(r));
const vec =
isVec(l) || isMat(l)
? l.type
: isVec(r) || isMat(r)
? r.type
: undefined;
const int = !vec
? isInt(l) || isUint(l) || isBool(l)
? l.type
: isInt(r) || isUint(r) || isBool(r)
? r.type
: undefined
: undefined;
const el = emit(l);
const er = emit(r);
return vec || (int && !CMP_OPS[t.op])
? `${t.l.type}.${OP_IDS[t.op]}${t.info || ""}(${el}, ${er})`
? `${vec || int}.${OP_IDS[t.op]}${t.info || ""}(${el}, ${er})`
: `(${el} ${t.op} ${er})`;
},

Expand Down

0 comments on commit fdaac1f

Please sign in to comment.