math-codegen
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,2 +5,3 @@ 'use strict'; | ||
module.exports = { | ||
// arithmetic | ||
'+': 'add', | ||
@@ -12,6 +13,23 @@ '-': 'sub', | ||
'%': 'mod', | ||
// comparison | ||
'<': 'lessThan', | ||
'>': 'greaterThan', | ||
'<=': 'lessEqualThan', | ||
'>=': 'greaterEqualThan' | ||
'>=': 'greaterEqualThan', | ||
'===': 'strictlyEqual', | ||
'==': 'equal', | ||
'!==': 'strictlyNotEqual', | ||
'!=': 'notEqual', | ||
// shift | ||
'>>': 'shiftRight', | ||
'<<': 'shiftLeft', | ||
'>>>': 'unsignedRightShift', | ||
// logical | ||
'|': 'or', | ||
'&': 'and', | ||
'in': 'in', | ||
'instanceof': 'is' | ||
}; |
@@ -8,3 +8,5 @@ 'use strict'; | ||
'!': 'logicalNegation', | ||
'~': 'oneComplement' | ||
'~': 'oneComplement', | ||
'typeof': 'typeOf', | ||
'delete': 'del' | ||
}; |
@@ -6,15 +6,50 @@ /** | ||
function equalOperator(node) { | ||
return '(scope["' + node.left.name + '"] = ' + this.next(node.right) + ')'; | ||
return '(scope["' + node.left.name + '"] = ' + node.right + ')'; | ||
} | ||
function equalPreProcessOperator(node) { | ||
node.right = this.next(node.right); | ||
return equalOperator(node); | ||
} | ||
function binaryProxy(node, operator) { | ||
var right = { | ||
type: 'BinaryExpression', | ||
operator: operator, | ||
left: node.left, | ||
right: node.right | ||
}; | ||
return equalOperator({ | ||
left: node.left, | ||
right: this.next(right) | ||
}); | ||
} | ||
function binaryEqualOperator(operator) { | ||
return function (node) { | ||
// `this` is the Interpreter instance here | ||
return binaryProxy.call(this, node, operator); | ||
}; | ||
} | ||
// https://github.com/estree/estree/blob/master/spec.md#binaryoperator | ||
var operators = { | ||
'=': equalOperator | ||
'=': equalPreProcessOperator, | ||
'+=': binaryEqualOperator('+'), | ||
'-=': binaryEqualOperator('-'), | ||
'*=': binaryEqualOperator('*'), | ||
'/=': binaryEqualOperator('/'), | ||
'%=': binaryEqualOperator('%'), | ||
'<<=': binaryEqualOperator('<<'), | ||
'>>=': binaryEqualOperator('>>'), | ||
'>>>=': binaryEqualOperator('>>>'), | ||
'|=': binaryEqualOperator('|'), | ||
'^=': binaryEqualOperator('^'), | ||
'&=': binaryEqualOperator('^') | ||
}; | ||
module.exports = function (node) { | ||
if (!(node.operator in operators)) { | ||
throw new SyntaxError(node.operator + ' not implemented'); | ||
} | ||
return operators[node.operator].call(this, node); | ||
}; |
@@ -10,6 +10,2 @@ 'use strict'; | ||
if (!(node.operator in operators)) { | ||
throw new SyntaxError(node.operator + ' not implemented'); | ||
} | ||
// transform to CallExpression | ||
@@ -16,0 +12,0 @@ var binaryNode = { |
{ | ||
"name": "math-codegen", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Generates code from mathematical expressions", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/maurizzzio/math-codegen/issues", |
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
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
21157
289