forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction-node.js
More file actions
47 lines (41 loc) · 1.28 KB
/
function-node.js
File metadata and controls
47 lines (41 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const { utils } = require('../../utils');
const { WebGLFunctionNode } = require('../web-gl/function-node');
/**
* @class WebGL2FunctionNode
* @desc [INTERNAL] Takes in a function node, and does all the AST voodoo required to toString its respective webGL code.
* @extends WebGLFunctionNode
* @returns the converted webGL function string
*/
class WebGL2FunctionNode extends WebGLFunctionNode {
/**
* @desc Parses the abstract syntax tree for *identifier* expression
* @param {Object} idtNode - An ast Node
* @param {Array} retArr - return array string
* @returns {Array} the append retArr
*/
astIdentifierExpression(idtNode, retArr) {
if (idtNode.type !== 'Identifier') {
throw this.astErrorOutput(
'IdentifierExpression - not an Identifier',
idtNode
);
}
const type = this.getType(idtNode);
const name = utils.sanitizeName(idtNode.name);
if (idtNode.name === 'Infinity') {
retArr.push('intBitsToFloat(2139095039)');
} else if (type === 'Boolean') {
if (this.argumentNames.indexOf(name) > -1) {
retArr.push(`bool(user_${name})`);
} else {
retArr.push(`user_${name}`);
}
} else {
retArr.push(`user_${name}`);
}
return retArr;
}
}
module.exports = {
WebGL2FunctionNode
};