Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function(node, args) {
if (node.type !== Syntax.CallExpression) {
Shade.throwError(node, "Internal Error in Math object");
}
// Cast all arguments of the math function to float, as they are
// not defined for other types (int, bool)
// Don't replace the arguments array, it's already cached by the traversal
for(var i = 0; i < args.length; i++) {
if (args[i].isInt())
node.arguments[i] = Tools.castToFloat(node.arguments[i]);
}
node.callee = Tools.removeMemberFromExpression(node.callee);
if (opt.name) {
node.callee.name = opt.name;
}
if (opt.arguments) {
for (var idx = 0; idx < opt.arguments.length; ++idx)
if (typeof opt.arguments[idx] !== "undefined")
function trampoline(node) {
switch (node.type) {
// re-direct all non-primitive calls through trampoline
// this is only okay in cps where no implicit stack is used!
case Syntax.ExpressionStatement:
switch (node.expression.type) {
case Syntax.CallExpression:
if (isPrimitive(node.expression.callee)) {
return node;
}
else {
return build.returnStatement(thunkify(node.expression));
}
default:
return build.returnStatement(thunkify(node.expression));
}
default:
return node;
}
}
function naming(node) {
switch (node.type) {
case Syntax.FunctionExpression:
return build.functionExpression(node.id,
[addresses.shift()].concat(node.params),
node.body);
// add a gensym onto the address variable
case Syntax.CallExpression:
if (isPrimitive(node.callee)) {
return node;
} else {
return build.callExpression(node.callee,
[makeAddressExtension(addresses[0])].concat(node.arguments));
}
default:
}
}
return Au(store, environment, element);
})));
case Syntax.BinaryExpression:
if (expr.operator === '+' ||
expr.operator === '-') {
return Set.of(new Num({}));
}
else if (expr.operator === '==') {
return Set.of(true, false);
}
else {
console.log(Au(store, environment, expr.left));
console.log(Au(store, environment, expr.right));
throw new Error('Au: unhandled binary operator ' + expr.operator);
}
case Syntax.CallExpression:
if (types.MemberExpression.check(expr.callee) &&
! expr.callee.computed &&
expr.callee.property.name === 'concat') {
console.log(Au(store, environment, expr.callee.object));
console.log(Au(store, environment, expr.callee.object));
throw 23;
}
else {
console.log(expr);
console.log(require('escodegen').generate(expr));
throw 12;
}
case Syntax.FunctionExpression:
return Set.of(expr);
case Syntax.Identifier:
var value = environment.get(expr.name, false) || store.get(expr.name, false);
createFunctionCall: function(functionName, secondVecSize, node, args, parent) {
var replace = {
type: Syntax.CallExpression,
callee: {
type: Syntax.Identifier,
name: functionName
},
arguments: [
node.callee.object
]
};
if(secondVecSize){
var other = Vec.generateVecFromArgs(secondVecSize, node.arguments);
replace.arguments.push(other);
}
ANNO(replace).copy(ANNO(node));
return replace;
},
callExp: function(node) {
return {
type: Syntax.BinaryExpression,
operator: "+",
left: {
type: Syntax.CallExpression,
callee: node.callee.property,
arguments: node.arguments
},
right: node.callee,
extra: {
type: Shade.TYPES.OBJECT,
kind: Shade.OBJECT_KINDS.COLOR_CLOSURE
}
}
}
},
object: node.callee.object,
property: node.arguments[0],
computed: true
};
ANNO(memberAccess).setType(TYPES.OBJECT, Mat.TYPES[matName].colKind);
if (args.length == 1) {
return memberAccess;
}
else {
var methodKey = "_" + matName + "_col";
var methodName = ns.getInternalFunctionName(state, methodKey,
"MatCol", {colType: "vec" + Mat.TYPES[matName].colCount, matType: Mat.TYPES[matName].glslType});
var replace = {
type: Syntax.CallExpression,
callee: {type: Syntax.Identifier, name: methodName},
arguments: [
node.callee.object,
node.arguments[0],
node.arguments[1]
]
};
ANNO(replace).copy(ANNO(node));
return replace;
}
}
function wrapProgram(node) {
var expr = node.body[0].expression;
assert.ok(expr.type === Syntax.CallExpression);
return build.program([
build.expressionStatement(
build.functionExpression(
null,
[build.identifier(globalVarName)],
build.blockStatement([
build.returnStatement(expr)
])))]);
}
case Syntax.ArrayExpression:
case Syntax.AssignmentExpression:
case Syntax.BinaryExpression:
case Syntax.FunctionExpression:
case Syntax.Identifier:
case Syntax.Literal:
case Syntax.MemberExpression:
case Syntax.ObjectExpression:
case Syntax.UnaryExpression:
case Syntax.DebuggerStatement:
return atomize(node, function(node) {
return buildContinuationCall(k, node);
});
default:
return match(node, [
clause(Syntax.CallExpression, function(callee, args) {
return atomize(callee, function(callee) {
return atomizeStar(args, function(args) {
if (isPrimitive(callee)) {
return buildContinuationCall(k, buildCall(callee, args));
}
else {
return buildCall(callee, [k].concat(args));
}
});
});
}),
clause(Syntax.ConditionalExpression, function(test, consequent, alternate) {
return atomize(test, function(test) {
return bindContinuation(k, function(k) {
return build.conditionalExpression(test, cps(consequent, k), cps(alternate, k));
});
ns.binaryExpression2FunctionCall = function (node, name) {
node.right = ns.castToFloat(node.right);
node.left = ns.castToFloat(node.left);
return {
type: Syntax.CallExpression,
callee: {
type: Syntax.Identifier,
name: name
},
arguments: [
node.left,
node.right
],
extra: {
type: TYPES.NUMBER
}
}
};