New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

khepri-compile

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

khepri-compile - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

dist_node/ast.js

65

dist_node/builtin.js
/*
* THIS FILE IS AUTO GENERATED from 'lib/builtin.kep'
* THIS FILE IS AUTO GENERATED FROM 'lib/builtin.kep'
* DO NOT EDIT
*/"use strict";
*/
"use strict";
var ast_node = require("khepri-ast")["node"],

@@ -9,9 +10,61 @@ setData = ast_node["setData"],

ast_pattern = require("khepri-ast")["pattern"],
ast_expression = require("khepri-ast")["expression"],
ast_value = require("khepri-ast")["value"],
builtins;
builtins, unique = (function() {
var x = 0;
return (function() {
(x = (x + 1));
return x;
});
})(),
binary = (function(uid, op) {
var xArg = setData(ast_value.Identifier.create(null, "x"), "uid", unique()),
yArg = setData(ast_value.Identifier.create(null, "y"), "uid", unique());
return ast_expression.FunctionExpression.create(null, null, ast_pattern.ArgumentsPattern.create(null, null, [
ast_pattern.IdentifierPattern.create(null, xArg), ast_pattern.IdentifierPattern.create(null,
yArg)
]), op(xArg, yArg));
}),
binaryOp = (function(op, flipped) {
return binary(unique(), (function(x, y) {
return ast_expression.BinaryExpression.create(null, op, (flipped ? y : x), (flipped ? x : y));
}));
});
(builtins = ({
"require": setData(new(ast_value.Identifier)(null, "require"), "uid", 1),
"exports": setData(new(ast_value.Identifier)(null, "exports"), "uid", 2),
"module": setData(new(ast_value.Identifier)(null, "module"), "uid", 2)
"require": setData(new(ast_value.Identifier)(null, "require"), "uid", unique()),
"exports": setData(new(ast_value.Identifier)(null, "exports"), "uid", unique()),
"module": setData(new(ast_value.Identifier)(null, "module"), "uid", unique())
}));
[
["+", "__add"],
["-", "__sub"],
["*", "__mul"],
["/", "__div"],
["%", "__mod"],
["<<", "__blas"],
[">>", "__bras"],
[">>>", "__brls"],
["&", "__band"],
["^", "__bxor"],
["|", "bor"],
["<", "__lt"],
[">", "__gt"],
["<=", "__lte"],
[">=", "__gte"],
["==", "__eq"],
["!=", "__neq"],
["===", "__seq"],
["!==", "__sneq"],
["|>", "__pipe"],
["<|", "__rpipe"],
["\\>", "__compose"],
["\\>>", "__composen"],
["<\\", "__rcompose"],
["<<\\", "__rcomposen"]
].forEach((function(__o) {
var op = __o[0],
name = __o[1];
(builtins[op] = binaryOp(op));
(builtins[("_" + op)] = binaryOp(op, true));
}));
(module.exports = builtins);

22

dist_node/compile.js

@@ -6,7 +6,9 @@ /*

"use strict";
var lexical = require("./stage/lexical"),
normalize = require("./stage/normalize"),
transform = require("./stage/transform"),
khepri_peep = require("./stage/khepri_peep"),
ecma_peep = require("./stage/ecma_peep"),
var pre_normalize = require("./stages/pre_normalize"),
lexical = require("./stages/lexical"),
post_normalize = require("./stages/post_normalize"),
inline = require("./stages/inline"),
khepri_peep = require("./stages/khepri_peep"),
transform = require("./stages/transform"),
ecma_peep = require("./stages/ecma_peep"),
compile, compiler = (function(f, g) {

@@ -28,3 +30,11 @@ return (function(x) {

});
})(ecma_peep, transform), khepri_peep), lexical), normalize);
})((function(f, g) {
return (function(x) {
return f(g(x));
});
})((function(f, g) {
return (function(x) {
return f(g(x));
});
})(ecma_peep, transform), khepri_peep), inline), post_normalize), lexical), pre_normalize);
(compile = (function(f, g) {

@@ -31,0 +41,0 @@ return (function() {

@@ -80,83 +80,2 @@ /*

}));
var arithmetic = ({
"+": (function(x, y) {
return (x + y);
}),
"-": (function(x, y) {
return (x - y);
}),
"*": (function(x, y) {
return (x * y);
}),
"/": (function(x, y) {
return (x / y);
}),
"%": "%",
"<<": (function(x, y) {
return (x << y);
}),
">>": (function(x, y) {
return (x >> y);
}),
">>>": (function(x, y) {
return (x >>> y);
}),
"<": (function(x, y) {
return (x < y);
}),
">": (function(x, y) {
return (x > y);
}),
"<=": (function(x, y) {
return (x <= y);
}),
">=": (function(x, y) {
return (x >= y);
}),
"||": (function(x, y) {
return (x || y);
}),
"&&": (function(x, y) {
return (x && y);
})
});
addPeephole(["BinaryExpression", "LogicalExpression"], true, (function(__o) {
var operator = __o["operator"],
left = __o["left"],
right = __o["right"];
return ((arithmetic[operator] && isPrimitive(left)) && isPrimitive(right));
}), (function(__o) {
var operator = __o["operator"],
left = __o["left"],
right = __o["right"],
value = arithmetic[operator](left.value, right.value);
return ast_value.Literal.create(null, (typeof value), value);
}));
var arithmetic0 = ({
"!": (function(x) {
return (!x);
}),
"~": (function(x) {
return (~x);
}),
"typeof": (function(x) {
return (typeof x);
}),
"+": (function(x) {
return (+x);
}),
"-": (function(x) {
return (-x);
})
});
addPeephole(["UnaryExpression"], true, (function(__o) {
var operator = __o["operator"],
argument = __o["argument"];
return (arithmetic0[operator] && isPrimitive(argument));
}), (function(__o) {
var operator = __o["operator"],
argument = __o["argument"],
value = arithmetic0[operator](argument.value);
return ast_value.Literal.create(null, (typeof value), value);
}));
var upTransforms = (function(node) {

@@ -163,0 +82,0 @@ return ((node && peepholes[node.type]) || [])

@@ -6,3 +6,3 @@ /*

"use strict";
var constant, flip, reduce, reduceRight, foldl, foldr, concat, filter, map, flatten;
var constant, flip, reduce, reduceRight, foldl, foldr, concat, filter, map, flatten, flattenr;
(constant = (function(x) {

@@ -36,2 +36,5 @@ return (function() {

}));
(flattenr = (function(x) {
return (Array.isArray(x) ? flatten(x.map(flattenr)) : x);
}));
(exports["constant"] = constant);

@@ -46,2 +49,3 @@ (exports["flip"] = flip);

(exports["map"] = map);
(exports["flatten"] = flatten);
(exports["flatten"] = flatten);
(exports["flattenr"] = flattenr);
/*
* THIS FILE IS AUTO GENERATED FROM 'lib/khepri_peep.kep'
* THIS FILE IS AUTO GENERATED from 'lib/khepri_peep.kep'
* DO NOT EDIT
*/
"use strict";
var __o = require("khepri-ast-zipper"),
*/"use strict";
var hashtrie = require("hashtrie"),
__o = require("khepri-ast-zipper"),
khepriZipper = __o["khepriZipper"],

@@ -22,8 +22,13 @@ __o0 = require("khepri-ast")["node"],

Unique = require("akh")["unique"],
StateT = require("akh")["trans"]["state"],
ZipperT = require("zipper-m")["trans"]["zipper"],
walk = require("zipper-m")["walk"],
builtins = require("./builtin"),
fun = require("./fun"),
optimize, M = ZipperT(Unique),
__o2 = require("./ast"),
isPrimitive = __o2["isPrimitive"],
isTruthy = __o2["isTruthy"],
optimize, M = ZipperT(StateT(Unique)),
run = (function(c, ctx, seed) {
return Unique.runUnique(ZipperT.runZipperT(c, ctx), seed);
return Unique.runUnique(StateT.evalStateT(ZipperT.runZipperT(c, ctx), hashtrie.empty), seed);
}),

@@ -33,3 +38,18 @@ pass = M.of(null),

modify = M.modifyNode,
unique = M.lift(Unique.unique),
set = M.setNode,
unique = M.liftInner(Unique.unique),
getBinding = (function(uid) {
return (uid ? M.lift(M.inner.get)
.map((function(bindings) {
return hashtrie.get(uid, bindings);
})) : pass);
}),
addBinding = (function(uid, target) {
return getBinding((target.ud && target.ud.uid))
.chain((function(existing) {
return (existing ? addBinding(uid, existing) : M.lift(M.inner.modify((function(bindings) {
return hashtrie.set(uid, target, bindings);
}))));
}));
}),
peepholes = ({}),

@@ -45,96 +65,154 @@ addPeephole = (function(types, up, condition, f) {

}));
}),
arithmetic = ({
"+": (function(x, y) {
return (x + y);
}),
"-": (function(x, y) {
return (x - y);
}),
"*": (function(x, y) {
return (x * y);
}),
"/": (function(x, y) {
return (x / y);
}),
"%": "%",
"<<": (function(x, y) {
return (x << y);
}),
">>": (function(x, y) {
return (x >> y);
}),
">>>": (function(x, y) {
return (x >>> y);
}),
"<": (function(x, y) {
return (x < y);
}),
">": (function(x, y) {
return (x > y);
}),
"<=": (function(x, y) {
return (x <= y);
}),
">=": (function(x, y) {
return (x >= y);
}),
"||": (function(x, y) {
return (x || y);
}),
"&&": (function(x, y) {
return (x && y);
})
});
addPeephole(["ReturnStatement"], false, (function(node) {
return (node.argument && (node.argument.type === "LetExpression"));
}), modify((function(node) {
return ast_statement.WithStatement.create(null, node.argument.bindings, ast_statement.BlockStatement.create(
null, [ast_statement.ReturnStatement.create(node.loc, node.argument.body)]));
addPeephole(["BinaryExpression", "LogicalExpression"], true, (function(__o) {
var operator = __o["operator"],
left = __o["left"],
right = __o["right"];
return ((arithmetic[operator] && isPrimitive(left)) && isPrimitive(right));
}), modify((function(__o) {
var operator = __o["operator"],
left = __o["left"],
right = __o["right"],
value = arithmetic[operator](left.value, right.value);
return ast_value.Literal.create(null, (typeof value), value);
})));
addPeephole(["FunctionExpression"], false, (function(node) {
return (node.body.type === "LetExpression");
}), modify((function(node) {
return ast_expression.FunctionExpression.create(null, node.id, node.params, ast_statement.BlockStatement
.create(null, [ast_statement.WithStatement.create(null, node.body.bindings, ast_statement.BlockStatement
.create(null, [ast_statement.ReturnStatement.create(node.loc, node.body.body)]))]));
var arithmetic0 = ({
"!": (function(x) {
return (!x);
}),
"~": (function(x) {
return (~x);
}),
"typeof": (function(x) {
return (typeof x);
}),
"++": (function(x) {
return (+x);
}),
"--": (function(x) {
return (-x);
})
});
addPeephole(["UnaryExpression"], true, (function(__o) {
var operator = __o["operator"],
argument = __o["argument"];
return (arithmetic0[operator] && isPrimitive(argument));
}), modify((function(__o) {
var operator = __o["operator"],
argument = __o["argument"],
value = arithmetic0[operator](argument.value);
return ast_value.Literal.create(null, (typeof value), value);
})));
addPeephole(["ExpressionStatement"], true, (function(node) {
return (node.expression && (node.expression.type === "LetExpression"));
}), modify((function(node) {
return ast_statement.WithStatement.create(null, node.expression.bindings, ast_statement.BlockStatement.create(
null, [ast_statement.ExpressionStatement.create(node.loc, node.expression.body)]));
addPeephole(["IfStatement"], true, (function(node) {
return isPrimitive(node.test);
}), modify((function(__o) {
var test = __o["test"],
consequent = __o["consequent"],
alternate = __o["alternate"];
return (isTruthy(test) ? consequent : alternate);
})));
addPeephole(["ExpressionStatement"], true, (function(node) {
return ((node.expression && (node.expression.type === "AssignmentExpression")) && (node.expression.right.type ===
"LetExpression"));
}), modify((function(node) {
return ast_statement.WithStatement.create(null, node.expression.right.bindings, ast_statement.BlockStatement
.create(null, [ast_statement.ExpressionStatement.create(node.loc, ast_expression.AssignmentExpression
.create(node.expression.loc, node.expression.operator, node.expression.left, node.expression
.right.body))]));
addPeephole(["ConditionalExpression"], true, (function(node) {
return isPrimitive(node.test);
}), modify((function(__o) {
var test = __o["test"],
consequent = __o["consequent"],
alternate = __o["alternate"];
return (isTruthy(test) ? consequent : alternate);
})));
addPeephole(["LetExpression"], true, (function(node) {
return (node.body.type === "LetExpression");
addPeephole(["VariableDeclarator"], true, (function(node) {
return ((node.immutable && node.init) && (((node.init.type === "Identifier") && (node.init.ud.uid !== node.id
.ud.uid)) || isPrimitive(node.init)));
}), node.chain((function(node) {
return seq(addBinding(node.id.ud.uid, node.init), set([]));
})));
addPeephole(["Binding"], true, (function(node) {
return (((node.pattern.type === "IdentifierPattern") && node.pattern.id.ud) && (((node.value.type ===
"Identifier") && (node.value.ud.uid !== node.pattern.id.ud.uid)) || isPrimitive(node.value)));
}), node.chain((function(node) {
return seq(addBinding(node.pattern.id.ud.uid, node.value), set([]));
})));
addPeephole(["Identifier"], true, (function(node) {
return (node.ud && node.ud.uid);
}), node.chain((function(node) {
return getBinding(node.ud.uid)
.chain((function(binding) {
return (binding ? set(binding) : pass);
}));
})));
addPeephole(["Binding"], false, (function(node) {
return (node.value.type === "LetExpression");
}), modify((function(node) {
return ast_expression.LetExpression.create(null, fun.concat(node.bindings, node.body.bindings), node.body
.body);
return fun.flatten(node.value.bindings.concat(ast_declaration.Binding.create(null, node.pattern, node.value
.body)));
})));
addPeephole(["UnaryOperatorExpression"], true, (function(_) {
addPeephole(["VariableDeclaration"], true, (function(_) {
return true;
}), unique.chain((function(xUid) {
return modify((function(node) {
var arg = setData(ast_value.Identifier.create(null, "x"), "uid", xUid);
return ast_expression.FunctionExpression.create(null, null, ast_pattern.ArgumentsPattern.create(
null, null, [ast_pattern.IdentifierPattern.create(null, arg)]), ast_expression.UnaryExpression
.create(null, node.op, arg));
}));
}), modify((function(__o) {
var declarations = __o["declarations"],
bound = fun.flattenr(declarations);
return (bound.length ? ast_declaration.VariableDeclaration.create(null, bound) : null);
})));
addPeephole(["BinaryOperatorExpression"], true, (function(_) {
addPeephole(["LetExpression"], true, (function(_) {
return true;
}), unique.chain((function(xUid) {
return unique.chain((function(yUid) {
return modify((function(node) {
var xArg = setData(ast_value.Identifier.create(null, "x"), "uid", xUid),
yArg = setData(ast_value.Identifier.create(null, "y"), "uid", yUid),
kind = (((node.op === "||") || (node.op === "&&")) ? ast_expression.LogicalExpression
.create : ((node.op === ".") ? (function(loc, _, x, y) {
return ast_expression.MemberExpression.create(loc, x, y,
true);
}) : ((node.op === "@") ? (function(loc, _, x, y) {
return ast_expression.CurryExpression.create(loc, x, y);
}) : ((node.op === "new") ? (function(loc, _, x, y) {
return ast_expression.NewExpression.create(loc, x, [
y
]);
}) : ast_expression.BinaryExpression.create))));
return ast_expression.FunctionExpression.create(null, null, ast_pattern.ArgumentsPattern
.create(null, null, [ast_pattern.IdentifierPattern.create(null, xArg),
ast_pattern.IdentifierPattern.create(null, yArg)
]), (node.flipped ? kind(null, node.op, yArg, xArg) : kind(null, node.op,
xArg, yArg)));
}));
}));
}), modify((function(__o) {
var bindings = __o["bindings"],
body = __o["body"],
bound = fun.flattenr(bindings);
return (bound.length ? ast_expression.LetExpression.create(null, bound, body) : body);
})));
addPeephole(["CurryExpression"], true, (function(node) {
return ((node.base.type === "FunctionExpression") && (!node.base.params.id));
}), modify((function(node) {
var first = node.base.params.elements[0],
rest = node.base.params.elements.slice(1),
body = ast_expression.FunctionExpression.create(null, null, ast_pattern.ArgumentsPattern.create(
null, null, rest, node.base.params.self), node.base.body);
return ((first && (((first.type === "IdentifierPattern") || (first.type === "AsPattern")) || (first.type ===
"ObjectPattern"))) ? ast_expression.LetExpression.create(null, [ast_declaration.Binding.create(
null, first, node.args[0])], body) : body);
addPeephole(["WithStatement"], true, (function(_) {
return true;
}), modify((function(__o) {
var bindings = __o["bindings"],
body = __o["body"],
bound = fun.flattenr(bindings);
return (bound.length ? ast_statement.WithStatement.create(null, bound, body) : body);
})));
addPeephole(["CurryExpression"], true, (function(node) {
return (((node.base.type === "LetExpression") && (node.base.body.type === "FunctionExpression")) && (!node.base
.body.params.id));
addPeephole(["LetExpression"], true, (function(node) {
return (node.body.type === "LetExpression");
}), modify((function(node) {
var first = node.base.body.params.elements[0],
rest = node.base.body.params.elements.slice(1),
body = ast_expression.FunctionExpression.create(null, null, ast_pattern.ArgumentsPattern.create(
null, null, rest, node.base.body.params.self), node.base.body.body);
return ((first && (((first.type === "IdentifierPattern") || (first.type === "AsPattern")) || (first.type ===
"ObjectPattern"))) ? ast_expression.LetExpression.create(null, fun.concat(node.base.bindings,
ast_declaration.Binding.create(null, first, node.args[0])), body) : ast_expression.LetExpression
.create(null, node.base.bindings, body));
return ((node.body.type === "LetExpression") ? ast_expression.LetExpression.create(null, fun.concat(
node.bindings, node.body.bindings), node.body.body) : node);
})));

@@ -146,23 +224,2 @@ addPeephole(["CurryExpression"], true, (function(node) {

})));
addPeephole(["BinaryExpression"], true, (function(node) {
return ((node.operator === "|>") && (node.right.type === "CurryExpression"));
}), modify((function(node) {
return ast_expression.CallExpression.create(null, node.right.base, fun.concat((node.right.args || []),
node.left));
})));
addPeephole(["BinaryExpression"], true, (function(__o) {
var operator = __o["operator"],
left = __o["left"];
return ((operator === "<|") && (left.type === "CurryExpression"));
}), modify((function(node) {
return ast_expression.CallExpression.create(null, node.left.base, fun.concat((node.left.args || []),
node.right));
})));
addPeephole(["CallExpression"], true, (function(__o) {
var callee = __o["callee"];
return (callee.type === "CurryExpression");
}), modify((function(node) {
return ast_expression.CallExpression.create(null, node.callee.base, fun.concat((node.callee.args || []),
node.args));
})));
var upTransforms = (function(node) {

@@ -169,0 +226,0 @@ return ((node && peepholes[node.type]) || [])

@@ -228,3 +228,5 @@ /*

addCheck("SinkPattern", unique.chain((function(uid) {
return setNode(setData(ast_value.Identifier.create(null, "_"), "uid", uid));
return modifyNode((function(node) {
return setData(node, "id", setData(ast_value.Identifier.create(null, "_"), "uid", uid));
}));
})));

@@ -241,13 +243,3 @@ addCheck("IdentifierPattern", seq(inspect((function(node) {

}))));
addCheck("ObjectPattern", inspect((function(node) {
if (((!node.ud) || (!node.ud.id))) {
return seq(unique.chain((function(uid) {
var id = ast_pattern.IdentifierPattern.create(node.loc, setData(ast_value.Identifier
.create(null, "__o"), "uid", uid));
(id.reserved = true);
return setNode(ast_pattern.AsPattern.create(null, id, node));
})), checkTop);
}
return checkChild("elements");
})));
addCheck("ObjectPattern", checkChild("elements"));
addCheck("ObjectPatternElement", seq(checkChild("target"), checkChild("key")));

@@ -283,3 +275,3 @@ addCheck("ArgumentsPattern", seq(checkChild("id"), checkChild("elements"), checkChild("self")));

});
(check = (function(ast, globals) {
(check = (function(ast, globals, seed) {
return run(seq(checkTop, root, extractNode.chain((function(x) {

@@ -296,4 +288,4 @@ return unique.chain((function(unique) {

}));
}))), addBindings(g((globals || []))), khepriZipper(ast), suc, fail);
}))), addBindings(g((globals || []))), khepriZipper(ast), suc, fail, seed);
}));
(exports["check"] = check);
{
"name": "khepri-compile",
"version": "0.3.2",
"version": "0.3.3",
"description": "Compiler for the Khepri programming language",

@@ -37,2 +37,3 @@ "author": "Matt Bierner",

"neith": "1.5.x",
"nu-stream": ">=3.1.0",

@@ -39,0 +40,0 @@ "ecma-ast": "2.4.x",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc