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

walt-compiler

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

walt-compiler - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

.nyc_output/04c89d16ed85990ecf6371713064876f.json

4

package.json
{
"name": "walt-compiler",
"version": "0.7.0",
"version": "0.8.0",
"description": "Alternative syntax for WebAssembly text format",

@@ -75,3 +75,3 @@ "main": "dist/walt.js",

"uglify-es": "3.0.17",
"walt-buildtools": "^0.0.3"
"walt-buildtools": "^0.0.4"
},

@@ -78,0 +78,0 @@ "prettier": {

@@ -11,21 +11,21 @@ # Snapshot report for `src/__tests__/compiler-spec.js`

`<Program value="ROOT_NODE" >␊
`<Program value="ROOT_NODE" type=null >␊
<Import value="import" >␊
<Import value="import" type=null >␊
<Sequence value="," >␊
<Sequence value="," type=null >␊
<Identifier value="getStringIterator" />␊
<BinaryExpression value="as" >␊
<Identifier value="getStringIterator" type=null />␊
<BinaryExpression value="as" type=null >␊
<Identifier value="next" />␊
<Identifier value="string_next" />␊
<Identifier value="next" type=null />␊
<Identifier value="string_next" type=null />␊
</BinaryExpression>␊
<Identifier value="reset" />␊
<Identifier value="stringLength" />␊
<Identifier value="indexOf" />␊
<Identifier value="reset" type=null />␊
<Identifier value="stringLength" type=null />␊
<Identifier value="indexOf" type=null />␊
</Sequence>␊
<StringLiteral value="../walt/string" />␊
<StringLiteral value="../walt/string" type=null />␊

@@ -32,0 +32,0 @@ </Import>␊

@@ -45,1 +45,21 @@ import test from "ava";

});
test("bool types", t => {
const source = `
const b : bool = false;
function foo() : bool {
return true;
}
function bar(): bool {
return false;
}
export function test() : bool {
return bar() || foo();
}
`;
return compileAndRun(source).then(({ instance }) => {
t.is(instance.exports.test(), 1);
});
});

@@ -223,6 +223,6 @@ // @flow

if (to === "i32" && from === "i64") {
if (["i32", "bool"].includes(to) && from === "i64") {
return def.i32Wrapi64;
}
if (to === "i64" && from === "i32") {
if (to === "i64" && ["i32", "bool"].includes(from)) {
return def.i64ExtendSi32;

@@ -229,0 +229,0 @@ }

@@ -70,10 +70,15 @@ // @flow

const validate = (block, i) =>
invariant(
block.kind,
"Unknown opcode generated in block index %s %s. \nOperand: \n%s",
i,
JSON.stringify(block),
printNode(operand)
);
const validate = (block, i) => {
// Only invariant a block if it's falsy, otherwise we will print _every_
// opcode generated.
if (!block.kind) {
invariant(
block.kind,
"Unknown opcode generated in block index %s %s. \nOperand: \n%s",
i,
JSON.stringify(block),
printNode(operand)
);
}
};
const blocks = mapping(operand, parent);

@@ -80,0 +85,0 @@ if (Array.isArray(blocks)) {

@@ -12,2 +12,8 @@ // @flow

if (node.value === "false" || node.value === "true") {
node.type = "bool";
node.value = node.value === "true" ? "1" : "0";
return ctx.endNode(node, Syntax.Constant);
}
if (ctx.eat(["("])) {

@@ -14,0 +20,0 @@ const params = [expression(ctx)];

// @flow
import Syntax from "../../Syntax";
import curry from "curry";
import { extendNode } from "../../utils/extend-node";
import { getTypeSize } from "../../utils/types";
import {

@@ -13,84 +15,69 @@ CLOSURE_TYPE,

const getTypeSize = typeString => {
switch (typeString) {
case "i64":
case "f64":
return 8;
case "i32":
case "f32":
default:
return 4;
}
const parseArray = type => {
const subscriptType = type.slice(-2) === "[]" ? "i32" : null;
return {
arrayType: subscriptType ? type.slice(0, -2) : null,
subscriptType,
};
};
const isClosureType = (types, type): boolean => {
return types[type] != null && !!types[type].meta[CLOSURE_TYPE];
};
const parse = (isConst, { types, scope }, declaration) => {
const index = Object.keys(scope).length;
const typeString = declaration.type;
const modifier = declaration.type.slice(-2);
const isArray = modifier === "[]";
const isClosure = isClosureType(types, typeString);
const type = (() => {
if (isArray) {
return "i32";
} else if (isClosure) {
return "i64";
}
return declaration.type;
})();
const meta = {
[TYPE_ARRAY]: isArray ? typeString.slice(0, -2) : null,
[CLOSURE_TYPE]: isClosure || null,
[TYPE_CONST]: isConst || null,
[TYPE_INDEX]: isClosure ? Object.keys(types).indexOf(typeString) : null,
};
// Parse and return a fully typed declaration options
// [ type, meta, index ]
const parse = ({ isConst, types, scope, node }) => {
const { subscriptType, arrayType } = parseArray(node.type);
const closureType =
types[node.type] && types[node.type].meta[CLOSURE_TYPE] ? "i64" : null;
return [type, meta, index];
return [
subscriptType || closureType || node.type,
{
[TYPE_ARRAY]: arrayType,
[TYPE_CONST]: isConst || null,
[CLOSURE_TYPE]: closureType,
[TYPE_INDEX]: Object.keys(types).indexOf(node.type),
},
Object.keys(scope).length,
];
};
export const parseDeclaration = curry((isConst, options, declaration) => {
const { locals: scope, closures } = options;
const [type, meta, index] = parse(
isConst,
{ ...options, scope },
declaration
// Parse a local declaration
export const parseDeclaration = curry((isConst, options, node) => {
const { locals: scope, closures, types } = options;
const [type, meta, index] = parse({ isConst, types, scope, node });
scope[node.value] = extendNode(
{
params: node.params.map(extendNode({ type: node.type })),
type,
meta: { ...meta, [LOCAL_INDEX]: index },
Type: Syntax.Declaration,
},
node
);
const params = declaration.params.map(node => ({
...node,
type: declaration.type,
}));
if (closures.variables[node.value] != null && node.params[0]) {
closures.offsets[node.value] = closures.envSize;
closures.envSize += getTypeSize(node.type);
}
});
scope[declaration.value] = {
...declaration,
params,
type,
meta: { ...meta, [LOCAL_INDEX]: index },
Type: Syntax.Declaration,
};
// Map a global declaration
export const parseGlobalDeclaration = curry((isConst, options, node) => {
const { globals: scope, types } = options;
const [type, meta, index] = parse({ isConst, types, scope, node });
const { variables } = closures;
if (variables[declaration.value] != null && declaration.params[0]) {
const { offsets } = closures;
offsets[declaration.value] = closures.envSize;
closures.envSize += getTypeSize(declaration.type);
if (["Table", "Memory"].includes(node.type)) {
return extendNode({ meta: { [GLOBAL_INDEX]: -1 } }, node);
}
});
export const parseGlobalDeclaration = curry((isConst, options, node) => {
const { globals: scope } = options;
if (node.type !== "Table" && node.type !== "Memory") {
const [type, meta, index] = parse(isConst, { ...options, scope }, node);
scope[node.value] = {
...node,
scope[node.value] = extendNode(
{
meta: { ...meta, [GLOBAL_INDEX]: index },
type,
Type: Syntax.Declaration,
};
},
node
);
return scope[node.value];
}
return { ...node, meta: { [GLOBAL_INDEX]: -1 } };
return scope[node.value];
});

@@ -25,2 +25,3 @@ // @flow

} from "../closure";
import { typeWeight } from "../../types";
import makePair from "./map-pair";

@@ -242,3 +243,3 @@ import walkNode from "../../utils/walk-node";

expression.Type === Syntax.Constant &&
expression.type !== fun.type
typeWeight(expression.type) !== typeWeight(fun.type)
) {

@@ -245,0 +246,0 @@ return {

@@ -12,20 +12,2 @@ // @flow

if (identifier.value === "false") {
return {
...identifier,
type: "i32",
value: "0",
Type: Syntax.Constant,
};
}
if (identifier.value === "true") {
return {
...identifier,
type: "i32",
value: "1",
Type: Syntax.Constant,
};
}
if (identifier.value === "__DATA_LENGTH__") {

@@ -32,0 +14,0 @@ return {

// @flow
import Syntax from "../../Syntax";
import { TYPE_CAST } from "../metadata";
import { typeWeight } from "../../types";
import type { NodeType } from "../../flow/types";
export const typeWeight = (typeString: ?string) => {
switch (typeString) {
case "i32":
return 0;
case "i64":
return 1;
case "f32":
return 2;
case "f64":
return 3;
default:
return -1;
}
};
export const balanceTypesInMathExpression = (

@@ -36,3 +22,6 @@ expression: NodeType

const params = expression.params.map(paramNode => {
if (paramNode.type != null && paramNode.type !== type) {
if (
paramNode.type != null &&
typeWeight(paramNode.type) !== typeWeight(type)
) {
return {

@@ -39,0 +28,0 @@ ...paramNode,

@@ -66,2 +66,3 @@ // @flow

export const Table = "Table";
export const bool = "bool";

@@ -75,2 +76,3 @@ export const builtinTypes = {

Table,
bool,
};

@@ -77,0 +79,0 @@

@@ -16,2 +16,3 @@ // @flow

"u8[]",
"bool",
"Function",

@@ -18,0 +19,0 @@ "Memory",

@@ -193,3 +193,3 @@ # Snapshot report for `src/validation/__tests__/validation-spec.js`

^^^^^^^^^^^^^^^^^^ Variables must be assigned with a known type.␊
Unknown type used in a declartion, "unknown"␊
Unknown type used in a declaration, "unknown"␊
at global (spec.walt:2:4)␊

@@ -196,0 +196,0 @@

@@ -13,2 +13,3 @@ // @flow

} from "../semantics/metadata";
import { typeWeight } from "../types";
import type { NodeType } from "../flow/types";

@@ -115,2 +116,3 @@

const [initializer] = decl.params;
if (decl.meta[TYPE_CONST] != null) {

@@ -149,3 +151,3 @@ const validTypes = [Syntax.Constant, Syntax.StringLiteral];

error(
"Unknown type used in a declartion, " + `"${String(decl.type)}"`,
"Unknown type used in a declaration, " + `"${String(decl.type)}"`,
"Variables must be assigned with a known type.",

@@ -274,8 +276,6 @@ { start, end },

}
return [">", "<", ">=", "<=", "==", "!="].includes(expression.value)
? "i32"
: expression.type;
return expression.type;
})();
if (type !== func.type) {
if (typeWeight(type) !== typeWeight(func.type)) {
problems.push(

@@ -282,0 +282,0 @@ error(

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 too big to display

Sorry, the diff of this file is too big to display

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