├── .gitignore ├── LICENSE ├── README.md ├── bin ├── usage.txt └── validate-asm ├── package.json └── test ├── invalid ├── GeometricMean-no-export.js └── GeometricMean-type.js ├── valid ├── GeometricMean-common.js └── GeometricMean-umd.js └── validate-asm.sh /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Alexander Gugel 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. 4 | 5 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated. This module is now [part of the official asm.js repository](https://github.com/dherman/asm.js/pull/103). 2 | 3 | 4 | [ ![Codeship Status for alexanderGugel/validate-asm](https://codeship.com/projects/93639d10-9cf4-0132-95e9-028d633c913e/status?branch=master)](https://codeship.com/projects/64402) 5 | 6 | # validate-asm 7 | 8 | Like JSLint, but for asm.js 9 | 10 | ## example 11 | 12 | Let's say you have an asm module called `GeometricMean.js`: 13 | 14 | ```javascript 15 | function GeometricMean(stdlib, foreign, buffer) { 16 | "use asm"; 17 | 18 | var exp = stdlib.Math.exp; 19 | var log = stdlib.Math.log; 20 | var values = new stdlib.Float64Array(buffer); 21 | 22 | function logSum(start, end) { 23 | start = start|0; 24 | end = end|0; 25 | 26 | var sum = 0.0, p = 0, q = 0; 27 | 28 | // asm.js forces byte addressing of the heap by requiring shifting by 3 29 | for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) { 30 | sum = sum + +log(values[p>>3]); 31 | } 32 | 33 | return +sum; 34 | } 35 | 36 | function geometricMean(start, end) { 37 | start = start|0; 38 | end = end|0; 39 | 40 | return +exp(+logSum(start, end) / +((end - start)|0)); 41 | } 42 | 43 | return { geometricMean: geometricMean }; 44 | } 45 | 46 | module.exports = GeometricMean; 47 | ``` 48 | 49 | In order to validate it, simply run 50 | 51 | `validate-asm GeometricMean.js` 52 | 53 | That's it! 54 | 55 | ## install 56 | 57 | With [npm](http://npmjs.org) do: 58 | 59 | ``` 60 | npm install -g validate-asm 61 | ``` 62 | 63 | ## usage 64 | 65 | ``` 66 | Usage: validate-asm [entry files] {OPTIONS} 67 | 68 | Standard Options: 69 | 70 | --help, -h Show this message 71 | 72 | Specify a parameter. 73 | ``` 74 | 75 | ## credits 76 | 77 | * based on [asm.js](https://github.com/dherman/asm.js/tree/master/lib) 78 | 79 | ## license 80 | 81 | ISC 82 | -------------------------------------------------------------------------------- /bin/usage.txt: -------------------------------------------------------------------------------- 1 | Usage: validate-asm [entry files] {OPTIONS} 2 | 3 | Standard Options: 4 | 5 | --help, -h Show this message 6 | 7 | Specify a parameter. 8 | -------------------------------------------------------------------------------- /bin/validate-asm: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var path = require('path'); 4 | var argv = require('minimist')(process.argv.slice(2)); 5 | var colors = require('colors/safe'); 6 | var asm = require('asm.js'); 7 | var fs = require('fs'); 8 | 9 | var exitCode = 0; 10 | 11 | if (argv.help || argv._.length === 0) { 12 | return fs.createReadStream(__dirname + '/usage.txt') 13 | .pipe(process.stdout) 14 | .on('close', function () { 15 | process.exit(1); 16 | }) 17 | ; 18 | } 19 | 20 | var files = argv._; 21 | 22 | if (files.length === 0) { 23 | exitCode = 1; 24 | console.error(colors.red('No matching files found')); 25 | } 26 | 27 | files.forEach(function (file) { 28 | process.stdout.write('Validating ' + file + '...'); 29 | var module = require(path.resolve(process.cwd(), file)); 30 | if (typeof module !== 'function') { 31 | console.error(colors.red(' Error!')); 32 | console.error(colors.red(file + ' needs to export a single function')); 33 | exitCode = 1; 34 | return; 35 | } 36 | var source = String(module); 37 | try { 38 | asm.validate(source); 39 | console.log(colors.green(' Success!')); 40 | } catch(error) { 41 | console.log(colors.red(' Error!')); 42 | console.error(colors.red(error.stack)); 43 | exitCode = 1; 44 | } 45 | }); 46 | 47 | if (exitCode === 0) { 48 | console.log(colors.grey('---')); 49 | console.log(colors.green('No validation errors found')); 50 | } 51 | 52 | process.exit(exitCode) 53 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "validate-asm", 3 | "version": "0.0.1", 4 | "bin": { 5 | "validate-asm": "./bin/validate-asm" 6 | }, 7 | "scripts": { 8 | "test": "./test/validate-asm.sh" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "asm.js": "0.0.2", 14 | "colors": "^1.0.3", 15 | "minimist": "^1.1.0" 16 | }, 17 | "main": "index.js", 18 | "directories": { 19 | "test": "test" 20 | }, 21 | "devDependencies": {}, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/alexanderGugel/validate-asm.git" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/alexanderGugel/validate-asm/issues" 28 | }, 29 | "homepage": "https://github.com/alexanderGugel/validate-asm" 30 | } 31 | -------------------------------------------------------------------------------- /test/invalid/GeometricMean-no-export.js: -------------------------------------------------------------------------------- 1 | function GeometricMean(stdlib, foreign, buffer) { 2 | "use asm"; 3 | 4 | var exp = stdlib.Math.exp; 5 | var log = stdlib.Math.log; 6 | var values = new stdlib.Float64Array(buffer); 7 | 8 | function logSum(start, end) { 9 | start = start|0; 10 | end = end|0; 11 | 12 | var sum = 0.0, p = 0, q = 0; 13 | 14 | // asm.js forces byte addressing of the heap by requiring shifting by 3 15 | for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) { 16 | sum = sum + +log(values[p>>3]); 17 | } 18 | 19 | return +sum; 20 | } 21 | 22 | function geometricMean(start, end) { 23 | start = start|0; 24 | end = end|0; 25 | 26 | return +exp(+logSum(start, end) / +((end - start)|0)); 27 | } 28 | 29 | return { geometricMean: geometricMean }; 30 | } 31 | -------------------------------------------------------------------------------- /test/invalid/GeometricMean-type.js: -------------------------------------------------------------------------------- 1 | function GeometricMean(stdlib, foreign, buffer) { 2 | "use asm"; 3 | 4 | var exp = stdlib.Math.exp; 5 | var log = stdlib.Math.log; 6 | var values = new stdlib.Float64Array(buffer); 7 | 8 | function logSum(start, end) { 9 | start = start|0; 10 | end = end|0; 11 | 12 | var sum = 0, p = 0, q = 0; 13 | 14 | // asm.js forces byte addressing of the heap by requiring shifting by 3 15 | for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) { 16 | sum = sum + +log(values[p>>3]); 17 | } 18 | 19 | return +sum; 20 | } 21 | 22 | function geometricMean(start, end) { 23 | start = start|0; 24 | end = end|0; 25 | 26 | return +exp(+logSum(start, end) / +((end - start)|0)); 27 | } 28 | 29 | return { geometricMean: geometricMean }; 30 | } 31 | 32 | module.exports = GeometricMean; 33 | -------------------------------------------------------------------------------- /test/valid/GeometricMean-common.js: -------------------------------------------------------------------------------- 1 | function GeometricMean(stdlib, foreign, buffer) { 2 | "use asm"; 3 | 4 | var exp = stdlib.Math.exp; 5 | var log = stdlib.Math.log; 6 | var values = new stdlib.Float64Array(buffer); 7 | 8 | function logSum(start, end) { 9 | start = start|0; 10 | end = end|0; 11 | 12 | var sum = 0.0, p = 0, q = 0; 13 | 14 | // asm.js forces byte addressing of the heap by requiring shifting by 3 15 | for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) { 16 | sum = sum + +log(values[p>>3]); 17 | } 18 | 19 | return +sum; 20 | } 21 | 22 | function geometricMean(start, end) { 23 | start = start|0; 24 | end = end|0; 25 | 26 | return +exp(+logSum(start, end) / +((end - start)|0)); 27 | } 28 | 29 | return { geometricMean: geometricMean }; 30 | } 31 | 32 | module.exports = GeometricMean; 33 | -------------------------------------------------------------------------------- /test/valid/GeometricMean-umd.js: -------------------------------------------------------------------------------- 1 | function GeometricMean(stdlib, foreign, buffer) { 2 | "use asm"; 3 | 4 | var exp = stdlib.Math.exp; 5 | var log = stdlib.Math.log; 6 | var values = new stdlib.Float64Array(buffer); 7 | 8 | function logSum(start, end) { 9 | start = start|0; 10 | end = end|0; 11 | 12 | var sum = 0.0, p = 0, q = 0; 13 | 14 | // asm.js forces byte addressing of the heap by requiring shifting by 3 15 | for (p = start << 3, q = end << 3; (p|0) < (q|0); p = (p + 8)|0) { 16 | sum = sum + +log(values[p>>3]); 17 | } 18 | 19 | return +sum; 20 | } 21 | 22 | function geometricMean(start, end) { 23 | start = start|0; 24 | end = end|0; 25 | 26 | return +exp(+logSum(start, end) / +((end - start)|0)); 27 | } 28 | 29 | return { geometricMean: geometricMean }; 30 | } 31 | 32 | // [UMD pattern](https://github.com/umdjs/umd) 33 | // used for making this module work with Node, AMD and browser globals 34 | (function (root, factory) { 35 | if (typeof define === 'function' && define.amd) { 36 | define([], factory); 37 | } else if (typeof exports === 'object') { 38 | module.exports = factory(); 39 | } else { 40 | root.returnExports = factory(); 41 | } 42 | }(this, function () { 43 | return GeometricMean; 44 | })); 45 | -------------------------------------------------------------------------------- /test/validate-asm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 4 | 5 | VALID_FILES=${DIR}/valid/*.js 6 | 7 | for f in $VALID_FILES 8 | do 9 | ./bin/validate-asm $f 10 | if [ $? -ne 0 ]; then 11 | exit 1 12 | fi 13 | done 14 | 15 | INVALID_FILES=${DIR}/invalid/*.js 16 | 17 | for f in $INVALID_FILES 18 | do 19 | ./bin/validate-asm $f 20 | if [ $? -ne 1 ]; then 21 | exit 1 22 | fi 23 | done 24 | --------------------------------------------------------------------------------