Skip to content

Commit

Permalink
fix: styling
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed Feb 25, 2019
1 parent 2310334 commit 8875cf1
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bench:
$(NODE) $(NODE_OPTS) ./benchmark

fix:
$(PRETTIER) --write "{packages,docs,benchmark}/**/*.js" "**/*.tjs"
$(PRETTIER) --write "{packages,docs,benchmark}/**/*.js"

flow-update-def:
$(FLOWTYPED) install --libdefDir src/types
14 changes: 4 additions & 10 deletions packages/helper-compiler/src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,13 @@ export const kStart = Symbol("_start");
declare function LABEL_POP(): void;
declare function LABEL_PUSH(n: Node): void;

define(
LABEL_POP,
() => `
define(LABEL_POP, () => `
this._labels.pop();
`
);
`);

define(
LABEL_PUSH,
node => `
define(LABEL_PUSH, node => `
this._labels.push(${node});
`
);
`);

/**
* ModuleContext
Expand Down
2 changes: 1 addition & 1 deletion packages/leb128/test/original-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ function testLossy64() {
const bit = i == 0 || i == bitCount - 1 ? 1 : rand.nextBit();
const at = offset + i;
if (bit) {
buf[Math.floor(at / 8)] |= 1 << (at % 8);
buf[Math.floor(at / 8)] |= 1 << at % 8;
}
}

Expand Down
9 changes: 3 additions & 6 deletions packages/wasm-edit/src/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ import { define } from "mamacro";

declare function CHECK_END(body: Array<Object>): void;

define(
CHECK_END,
body => `
define(CHECK_END, body => `
const body = ${body};
if (body.length === 0 || body[body.length - 1].id !== "end") {
throw new Error("expressions must be ended");
}
`
);
`);

type State = {
uint8Buffer: Uint8Array,
Expand Down Expand Up @@ -154,7 +151,7 @@ function applyDelete(ast: Program, uint8Buffer: Uint8Array, node: Node): State {
*/
uint8Buffer = removeSections(ast, uint8Buffer, "start");

const deltaBytes = -(sectionMetadata.size.value + 1) /* section id */;
const deltaBytes = -(sectionMetadata.size.value + 1); /* section id */

return { uint8Buffer, deltaBytes, deltaElements };
}
Expand Down
7 changes: 2 additions & 5 deletions packages/wasm-parser/src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { define } from "mamacro";

declare function WITH_LOC<T>(n: T, startLoc: Position): T;

define(
WITH_LOC,
(node, startLoc) => `
define(WITH_LOC, (node, startLoc) => `
(function() {
const endLoc = getPosition();
Expand All @@ -20,8 +18,7 @@ define(
${startLoc}
);
})()
`
);
`);

import {
decodeInt32,
Expand Down
7 changes: 2 additions & 5 deletions packages/wast-parser/src/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ import { tokens, keywords } from "./tokenizer";

declare function createUnexpectedToken(msg: string): void;

define(
createUnexpectedToken,
msg => `return new Error(
define(createUnexpectedToken, msg => `return new Error(
"\n" +
codeFrameFromSource(source, token.loc) + "\n"
+ ${msg} + ", given " + tokenToString(token)
);`
);
);`);

type AllArgs = {
args: Array<Expression>,
Expand Down
7 changes: 2 additions & 5 deletions packages/wast-parser/src/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ declare function unexpectedCharacter(): void;
/**
* Throw an error in case the current character is invalid
*/
define(
unexpectedCharacter,
() =>
`throw new Error(getCodeFrame(input, line, column) + "Unexpected character " + JSON.stringify(char));`
);
define(unexpectedCharacter, () =>
`throw new Error(getCodeFrame(input, line, column) + "Unexpected character " + JSON.stringify(char));`);

// eslint-disable-next-line
function getCodeFrame(source: string, line: number, column: number) {
Expand Down
12 changes: 5 additions & 7 deletions packages/webassemblyjs/src/interpreter/host-func.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ const { executeStackFrame } = require("./kernel/exec");
const { createStackFrame } = require("./kernel/stackframe");
const { ExecutionHasBeenTrapped } = require("./kernel/signals");

define(
trace,
msg => `
define(trace, msg => `
console.log("host " + ${msg});
`
);
`);

export function createHostfunc(
ir: IR,
Expand Down Expand Up @@ -87,8 +84,9 @@ export function createHostfunc(
);
}

const argsWithType = args.map((value: any, i: number): StackLocal =>
castIntoStackLocalOfType(funcinstArgs[i], value)
const argsWithType = args.map(
(value: any, i: number): StackLocal =>
castIntoStackLocalOfType(funcinstArgs[i], value)
);

const stackFrame = createStackFrame(
Expand Down
49 changes: 14 additions & 35 deletions packages/webassemblyjs/src/interpreter/kernel/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,19 @@ declare function POP_STACK_FRAME(): void;
declare function POP_LABEL(): void;
declare function assertNItemsOnStack(n: number): void;

define(
assertNItemsOnStack,
n => `
define(assertNItemsOnStack, n => `
if (frame.values.length < ${n}) {
throw new RuntimeError(
"Assertion error: expected " + JSON.stringify(${n})
+ " on the stack, found " + frame.values.length
);
}`
);
}`);

define(
trace,
msg => `
define(trace, msg => `
console.log("trace " + ${msg});
`
);
`);

define(
POP_LABEL,
() => `
define(POP_LABEL, () => `
// 3. Assert: due to validation, the label L is now on the top of the stack.
// 4. Pop the label from the stack.
let found = false;
Expand All @@ -51,32 +43,23 @@ define(
frame.values.splice(initialOrderIndex, 1);
}
`
);
`);

define(
GOTO,
labelOffset => `
define(GOTO, labelOffset => `
pc = offsets.indexOf(String(${labelOffset}));
`
);
`);

define(
RETURN,
() => `
define(RETURN, () => `
const activeFrame = getActiveStackFrame();
if (activeFrame.values.length > 0) {
return pop1(activeFrame);
} else {
return;
}
`
);
`);

define(
PUSH_NEW_STACK_FRAME,
pc => `
define(PUSH_NEW_STACK_FRAME, pc => `
const stackframe = require("./stackframe");
const activeFrame = getActiveStackFrame();
Expand All @@ -91,12 +74,9 @@ define(
// Push the frame on top of the stack
callStack[framepointer] = newStackFrame;
`
);
`);

define(
POP_STACK_FRAME,
() => `
define(POP_STACK_FRAME, () => `
const activeFrame = getActiveStackFrame();
// pass the result of the previous call into the new active fame
Expand All @@ -115,8 +95,7 @@ define(
if (res !== undefined && newStackFrame !== undefined) {
pushResult(newStackFrame, res);
}
`
);
`);

const {
binopi32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class f64nan extends f64 {

// 52-bit mantissa which is obtained by disregarding the sign of _value
const mantissa = this._value <= 0 ? -this._value : this._value;
lower = lower | (mantissa % 2 ** 32);
lower = lower | mantissa % 2 ** 32;
upper = upper | Math.floor(mantissa / 2 ** 32);

return new i64(Long.fromBits(lower, upper));
Expand Down
7 changes: 2 additions & 5 deletions packages/webassemblyjs/src/interpreter/runtime/values/i64.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import { i32, createTrue, createFalse } from "./i32";
import { define, assert } from "mamacro";

declare function ASSERT_NOT_ZERO(x: any): void;
define(
ASSERT_NOT_ZERO,
x => `{
define(ASSERT_NOT_ZERO, x => `{
if (${x}._value.isZero()) {
throw new RuntimeError("integer divide by zero");
}
}`
);
}`);

declare function TO_BOOLEAN(cond: any): i32;
define(TO_BOOLEAN, cond => `(${cond}) ? createTrue() : createFalse()`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { RuntimeError } = require("../../../errors");

const WEBASSEMBLY_PAGE_SIZE = 64 * 1024 /* 64KiB */;
const WEBASSEMBLY_PAGE_SIZE = 64 * 1024; /* 64KiB */

export class Memory implements MemoryInstance {
_initialBytes: number;
Expand Down

0 comments on commit 8875cf1

Please sign in to comment.