made with esnextbin
Last active
June 6, 2017 12:07
-
-
Save kaosat-dev/27e3054a6de2d33702b6b2669631403f to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<!-- put markup and other contents here --> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const acorn = require('acorn') | |
const estraverse = require('estraverse') | |
//const travel = require('astravel') | |
const source = ` | |
const a = cube() | |
union( | |
difference( | |
cube(), | |
sphere(2) | |
), | |
intersection( | |
union(sphere(1.3), cube(2)), | |
a | |
) | |
) | |
` | |
const ast = acorn.parse(source) | |
//console.log(ast) | |
//determine all boolean operations that can be done in parallel | |
let indepOpsCandidates = [] | |
const opTypes = ['difference', 'union', 'intersection'] | |
estraverse.traverse(ast, { | |
enter: function (node, parent) { | |
//console.log(node) | |
if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration') | |
return estraverse.VisitorOption.Skip; | |
if(node.type === 'CallExpression' && opTypes.indexOf(node.callee.name)>-1 ) | |
{ | |
console.log('enter', node.callee.name, node) | |
//if(node.arguments[1].callee ) | |
//indepOpsCandidates.push(node) | |
} | |
}, | |
leave: function (node, parent) { | |
//console.log('leave', node) | |
if(node.type === 'CallExpression' && opTypes.indexOf(node.callee.name)>-1 ) | |
{ | |
console.log('leave', node.callee.name, node) | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"acorn": "4.0.11", | |
"estraverse": "4.2.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var acorn = require('acorn'); | |
var estraverse = require('estraverse'); | |
//const travel = require('astravel') | |
var source = '\nconst a = cube() \nunion(\n difference(\n cube(),\n sphere(2)\n ),\n intersection(\n union(sphere(1.3), cube(2)),\n a\n )\n )\n'; | |
var ast = acorn.parse(source); | |
//console.log(ast) | |
//determine all boolean operations that can be done in parallel | |
var indepOpsCandidates = []; | |
var opTypes = ['difference', 'union', 'intersection']; | |
estraverse.traverse(ast, { | |
enter: function enter(node, parent) { | |
//console.log(node) | |
if (node.type == 'FunctionExpression' || node.type == 'FunctionDeclaration') return estraverse.VisitorOption.Skip; | |
if (node.type === 'CallExpression' && opTypes.indexOf(node.callee.name) > -1) { | |
console.log('enter', node.callee.name, node); | |
//if(node.arguments[1].callee ) | |
//indepOpsCandidates.push(node) | |
} | |
}, | |
leave: function leave(node, parent) { | |
//console.log('leave', node) | |
if (node.type === 'CallExpression' && opTypes.indexOf(node.callee.name) > -1) { | |
console.log('leave', node.callee.name, node); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment