@@ -37,6 +37,7 @@ export const BaseType = {
3737 BOOL : "bool" ,
3838 MAT : "mat" ,
3939 DEFER : "defer" ,
40+ ASSIGN_ON_USE : "assign_on_use" ,
4041 SAMPLER2D : "sampler2D" ,
4142 SAMPLER : "sampler" ,
4243} ;
@@ -46,6 +47,7 @@ export const BasePriority = {
4647 [ BaseType . BOOL ] : 1 ,
4748 [ BaseType . MAT ] : 0 ,
4849 [ BaseType . DEFER ] : - 1 ,
50+ [ BaseType . ASSIGN_ON_USE ] : - 2 ,
4951 [ BaseType . SAMPLER2D ] : - 10 ,
5052 [ BaseType . SAMPLER ] : - 11 ,
5153} ;
@@ -66,6 +68,7 @@ export const DataType = {
6668 mat3 : { fnName : "mat3x3" , baseType : BaseType . MAT , dimension :3 , priority : 0 , } ,
6769 mat4 : { fnName : "mat4x4" , baseType : BaseType . MAT , dimension :4 , priority : 0 , } ,
6870 defer : { fnName : null , baseType : BaseType . DEFER , dimension : null , priority : - 1 } ,
71+ assign_on_use : { fnName : null , baseType : BaseType . ASSIGN_ON_USE , dimension : null , priority : - 2 } ,
6972 sampler2D : { fnName : "sampler2D" , baseType : BaseType . SAMPLER2D , dimension : 1 , priority : - 10 } ,
7073 sampler : { fnName : "sampler" , baseType : BaseType . SAMPLER , dimension : 1 , priority : - 11 } ,
7174}
@@ -137,22 +140,22 @@ export const OpCode = {
137140 }
138141} ;
139142export const OperatorTable = [
140- { arity : "unary" , name : "not" , symbol : "!" , opCode : OpCode . Unary . LOGICAL_NOT } ,
143+ { arity : "unary" , boolean : true , name : "not" , symbol : "!" , opCode : OpCode . Unary . LOGICAL_NOT } ,
141144 { arity : "unary" , name : "neg" , symbol : "-" , opCode : OpCode . Unary . NEGATE } ,
142145 { arity : "unary" , name : "plus" , symbol : "+" , opCode : OpCode . Unary . PLUS } ,
143146 { arity : "binary" , name : "add" , symbol : "+" , opCode : OpCode . Binary . ADD } ,
144147 { arity : "binary" , name : "sub" , symbol : "-" , opCode : OpCode . Binary . SUBTRACT } ,
145148 { arity : "binary" , name : "mult" , symbol : "*" , opCode : OpCode . Binary . MULTIPLY } ,
146149 { arity : "binary" , name : "div" , symbol : "/" , opCode : OpCode . Binary . DIVIDE } ,
147150 { arity : "binary" , name : "mod" , symbol : "%" , opCode : OpCode . Binary . MODULO } ,
148- { arity : "binary" , name : "equalTo" , symbol : "==" , opCode : OpCode . Binary . EQUAL } ,
149- { arity : "binary" , name : "notEqual" , symbol : "!=" , opCode : OpCode . Binary . NOT_EQUAL } ,
150- { arity : "binary" , name : "greaterThan" , symbol : ">" , opCode : OpCode . Binary . GREATER_THAN } ,
151- { arity : "binary" , name : "greaterEqual" , symbol : ">=" , opCode : OpCode . Binary . GREATER_EQUAL } ,
152- { arity : "binary" , name : "lessThan" , symbol : "<" , opCode : OpCode . Binary . LESS_THAN } ,
153- { arity : "binary" , name : "lessEqual" , symbol : "<=" , opCode : OpCode . Binary . LESS_EQUAL } ,
154- { arity : "binary" , name : "and" , symbol : "&&" , opCode : OpCode . Binary . LOGICAL_AND } ,
155- { arity : "binary" , name : "or" , symbol : "||" , opCode : OpCode . Binary . LOGICAL_OR } ,
151+ { arity : "binary" , boolean : true , name : "equalTo" , symbol : "==" , opCode : OpCode . Binary . EQUAL } ,
152+ { arity : "binary" , boolean : true , name : "notEqual" , symbol : "!=" , opCode : OpCode . Binary . NOT_EQUAL } ,
153+ { arity : "binary" , boolean : true , name : "greaterThan" , symbol : ">" , opCode : OpCode . Binary . GREATER_THAN } ,
154+ { arity : "binary" , boolean : true , name : "greaterEqual" , symbol : ">=" , opCode : OpCode . Binary . GREATER_EQUAL } ,
155+ { arity : "binary" , boolean : true , name : "lessThan" , symbol : "<" , opCode : OpCode . Binary . LESS_THAN } ,
156+ { arity : "binary" , boolean : true , name : "lessEqual" , symbol : "<=" , opCode : OpCode . Binary . LESS_EQUAL } ,
157+ { arity : "binary" , boolean : true , name : "and" , symbol : "&&" , opCode : OpCode . Binary . LOGICAL_AND } ,
158+ { arity : "binary" , boolean : true , name : "or" , symbol : "||" , opCode : OpCode . Binary . LOGICAL_OR } ,
156159] ;
157160export const ConstantFolding = {
158161 [ OpCode . Binary . ADD ] : ( a , b ) => a + b ,
@@ -173,7 +176,8 @@ export const ConstantFolding = {
173176export const OpCodeToSymbol = { } ;
174177export const UnarySymbolToName = { } ;
175178export const BinarySymbolToName = { } ;
176- for ( const { symbol, opCode, name, arity } of OperatorTable ) {
179+ export const booleanOpCode = { } ;
180+ for ( const { symbol, opCode, name, arity, boolean } of OperatorTable ) {
177181 // SymbolToOpCode[symbol] = opCode;
178182 OpCodeToSymbol [ opCode ] = symbol ;
179183 if ( arity === 'unary' ) {
@@ -182,6 +186,9 @@ for (const { symbol, opCode, name, arity } of OperatorTable) {
182186 if ( arity === 'binary' ) {
183187 BinarySymbolToName [ symbol ] = name ;
184188 }
189+ if ( boolean ) {
190+ booleanOpCode [ opCode ] = true ;
191+ }
185192}
186193export const BlockType = {
187194 GLOBAL : 'global' ,
0 commit comments