Skip to content

Commit 2b6802e

Browse files
fix: astBinaryExpression unit tests
Simplify internal/kernel.js tests
1 parent f48409c commit 2b6802e

File tree

8 files changed

+178
-359
lines changed

8 files changed

+178
-359
lines changed

bin/gpu-browser-core.js

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 2.0.0
8-
* @date Tue Feb 05 2019 21:07:15 GMT-0500 (Eastern Standard Time)
8+
* @date Tue Feb 05 2019 22:00:22 GMT-0500 (Eastern Standard Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -673,7 +673,6 @@ class CPUFunctionNode extends FunctionNode {
673673
module.exports = {
674674
CPUFunctionNode
675675
};
676-
677676
},{"../function-node":7}],4:[function(require,module,exports){
678677
const {
679678
utils
@@ -2818,19 +2817,30 @@ class WebGLFunctionNode extends FunctionNode {
28182817
}
28192818

28202819
retArr.push('(');
2821-
if (ast.operator === '===') {
2822-
this.astGeneric(ast.left, retArr);
2823-
retArr.push('==');
2824-
this.astGeneric(ast.right, retArr);
2825-
} else if (ast.operator === '!==') {
2826-
this.astGeneric(ast.left, retArr);
2827-
retArr.push('!=');
2828-
this.astGeneric(ast.right, retArr);
2829-
} else if (this.fixIntegerDivisionAccuracy && ast.operator === '/') {
2820+
if (this.fixIntegerDivisionAccuracy && ast.operator === '/') {
28302821
retArr.push('div_with_int_check(');
2831-
this.astGeneric(ast.left, retArr);
2822+
2823+
if (this.firstAvailableTypeFromAst(ast.left) !== 'Number') {
2824+
retArr.push('int(');
2825+
this.pushState('casting-to-float');
2826+
this.astGeneric(ast.left, retArr);
2827+
this.popState('casting-to-float');
2828+
retArr.push(')');
2829+
} else {
2830+
this.astGeneric(ast.left, retArr);
2831+
}
2832+
28322833
retArr.push(', ');
2833-
this.astGeneric(ast.right, retArr);
2834+
2835+
if (this.firstAvailableTypeFromAst(ast.right) !== 'Number') {
2836+
retArr.push('float(');
2837+
this.pushState('casting-to-float');
2838+
this.astGeneric(ast.right, retArr);
2839+
this.popState('casting-to-float');
2840+
retArr.push(')');
2841+
} else {
2842+
this.astGeneric(ast.right, retArr);
2843+
}
28342844
retArr.push(')');
28352845
} else {
28362846
const leftType = this.firstAvailableTypeFromAst(ast.left) || 'Number';
@@ -2842,25 +2852,25 @@ class WebGLFunctionNode extends FunctionNode {
28422852
switch (key) {
28432853
case 'Integer & Integer':
28442854
this.astGeneric(ast.left, retArr);
2845-
retArr.push(ast.operator);
2855+
retArr.push(operatorMap[ast.operator] || ast.operator);
28462856
this.astGeneric(ast.right, retArr);
28472857
break;
28482858
case 'Number & Number':
28492859
this.astGeneric(ast.left, retArr);
2850-
retArr.push(ast.operator);
2860+
retArr.push(operatorMap[ast.operator] || ast.operator);
28512861
this.astGeneric(ast.right, retArr);
28522862
break;
28532863
case 'LiteralInteger & LiteralInteger':
28542864
this.pushState('casting-to-float');
28552865
this.astGeneric(ast.left, retArr);
2856-
retArr.push(ast.operator);
2866+
retArr.push(operatorMap[ast.operator] || ast.operator);
28572867
this.astGeneric(ast.right, retArr);
28582868
this.popState('casting-to-float');
28592869
break;
28602870

28612871
case 'Integer & Number':
28622872
this.astGeneric(ast.left, retArr);
2863-
retArr.push(ast.operator);
2873+
retArr.push(operatorMap[ast.operator] || ast.operator);
28642874
this.pushState('casting-to-integer');
28652875
retArr.push('int(');
28662876
this.astGeneric(ast.right, retArr);
@@ -2869,15 +2879,15 @@ class WebGLFunctionNode extends FunctionNode {
28692879
break;
28702880
case 'Integer & LiteralInteger':
28712881
this.astGeneric(ast.left, retArr);
2872-
retArr.push(ast.operator);
2882+
retArr.push(operatorMap[ast.operator] || ast.operator);
28732883
this.pushState('casting-to-integer');
28742884
this.astGeneric(ast.right, retArr);
28752885
this.popState('casting-to-integer');
28762886
break;
28772887

28782888
case 'Number & Integer':
28792889
this.astGeneric(ast.left, retArr);
2880-
retArr.push(ast.operator);
2890+
retArr.push(operatorMap[ast.operator] || ast.operator);
28812891
this.pushState('casting-to-float');
28822892
retArr.push('float(');
28832893
this.astGeneric(ast.right, retArr);
@@ -2886,7 +2896,7 @@ class WebGLFunctionNode extends FunctionNode {
28862896
break;
28872897
case 'Number & LiteralInteger':
28882898
this.astGeneric(ast.left, retArr);
2889-
retArr.push(ast.operator);
2899+
retArr.push(operatorMap[ast.operator] || ast.operator);
28902900
this.pushState('casting-to-float');
28912901
this.astGeneric(ast.right, retArr);
28922902
this.popState('casting-to-float');
@@ -2896,14 +2906,14 @@ class WebGLFunctionNode extends FunctionNode {
28962906
this.pushState('casting-to-float');
28972907
this.astGeneric(ast.left, retArr);
28982908
this.popState('casting-to-float');
2899-
retArr.push(ast.operator);
2909+
retArr.push(operatorMap[ast.operator] || ast.operator);
29002910
this.astGeneric(ast.right, retArr);
29012911
break;
29022912
case 'LiteralInteger & Integer':
29032913
this.pushState('casting-to-integer');
29042914
this.astGeneric(ast.left, retArr);
29052915
this.popState('casting-to-integer');
2906-
retArr.push(ast.operator);
2916+
retArr.push(operatorMap[ast.operator] || ast.operator);
29072917
this.astGeneric(ast.right, retArr);
29082918
break;
29092919
default:
@@ -3566,6 +3576,11 @@ const typeMap = {
35663576
'ArrayTexture(4)': 'sampler2D'
35673577
};
35683578

3579+
const operatorMap = {
3580+
'===': '==',
3581+
'!==': '!='
3582+
};
3583+
35693584
module.exports = {
35703585
WebGLFunctionNode
35713586
};

bin/gpu-browser.js

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* GPU Accelerated JavaScript
66
*
77
* @version 2.0.0
8-
* @date Tue Feb 05 2019 21:07:15 GMT-0500 (Eastern Standard Time)
8+
* @date Tue Feb 05 2019 22:00:22 GMT-0500 (Eastern Standard Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -5437,7 +5437,6 @@ class CPUFunctionNode extends FunctionNode {
54375437
module.exports = {
54385438
CPUFunctionNode
54395439
};
5440-
54415440
},{"../function-node":8}],5:[function(require,module,exports){
54425441
const {
54435442
utils
@@ -7582,19 +7581,30 @@ class WebGLFunctionNode extends FunctionNode {
75827581
}
75837582

75847583
retArr.push('(');
7585-
if (ast.operator === '===') {
7586-
this.astGeneric(ast.left, retArr);
7587-
retArr.push('==');
7588-
this.astGeneric(ast.right, retArr);
7589-
} else if (ast.operator === '!==') {
7590-
this.astGeneric(ast.left, retArr);
7591-
retArr.push('!=');
7592-
this.astGeneric(ast.right, retArr);
7593-
} else if (this.fixIntegerDivisionAccuracy && ast.operator === '/') {
7584+
if (this.fixIntegerDivisionAccuracy && ast.operator === '/') {
75947585
retArr.push('div_with_int_check(');
7595-
this.astGeneric(ast.left, retArr);
7586+
7587+
if (this.firstAvailableTypeFromAst(ast.left) !== 'Number') {
7588+
retArr.push('int(');
7589+
this.pushState('casting-to-float');
7590+
this.astGeneric(ast.left, retArr);
7591+
this.popState('casting-to-float');
7592+
retArr.push(')');
7593+
} else {
7594+
this.astGeneric(ast.left, retArr);
7595+
}
7596+
75967597
retArr.push(', ');
7597-
this.astGeneric(ast.right, retArr);
7598+
7599+
if (this.firstAvailableTypeFromAst(ast.right) !== 'Number') {
7600+
retArr.push('float(');
7601+
this.pushState('casting-to-float');
7602+
this.astGeneric(ast.right, retArr);
7603+
this.popState('casting-to-float');
7604+
retArr.push(')');
7605+
} else {
7606+
this.astGeneric(ast.right, retArr);
7607+
}
75987608
retArr.push(')');
75997609
} else {
76007610
const leftType = this.firstAvailableTypeFromAst(ast.left) || 'Number';
@@ -7606,25 +7616,25 @@ class WebGLFunctionNode extends FunctionNode {
76067616
switch (key) {
76077617
case 'Integer & Integer':
76087618
this.astGeneric(ast.left, retArr);
7609-
retArr.push(ast.operator);
7619+
retArr.push(operatorMap[ast.operator] || ast.operator);
76107620
this.astGeneric(ast.right, retArr);
76117621
break;
76127622
case 'Number & Number':
76137623
this.astGeneric(ast.left, retArr);
7614-
retArr.push(ast.operator);
7624+
retArr.push(operatorMap[ast.operator] || ast.operator);
76157625
this.astGeneric(ast.right, retArr);
76167626
break;
76177627
case 'LiteralInteger & LiteralInteger':
76187628
this.pushState('casting-to-float');
76197629
this.astGeneric(ast.left, retArr);
7620-
retArr.push(ast.operator);
7630+
retArr.push(operatorMap[ast.operator] || ast.operator);
76217631
this.astGeneric(ast.right, retArr);
76227632
this.popState('casting-to-float');
76237633
break;
76247634

76257635
case 'Integer & Number':
76267636
this.astGeneric(ast.left, retArr);
7627-
retArr.push(ast.operator);
7637+
retArr.push(operatorMap[ast.operator] || ast.operator);
76287638
this.pushState('casting-to-integer');
76297639
retArr.push('int(');
76307640
this.astGeneric(ast.right, retArr);
@@ -7633,15 +7643,15 @@ class WebGLFunctionNode extends FunctionNode {
76337643
break;
76347644
case 'Integer & LiteralInteger':
76357645
this.astGeneric(ast.left, retArr);
7636-
retArr.push(ast.operator);
7646+
retArr.push(operatorMap[ast.operator] || ast.operator);
76377647
this.pushState('casting-to-integer');
76387648
this.astGeneric(ast.right, retArr);
76397649
this.popState('casting-to-integer');
76407650
break;
76417651

76427652
case 'Number & Integer':
76437653
this.astGeneric(ast.left, retArr);
7644-
retArr.push(ast.operator);
7654+
retArr.push(operatorMap[ast.operator] || ast.operator);
76457655
this.pushState('casting-to-float');
76467656
retArr.push('float(');
76477657
this.astGeneric(ast.right, retArr);
@@ -7650,7 +7660,7 @@ class WebGLFunctionNode extends FunctionNode {
76507660
break;
76517661
case 'Number & LiteralInteger':
76527662
this.astGeneric(ast.left, retArr);
7653-
retArr.push(ast.operator);
7663+
retArr.push(operatorMap[ast.operator] || ast.operator);
76547664
this.pushState('casting-to-float');
76557665
this.astGeneric(ast.right, retArr);
76567666
this.popState('casting-to-float');
@@ -7660,14 +7670,14 @@ class WebGLFunctionNode extends FunctionNode {
76607670
this.pushState('casting-to-float');
76617671
this.astGeneric(ast.left, retArr);
76627672
this.popState('casting-to-float');
7663-
retArr.push(ast.operator);
7673+
retArr.push(operatorMap[ast.operator] || ast.operator);
76647674
this.astGeneric(ast.right, retArr);
76657675
break;
76667676
case 'LiteralInteger & Integer':
76677677
this.pushState('casting-to-integer');
76687678
this.astGeneric(ast.left, retArr);
76697679
this.popState('casting-to-integer');
7670-
retArr.push(ast.operator);
7680+
retArr.push(operatorMap[ast.operator] || ast.operator);
76717681
this.astGeneric(ast.right, retArr);
76727682
break;
76737683
default:
@@ -8330,6 +8340,11 @@ const typeMap = {
83308340
'ArrayTexture(4)': 'sampler2D'
83318341
};
83328342

8343+
const operatorMap = {
8344+
'===': '==',
8345+
'!==': '!='
8346+
};
8347+
83338348
module.exports = {
83348349
WebGLFunctionNode
83358350
};

0 commit comments

Comments
 (0)