Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image generation and load utilities #16

Open
jeswr opened this issue Feb 2, 2023 · 3 comments
Open

Image generation and load utilities #16

jeswr opened this issue Feb 2, 2023 · 3 comments
Assignees

Comments

@jeswr
Copy link
Collaborator

jeswr commented Feb 2, 2023

This issue is simply to track this comment SWI-Prolog/swipl-devel#1108 (comment)

@jeswr
Copy link
Collaborator Author

jeswr commented Feb 2, 2023

@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
Copy link

josd commented Feb 2, 2023

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 jeswr self-assigned this Apr 7, 2023
@jeswr
Copy link
Collaborator Author

jeswr commented Apr 7, 2023

Assigning to myself as I still need to create docs for this here and in man/wasm.doc usptream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants