Skip to content

Commit b9deece

Browse files
committed
Standardize names
1 parent 48e01f2 commit b9deece

19 files changed

Lines changed: 80 additions & 96 deletions

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ gulp.task('build', function() {
88
return gulp.src([
99
'src/wrapper/prefix.js',
1010
'src/parser.js',
11+
'src/utils.js',
1112
'src/texture.js',
12-
'src/backend/gpu_utils.js',
1313
'src/gpu.js',
1414
'src/backend/functionNode_webgl.js',
1515
'src/backend/functionNode.js',

src/_anchor.txt

Whitespace-only changes.

src/backend/functionNode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ var functionNode = (function() {
6060
// Setup jsFunction and its string property + validate them
6161
//
6262
this.jsFunctionString = jsFunction.toString();
63-
if( !gpu_utils.isFunctionString(this.jsFunctionString) ) {
63+
if( !GPUUtils.isFunctionString(this.jsFunctionString) ) {
6464
console.error("jsFunction, to string conversion check falied: not a function?", this.jsFunctionString);
6565
throw "jsFunction, to string conversion check falied: not a function?";
6666
}
6767

68-
if( !gpu_utils.isFunction(jsFunction) ) {
68+
if( !GPUUtils.isFunction(jsFunction) ) {
6969
//throw "jsFunction, is not a valid JS Function";
7070
this.jsFunction = null;
7171
} else {
@@ -77,7 +77,7 @@ var functionNode = (function() {
7777
//
7878
this.functionName = functionName ||
7979
(jsFunction && jsFunction.name) ||
80-
gpu_utils.getFunctionName_fromString(this.jsFunctionString);
80+
GPUUtils.getFunctionName_fromString(this.jsFunctionString);
8181

8282
if( !(this.functionName) ) {
8383
throw "jsFunction, missing name argument or value";
@@ -86,7 +86,7 @@ var functionNode = (function() {
8686
//
8787
// Extract parameter name, and its argument types
8888
//
89-
this.paramNames = gpu_utils.getParamNames_fromString(this.jsFunctionString);
89+
this.paramNames = GPUUtils.getParamNames_fromString(this.jsFunctionString);
9090
if( paramTypeArray != null ) {
9191
if( paramTypeArray.length != this.paramNames.length ) {
9292
throw "Invalid argument type array length, against function length -> ("+

src/backend/mode_cpu.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
11
(function (GPU) {
2-
function clone(obj) {
3-
if(obj === null || typeof(obj) !== 'object' || 'isActiveClone' in obj)
4-
return obj;
5-
6-
var temp = obj.constructor(); // changed
7-
8-
for(var key in obj) {
9-
if(Object.prototype.hasOwnProperty.call(obj, key)) {
10-
obj.isActiveClone = null;
11-
temp[key] = clone(obj[key]);
12-
delete obj.isActiveClone;
13-
}
14-
}
15-
16-
return temp;
17-
}
18-
192
function getArgumentType(arg) {
203
if (Array.isArray(arg)) {
214
return 'Array';

src/backend/mode_gpu.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
11
(function(GPU) {
2-
function clone(obj) {
3-
if(obj === null || typeof(obj) !== 'object' || 'isActiveClone' in obj)
4-
return obj;
5-
6-
var temp = obj.constructor(); // changed
7-
8-
for(var key in obj) {
9-
if(Object.prototype.hasOwnProperty.call(obj, key)) {
10-
obj.isActiveClone = null;
11-
temp[key] = clone(obj[key]);
12-
delete obj.isActiveClone;
13-
}
14-
}
15-
16-
return temp;
17-
}
18-
192
function dimToTexSize(gl, dimensions) {
203
if (dimensions.length == 2) {
214
return dimensions;
@@ -47,15 +30,6 @@
4730
}
4831
return false;
4932
}
50-
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
51-
var ARGUMENT_NAMES = /([^\s,]+)/g;
52-
function getParamNames(func) {
53-
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
54-
var result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
55-
if(result === null)
56-
result = [];
57-
return result;
58-
}
5933

6034
function getDimensions(x, pad) {
6135
var ret;
@@ -74,7 +48,7 @@
7448
}
7549

7650
if (pad) {
77-
ret = clone(ret);
51+
ret = GPUUtils.clone(ret);
7852
while (ret.length < 3) {
7953
ret.push(1);
8054
}
@@ -155,7 +129,7 @@
155129
throw "Unable to get body of kernel function";
156130
}
157131

158-
var paramNames = getParamNames(funcStr);
132+
var paramNames = GPUUtils.getParamNames_fromString(funcStr);
159133

160134
var programCache = [];
161135

@@ -180,7 +154,7 @@
180154
canvas.height = texSize[1];
181155
gl.viewport(0, 0, texSize[0], texSize[1]);
182156

183-
var threadDim = clone(opt.dimensions);
157+
var threadDim = GPUUtils.clone(opt.dimensions);
184158
while (threadDim.length < 3) {
185159
threadDim.push(1);
186160
}

src/gpu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var GPU = (function() {
3131
this.canvas = canvas;
3232
this.canvasCpu = canvasCpu;
3333
this.programCache = {};
34-
this.endianness = gpu_utils.system_endianness();
34+
this.endianness = GPUUtils.systemEndianness();
3535

3636
this.functionBuilder = new functionBuilder(this);
3737
this.functionBuilder.polyfillStandardFunctions();
Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
11
///
2-
/// Class: gpu_utils
2+
/// Class: GPUUtils
33
///
44
/// Various utility functions / snippets of code that GPU.JS uses internally.\
55
/// This covers various snippets of code that is NOT gpu.js specific
66
///
7-
/// Note that all moethods in this class is "static" by nature `gpu_utils.functionName()`
7+
/// Note that all moethods in this class is "static" by nature `GPUUtils.functionName()`
88
///
9-
var gpu_utils = (function() {
9+
var GPUUtils = (function() {
1010

11-
function gpu_utils() {
12-
throw new Error("This is a utility class - do not construct it");
13-
}
11+
var GPUUtils = {};
1412

1513
// system_endianness closure based memoizer
16-
var system_endianness_memoizer = null;
14+
var endianness = null;
1715

1816
///
1917
/// Function: system_endianness
2018
///
2119
/// Gets the system endianness, and cache it
2220
///
2321
/// Returns:
24-
/// {String} "LE" or "BE" depending on system settings
22+
/// {String} "LE" or "BE" depending on system architecture
2523
///
2624
/// Credit: https://gist.github.com/TooTallNate/4750953
27-
function system_endianness() {
28-
if( system_endianness_memoizer !== null ) {
29-
return system_endianness_memoizer;
25+
function systemEndianness() {
26+
if( endianness !== null ) {
27+
return endianness;
3028
}
3129

3230
var b = new ArrayBuffer(4);
3331
var a = new Uint32Array(b);
3432
var c = new Uint8Array(b);
3533
a[0] = 0xdeadbeef;
36-
if (c[0] == 0xef) return system_endianness_memoizer = 'LE';
37-
if (c[0] == 0xde) return system_endianness_memoizer = 'BE';
34+
if (c[0] == 0xef) return endianness = 'LE';
35+
if (c[0] == 0xde) return endianness = 'BE';
3836
throw new Error('unknown endianness');
3937
}
40-
gpu_utils.system_endianness = system_endianness;
38+
GPUUtils.systemEndianness = systemEndianness;
4139

4240
///
4341
/// Function: isFunction
@@ -53,7 +51,7 @@ var gpu_utils = (function() {
5351
function isFunction( funcObj ) {
5452
return typeof(funcObj) === 'function';
5553
}
56-
gpu_utils.isFunction = isFunction;
54+
GPUUtils.isFunction = isFunction;
5755

5856
///
5957
/// Function: isFunctionString
@@ -74,7 +72,7 @@ var gpu_utils = (function() {
7472
}
7573
return false;
7674
}
77-
gpu_utils.isFunctionString = isFunctionString;
75+
GPUUtils.isFunctionString = isFunctionString;
7876

7977
// FUNCTION_NAME regex
8078
var FUNCTION_NAME = /function ([^(]*)/;
@@ -93,7 +91,7 @@ var gpu_utils = (function() {
9391
function getFunctionName_fromString( funcStr ) {
9492
return FUNCTION_NAME.exec(funcStr)[1];
9593
}
96-
gpu_utils.getFunctionName_fromString = getFunctionName_fromString;
94+
GPUUtils.getFunctionName_fromString = getFunctionName_fromString;
9795

9896
// STRIP COMMENTS regex
9997
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
@@ -119,7 +117,36 @@ var gpu_utils = (function() {
119117
result = [];
120118
return result;
121119
}
122-
gpu_utils.getParamNames_fromString = getParamNames_fromString;
120+
GPUUtils.getParamNames_fromString = getParamNames_fromString;
121+
122+
///
123+
/// Function: clone
124+
///
125+
/// Returns a clone
126+
///
127+
/// Parameters:
128+
/// obj - {Object} Object to clone
129+
///
130+
/// Returns:
131+
/// {Object} Cloned object
132+
///
133+
function clone(obj) {
134+
if(obj === null || typeof(obj) !== 'object' || 'isActiveClone' in obj)
135+
return obj;
136+
137+
var temp = obj.constructor(); // changed
138+
139+
for(var key in obj) {
140+
if(Object.prototype.hasOwnProperty.call(obj, key)) {
141+
obj.isActiveClone = null;
142+
temp[key] = clone(obj[key]);
143+
delete obj.isActiveClone;
144+
}
145+
}
146+
147+
return temp;
148+
}
149+
GPUUtils.clone = clone;
123150

124-
return gpu_utils;
151+
return GPUUtils;
125152
})();

test/html/features/addCustomFunction.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- gpu.js scripts -->
99
<script src="../../../src/parser.js"></script>
1010
<script src="../../../src/gpu.js"></script>
11-
<script src="../../../src/backend/gpu_utils.js"></script>
11+
<script src="../../../src/utils.js"></script>
1212
<script src="../../../src/backend/functionNode_webgl.js"></script>
1313
<script src="../../../src/backend/functionNode.js"></script>
1414
<script src="../../../src/backend/functionBuilder.js"></script>

test/html/features/for_loop.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- gpu.js scripts -->
99
<script src="../../../src/parser.js"></script>
1010
<script src="../../../src/gpu.js"></script>
11-
<script src="../../../src/backend/gpu_utils.js"></script>
11+
<script src="../../../src/utils.js"></script>
1212
<script src="../../../src/backend/functionNode_webgl.js"></script>
1313
<script src="../../../src/backend/functionNode.js"></script>
1414
<script src="../../../src/backend/functionBuilder.js"></script>

test/html/features/function_return.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- gpu.js scripts -->
99
<script src="../../../src/parser.js"></script>
1010
<script src="../../../src/gpu.js"></script>
11-
<script src="../../../src/backend/gpu_utils.js"></script>
11+
<script src="../../../src/utils.js"></script>
1212
<script src="../../../src/backend/functionNode_webgl.js"></script>
1313
<script src="../../../src/backend/functionNode.js"></script>
1414
<script src="../../../src/backend/functionBuilder.js"></script>

0 commit comments

Comments
 (0)