Skip to content

Commit

Permalink
initialize haskell plugins properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-azeez committed Jun 6, 2024
1 parent 598d257 commit ea14584
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
17 changes: 8 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class Plugin {
throw Error(`Plugin error: function does not exist ${func_name}`);
}

if (func_name != '_start' && this.guestRuntime?.init && !this.guestRuntime.initialized) {
if (func_name != '_start' && !this.guestRuntime.initialized) {
this.guestRuntime.init();
this.guestRuntime.initialized = true;
}
Expand Down Expand Up @@ -618,18 +618,17 @@ function haskellRuntime(module: WebAssembly.Instance): GuestRuntime | null {

const reactorInit = module.exports._initialize;

let init: () => void;
if (reactorInit) {
//@ts-ignore
init = () => reactorInit();
} else {
let init = () => {
if (reactorInit) {
//@ts-ignore
reactorInit();
}

//@ts-ignore
init = () => haskellInit();
haskellInit();
}

const kind = reactorInit ? 'reactor' : 'normal';
console.debug(`Haskell (${kind}) runtime detected.`);

return { type: GuestRuntimeType.Haskell, init: init, initialized: false };
}

Expand Down
38 changes: 17 additions & 21 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,25 @@ describe('test extism', () => {
expect(() => plugin.call("run_test", "")).toThrowError(/Call error/);
});

// test('can initialize haskell runtime', async () => {
// console.trace = jest.fn();

// const plugin = await newPlugin('hello_haskell.wasm', options => {
// options.config = {
// "greeting": "Howdy"
// };
// });

// {
// const output = await plugin.call("testing", "John");
// const result = output;
test('can initialize haskell runtime', async () => {
const plugin = await newPlugin('haskell.wasm', options => {
options.config = {
"greeting": "Howdy"
};
});

// expect(result).toBe("Howdy, John")
// }
{
const output = await plugin.call("greet", "John");
const result = output?.text();

// {
// const output = await plugin.call("testing", "Ben");
// const result = output;
expect(result).toBe("Howdy, John")
}

// expect(result).toBe("Howdy, Ben")
// }
{
const output = await plugin.call("greet", "Ben");
const result = output?.text();

// expect(console.debug).toHaveBeenCalledWith("Haskell (normal) runtime detected.");
// });
expect(result).toBe("Howdy, Ben")
}
});
});
Binary file added wasm/haskell.wasm
Binary file not shown.
Binary file removed wasm/hello_haskell.wasm
Binary file not shown.

0 comments on commit ea14584

Please sign in to comment.