Skip to content

Commit

Permalink
update deno
Browse files Browse the repository at this point in the history
  • Loading branch information
yoav-lavi committed Jun 25, 2022
1 parent f030b2a commit ebfc2c5
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 79 deletions.
126 changes: 73 additions & 53 deletions integrations/deno/melody_wasm.d.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
/* tslint:disable */
/* eslint-disable */
/**
*
*Compiles Melody source code to a regular expression
*
*# Errors
*
*Throws an error if a compilation error is encountered
*
*# Example
*
*```js
*const source = `
* <start>;
*
* option of "v";
*
* capture major {
* some of <digit>;
* }
*
* ".";
*
* capture minor {
* some of <digit>;
* }
*
* ".";
*
* capture patch {
* some of <digit>;
* }
*
* <end>;
*`;
*
*try {
* const output = compiler(source);
* new RegExp(output).test("v1.1.1"); // true
*} catch (error) {
* // handle compilation error
*}
*```
* @param {string} source
* @returns {string}
*/
*
*Compiles Melody source code to a regular expression
*
*# Errors
*
*Throws an error if a compilation error is encountered
*
*# Example
*
*```js
*import init, { compiler } from "https://deno.land/x/melody/melody_wasm.js";
*
*await init();
*
*const source = `
* <start>;
*
* option of "v";
*
* capture major {
* some of <digit>;
* }
*
* ".";
*
* capture minor {
* some of <digit>;
* }
*
* ".";
*
* capture patch {
* some of <digit>;
* }
*
* <end>;
*`;
*
*try {
* const output = compiler(source);
* new RegExp(output).test("v1.1.1"); // true
*} catch (error) {
* // handle compilation error
*}
*```
* @param {string} source
* @returns {string}
*/
export function compiler(source: string): string;

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export type InitInput =
| RequestInfo
| URL
| Response
| BufferSource
| WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
Expand All @@ -59,11 +68,22 @@ export interface InitOutput {
}

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
* Synchronously compiles the given `bytes` and instantiates the WebAssembly module.
*
* @param {BufferSource} bytes
*
* @returns {InitOutput}
*/
export function initSync(bytes: BufferSource): InitOutput;

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init(
module_or_path?: InitInput | Promise<InitInput>
): Promise<InitOutput>;
70 changes: 44 additions & 26 deletions integrations/deno/melody_wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ const cachedTextDecoder = new TextDecoder("utf-8", {

cachedTextDecoder.decode();

let cachegetUint8Memory0 = null;
let cachedUint8Memory0;
function getUint8Memory0() {
if (
cachegetUint8Memory0 === null ||
cachegetUint8Memory0.buffer !== wasm.memory.buffer
) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
if (cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
return cachedUint8Memory0;
}

function getStringFromWasm0(ptr, len) {
Expand Down Expand Up @@ -94,15 +91,12 @@ function passStringToWasm0(arg, malloc, realloc) {
return ptr;
}

let cachegetInt32Memory0 = null;
let cachedInt32Memory0;
function getInt32Memory0() {
if (
cachegetInt32Memory0 === null ||
cachegetInt32Memory0.buffer !== wasm.memory.buffer
) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
if (cachedInt32Memory0.byteLength === 0) {
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
return cachedInt32Memory0;
}

function getObject(idx) {
Expand Down Expand Up @@ -131,10 +125,6 @@ function takeObject(idx) {
*# Example
*
*```js
*import init, { compiler } from "https://deno.land/x/melody/melody_wasm.js";
*
*await init();
*
*const source = `
* <start>;
*
Expand Down Expand Up @@ -227,17 +217,45 @@ async function load(module, imports) {
}
}

async function init(input) {
if (typeof input === "undefined") {
input = new URL("melody_wasm_bg.wasm", import.meta.url);
}
function getImports() {
const imports = {};
imports.wbg = {};
imports.wbg.__wbindgen_error_new = function (arg0, arg1) {
const ret = new Error(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};

return imports;
}

function initMemory(imports, maybe_memory) {}

function finalizeInit(instance, module) {
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);

return wasm;
}

function initSync(bytes) {
const imports = getImports();

initMemory(imports);

const module = new WebAssembly.Module(bytes);
const instance = new WebAssembly.Instance(module, imports);

return finalizeInit(instance, module);
}

async function init(input) {
if (typeof input === "undefined") {
input = new URL("melody_wasm_bg.wasm", import.meta.url);
}
const imports = getImports();

if (
typeof input === "string" ||
(typeof Request === "function" && input instanceof Request) ||
Expand All @@ -246,12 +264,12 @@ async function init(input) {
input = fetch(input);
}

const { instance, module } = await load(await input, imports);
initMemory(imports);

wasm = instance.exports;
init.__wbindgen_wasm_module = module;
const { instance, module } = await load(await input, imports);

return wasm;
return finalizeInit(instance, module);
}

export { initSync };
export default init;
Binary file modified integrations/deno/melody_wasm_bg.wasm
Binary file not shown.

0 comments on commit ebfc2c5

Please sign in to comment.