Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: speed up compile by map #713

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 72 additions & 69 deletions src/backend/function-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,75 @@ const acorn = require('acorn');
const { utils } = require('../utils');
const { FunctionTracer } = require('./function-tracer');

const mathProperties = [
'E',
'PI',
'SQRT2',
'SQRT1_2',
'LN2',
'LN10',
'LOG2E',
'LOG10E',
];

const mathFunctions = [
'abs',
'acos',
'acosh',
'asin',
'asinh',
'atan',
'atan2',
'atanh',
'cbrt',
'ceil',
'clz32',
'cos',
'cosh',
'expm1',
'exp',
'floor',
'fround',
'imul',
'log',
'log2',
'log10',
'log1p',
'max',
'min',
'pow',
'random',
'round',
'sign',
'sin',
'sinh',
'sqrt',
'tan',
'tanh',
'trunc',
];

const allowedExpressions = [
'value',
'value[]',
'value[][]',
'value[][][]',
'value[][][][]',
'value.value',
'value.thread.value',
'this.thread.value',
'this.output.value',
'this.constants.value',
'this.constants.value[]',
'this.constants.value[][]',
'this.constants.value[][][]',
'this.constants.value[][][][]',
'fn()[]',
'fn()[][]',
'fn()[][][]',
'[][]',
];

/**
*
* @desc Represents a single function, inside JS, webGL, or openGL.
Expand Down Expand Up @@ -592,61 +661,15 @@ class FunctionNode {
}

isAstMathVariable(ast) {
const mathProperties = [
'E',
'PI',
'SQRT2',
'SQRT1_2',
'LN2',
'LN10',
'LOG2E',
'LOG10E',
];
return ast.type === 'MemberExpression' &&
ast.object && ast.object.type === 'Identifier' &&
ast.object.name === 'Math' &&
ast.property &&
ast.property.type === 'Identifier' &&
mathProperties.indexOf(ast.property.name) > -1;
mathProperties.includes(ast.property.name);
}

isAstMathFunction(ast) {
const mathFunctions = [
'abs',
'acos',
'acosh',
'asin',
'asinh',
'atan',
'atan2',
'atanh',
'cbrt',
'ceil',
'clz32',
'cos',
'cosh',
'expm1',
'exp',
'floor',
'fround',
'imul',
'log',
'log2',
'log10',
'log1p',
'max',
'min',
'pow',
'random',
'round',
'sign',
'sin',
'sinh',
'sqrt',
'tan',
'tanh',
'trunc',
];
return ast.type === 'CallExpression' &&
ast.callee &&
ast.callee.type === 'MemberExpression' &&
Expand All @@ -655,7 +678,7 @@ class FunctionNode {
ast.callee.object.name === 'Math' &&
ast.callee.property &&
ast.callee.property.type === 'Identifier' &&
mathFunctions.indexOf(ast.callee.property.name) > -1;
mathFunctions.includes(ast.callee.property.name);
}

isAstVariable(ast) {
Expand Down Expand Up @@ -844,27 +867,7 @@ class FunctionNode {
return signatureString;
}

const allowedExpressions = [
'value',
'value[]',
'value[][]',
'value[][][]',
'value[][][][]',
'value.value',
'value.thread.value',
'this.thread.value',
'this.output.value',
'this.constants.value',
'this.constants.value[]',
'this.constants.value[][]',
'this.constants.value[][][]',
'this.constants.value[][][][]',
'fn()[]',
'fn()[][]',
'fn()[][][]',
'[][]',
];
if (allowedExpressions.indexOf(signatureString) > -1) {
if (allowedExpressions.includes(signatureString)) {
return signatureString;
}
return null;
Expand Down