Image generation and load utilities
jeswr opened this issue · 3 comments
jeswr commented
This issue is simply to track this comment SWI-Prolog/swipl-devel#1108 (comment)
jeswr commented
@josd I just tried to implement a generic image generator but doing
import SWIPL, { SWIPLModule } from './swipl/swipl-bundle';
export async function generateImage(prolog: string): Promise<Uint8Array> {
const Module = await SWIPL({
arguments: ['-q', '-f', 'prolog.pl'],
// @ts-ignore
preRun: (module: SWIPLModule) => module.FS.writeFile('prolog.pl', prolog),
});
Module.prolog.query("main(['--image', 'image.pvm'])").once();
// return Module.FS.readFile('image.pvm')
return new Uint8Array()
}
async function main() {
const result = await image.generateImage(`
find_max(X, Y, X) :- X >= Y, !.
find_max(X, Y, Y) :- X < Y.
find_min(X, Y, X) :- X =< Y, !.
find_min(X, Y, Y) :- X > Y.
`);
console.log(result)
}
main();
Results in the error
wasm:wasm_call_string/3: Unknown procedure: main/1
However, there are definitions for:
main/0
Uint8Array(0) []
Which makes me think that this image generation functionality in this script is specific to eye; is that correct?
josd commented
It is indeed eye specific as you can see at https://github.com/eyereasoner/eye-js/blob/a8c288858de7d8a3bab9b47ec6c63fbacb67fddb/scripts/generate-pvm.ts#L32
and under the hood we do a standard swipl qsave_program/1.
jeswr commented
Assigning to myself as I still need to create docs for this here and in man/wasm.doc
usptream.