Skip to content

Commit e15870a

Browse files
committed
Merge branch 'master' of github.com:gpujs/gpu.js
2 parents df84a10 + e367060 commit e15870a

30 files changed

Lines changed: 476 additions & 344 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
**TODO: Add more stuff to this README =# **
66

7+
# Documentation
8+
Automatically built via a butler. Note that these documentations are quite prelimary, and **needs much cleanup**
9+
- Usr Docs : http://gpujs.github.io/usr-docs/
10+
- Dev Docs : http://gpujs.github.io/dev-docs/
11+
712
# HOWTO: Build / Generate Docs
813
- The following is required to be installed
914
- node.js

src/backend/functionNode.js

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ var functionNode = (function() {
3131
/// [Constructor] Builds the function with the given JS function, and argument type array.
3232
///
3333
/// Parameters:
34-
/// gpu - {GPU} The GPU instance
35-
/// functionName - {String} Function name to assume, if its null, it attempts to extract from the function
36-
/// jsFunction - {JS Function} JS Function to do conversion
37-
/// paramTypeArray - {[String,...]} Parameter type array, assumes all parameters are "float" if null
38-
/// returnType - {String} The return type, assumes "float" if null
34+
/// gpu - {GPU} The GPU instance
35+
/// functionName - {String} Function name to assume, if its null, it attempts to extract from the function
36+
/// jsFunction - {JS Function / String} JS Function to do conversion
37+
/// paramTypeArray - {[String,...]} Parameter type array, assumes all parameters are "float" if null
38+
/// returnType - {String} The return type, assumes "float" if null
3939
///
4040
function functionNode( gpu, functionName, jsFunction, paramTypeArray, returnType ) {
4141

@@ -50,22 +50,32 @@ var functionNode = (function() {
5050
this.writeVariables = [];
5151

5252
//
53-
// Setup jsFunction and its string property + validate them
53+
// Missing jsFunction object exception
5454
//
55-
this.jsFunction = jsFunction;
56-
if( !isFunction(this.jsFunction) ) {
57-
throw "jsFunction, is not a valid JS Function";
55+
if( jsFunction == null ) {
56+
throw "jsFunction, parameter is null";
5857
}
5958

59+
//
60+
// Setup jsFunction and its string property + validate them
61+
//
6062
this.jsFunctionString = jsFunction.toString();
6163
if( !validateStringIsFunction(this.jsFunctionString) ) {
62-
throw "jsFunction, to string conversion falied";
64+
console.error("jsFunction, to string conversion check falied: not a function?", this.jsFunctionString);
65+
throw "jsFunction, to string conversion check falied: not a function?";
66+
}
67+
68+
if( !isFunction(jsFunction) ) {
69+
//throw "jsFunction, is not a valid JS Function";
70+
this.jsFunction = null;
71+
} else {
72+
this.jsFunction = jsFunction;
6373
}
6474

6575
//
6676
// Setup the function name property
6777
//
68-
this.functionName = functionName || jsFunction.name;
78+
this.functionName = functionName || (jsFunction && jsFunction.name) || FUNCTION_NAME.exec(this.jsFunctionString)[1];
6979
if( !(this.functionName) ) {
7080
throw "jsFunction, missing name argument or value";
7181
}
@@ -136,6 +146,7 @@ var functionNode = (function() {
136146
return false;
137147
}
138148

149+
var FUNCTION_NAME = /function ([^(]*)/;
139150
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
140151
var ARGUMENT_NAMES = /([^\s,]+)/g;
141152

@@ -170,6 +181,29 @@ var functionNode = (function() {
170181
// Core function
171182
//----------------------------------------------------------------------------------------------------
172183

184+
///
185+
/// Function: getJSFunction
186+
///
187+
/// Gets and return the stored JS Function.
188+
/// Note: that this internally eval the function, if only the string was provided on construction
189+
///
190+
/// Returns:
191+
/// {JS Function} The function object
192+
///
193+
function getJSFunction() {
194+
if( this.jsFunction ) {
195+
return this.jsFunction;
196+
}
197+
198+
if( this.jsFunctionString ) {
199+
this.jsFunction = eval( this.jsFunctionString );
200+
return this.jsFunction;
201+
}
202+
203+
throw "Missin jsFunction, and jsFunctionString parameter";
204+
}
205+
functionNode.prototype.getJSFunction = getJSFunction;
206+
173207
///
174208
/// Function: getJS_AST
175209
///

src/backend/functionNode_webgl.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,7 @@ var functionNode_webgl = (function() {
147147
funcArr.push(lines[end.line-1].slice(0,end.column));
148148

149149
var funcStr = funcArr.join('\n');
150-
151-
// TODO: fix this evil!
152-
eval('var funcObj = ' + funcStr);
153-
154-
gpu.addFunction(funcObj);
150+
gpu.addFunction(funcStr);
155151

156152
return retArr;
157153
}

test/html/basic_for_loop.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/html/basic_if.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/html/basic_mult_AB.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/html/basic_return.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/html/basic_sum_AB.html

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>GPU.JS : add(Custom)Function</title>
6+
<link rel="stylesheet" href="../lib/qunit-1.20.0.css">
7+
8+
<!-- gpu.js scripts -->
9+
<script src="../../../src/parser.js"></script>
10+
<script src="../../../src/gpu.js"></script>
11+
<script src="../../../src/backend/functionNode_webgl.js"></script>
12+
<script src="../../../src/backend/functionNode.js"></script>
13+
<script src="../../../src/backend/functionBuilder.js"></script>
14+
<script src="../../../src/backend/glsl.js"></script>
15+
<script src="../../../src/backend/fallback.js"></script>
16+
</head>
17+
<body>
18+
<div id="qunit"></div>
19+
<div id="qunit-fixture"></div>
20+
<script src="../../lib/qunit-1.20.0.js"></script>
21+
<script src="../../src/features/addCustomFunction.js"></script>
22+
</body>
23+
</html>

test/html/features/for_loop.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>GPU.JS : For Loop</title>
6+
<link rel="stylesheet" href="../lib/qunit-1.20.0.css">
7+
8+
<!-- gpu.js scripts -->
9+
<script src="../../../src/parser.js"></script>
10+
<script src="../../../src/gpu.js"></script>
11+
<script src="../../../src/backend/functionNode_webgl.js"></script>
12+
<script src="../../../src/backend/functionNode.js"></script>
13+
<script src="../../../src/backend/functionBuilder.js"></script>
14+
<script src="../../../src/backend/glsl.js"></script>
15+
<script src="../../../src/backend/fallback.js"></script>
16+
</head>
17+
<body>
18+
<div id="qunit"></div>
19+
<div id="qunit-fixture"></div>
20+
<script src="../../lib/qunit-1.20.0.js"></script>
21+
<script src="../../src/features/for_loop.js"></script>
22+
</body>
23+
</html>

0 commit comments

Comments
 (0)