Comparing version 0.3.3 to 0.3.4
108
cwise.js
"use strict" | ||
var parse = require("cwise-parser") | ||
var createThunk = require("./lib/thunk.js") | ||
var parse = require("cwise-parser") | ||
var compile = require("cwise-compiler") | ||
@@ -9,18 +9,3 @@ var REQUIRED_FIELDS = [ "args", "body" ] | ||
function Procedure() { | ||
this.argTypes = [] | ||
this.shimArgs = [] | ||
this.arrayArgs = [] | ||
this.scalarArgs = [] | ||
this.indexArgs = [] | ||
this.shapeArgs = [] | ||
this.funcName = "" | ||
this.pre = null | ||
this.body = null | ||
this.post = null | ||
this.debug = false | ||
} | ||
function createCWise(user_args) { | ||
//Check parameters | ||
@@ -39,85 +24,14 @@ for(var id in user_args) { | ||
//Create procedure | ||
var proc = new Procedure() | ||
//Parse blocks | ||
proc.pre = parse(user_args.pre || function(){}) | ||
proc.body = parse(user_args.body) | ||
proc.post = parse(user_args.post || function(){}) | ||
//Parse arguments | ||
var proc_args = user_args.args.slice(0) | ||
proc.argTypes = proc_args | ||
for(var i=0; i<proc_args.length; ++i) { | ||
switch(proc_args[i]) { | ||
case "array": | ||
proc.arrayArgs.push(i) | ||
proc.shimArgs.push("array" + i) | ||
if(i < proc.pre.args.length && proc.pre.args[i].count>0) { | ||
throw new Error("cwise: pre() block may not reference array args") | ||
} | ||
if(i < proc.post.args.length && proc.post.args[i].count>0) { | ||
throw new Error("cwise: post() block may not reference array args") | ||
} | ||
break | ||
case "scalar": | ||
proc.scalarArgs.push(i) | ||
proc.shimArgs.push("scalar" + i) | ||
break | ||
case "index": | ||
proc.indexArgs.push(i) | ||
if(i < proc.pre.args.length && proc.pre.args[i].count > 0) { | ||
throw new Error("cwise: pre() block may not reference array index") | ||
} | ||
if(i < proc.body.args.length && proc.body.args[i].lvalue) { | ||
throw new Error("cwise: body() block may not write to array index") | ||
} | ||
if(i < proc.post.args.length && proc.post.args[i].count > 0) { | ||
throw new Error("cwise: post() block may not reference array index") | ||
} | ||
break | ||
case "shape": | ||
proc.shapeArgs.push(i) | ||
if(i < proc.pre.args.length && proc.pre.args[i].lvalue) { | ||
throw new Error("cwise: pre() block may not write to array shape") | ||
} | ||
if(i < proc.body.args.length && proc.body.args[i].lvalue) { | ||
throw new Error("cwise: body() block may not write to array shape") | ||
} | ||
if(i < proc.post.args.length && proc.post.args[i].lvalue) { | ||
throw new Error("cwise: post() block may not write to array shape") | ||
} | ||
break | ||
default: | ||
throw new Error("cwise: Unknown argument type " + proc_args[i]) | ||
} | ||
} | ||
//Make sure at least one array argument was specified | ||
if(proc.arrayArgs.length <= 0) { | ||
throw new Error("cwise: No array arguments specified") | ||
} | ||
//Make sure arguments are correct | ||
if(proc.pre.args.length > proc_args.length) { | ||
throw new Error("cwise: Too many arguments in pre() block") | ||
} | ||
if(proc.body.args.length > proc_args.length) { | ||
throw new Error("cwise: Too many arguments in body() block") | ||
} | ||
if(proc.post.args.length > proc_args.length) { | ||
throw new Error("cwise: Too many arguments in post() block") | ||
} | ||
//Check debug flag | ||
proc.debug = !!user_args.printCode | ||
//Retrieve name | ||
proc.funcName = user_args.funcName || user_args.body.name || "cwise" | ||
//Read in block size | ||
proc.blockSize = user_args.blockSize || 64 | ||
//Assemble thunk | ||
return createThunk(proc) | ||
return compile({ | ||
args: user_args.args, | ||
pre: parse(user_args.pre || function(){}), | ||
body: parse(user_args.body), | ||
post: parse(user_args.post || function(){}), | ||
debug: !!user_args.printCode, | ||
funcName: user_args.funcName || user_args.body.name || "cwise", | ||
blockSize: user_args.blockSize || 64 | ||
}) | ||
} | ||
module.exports = createCWise |
{ | ||
"name": "cwise", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Component-wise map/reduce for ndarrays", | ||
@@ -11,3 +11,3 @@ "main": "cwise.js", | ||
"cwise-parser": "~0.0.1", | ||
"uniq": "~0.0.2" | ||
"cwise-compiler": "~0.0.0" | ||
}, | ||
@@ -41,5 +41,5 @@ "devDependencies": { | ||
"author": "Mikola Lysenko", | ||
"license": "BSD", | ||
"license": "MIT", | ||
"gitHead": "1dd03e72f1b0fbec4186e497b3956d87aec6fc15", | ||
"readmeFilename": "README.md" | ||
} |
@@ -214,2 +214,2 @@ cwise | ||
======= | ||
(c) 2013 Mikola Lysenko. BSD License | ||
(c) 2013 Mikola Lysenko. MIT License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
0
1
8744
5
30
+ Addedcwise-compiler@~0.0.0
+ Addedcwise-compiler@0.0.0(transitive)
- Removeduniq@~0.0.2