Hello Qian,

I only did a quick test but no, not successfully, your test.core
is unusable. Use the key ":executable t" when the core image is dumped to
check this with ./test.core. I have no idea why the :callable-exports is
causing this.

So even without your test.c file you see that the image is useless as it
is. I guess you noticed it.

Greg

Le jeu. 26 sept. 2024 à 13:47, Qian Yun <[email protected]> a écrit :

> I was mistaken, I did not successfully call Lisp function
> from C side.
>
> I wonder if you can do this successfully:
>
> 1. put SBCL source code to $SRC
> 2. build SBCL and libsbcl.so:
>    cd $SRC
>    ./make.sh
>    ./make-shared-library.sh
> 3. dump a Lisp core:
> ==== test.lisp ====
> (sb-alien:define-alien-callable fun1 sb-alien:int () 2)
> (sb-ext:save-lisp-and-die "test.core" :callable-exports '(fun1))
> ==== end test.lisp ====
>
>    $SRC/run-sbcl.sh --load test.lisp
>
> 4. build a C executable:
> ==== test.c ====
> #include <stdio.h>
>
> extern int initialize_lisp(int argc, char *argv[], char *envp[]);
>
> int main(int argc, char *argv[], char *envp[]){
>
>    int sargc=4;
>    char * sargv[] = {argv[0], "--core", "test.core", "--no-sysinit", };
>    printf("start init\n");
>    initialize_lisp(sargc, sargv, envp);
>
>    printf("finish init\n");
>    return 0;
> }
> ==== end test.c ====
>
>    cc test.c $SRC/runtime/libsbcl.so -o app
>
> 5. execute the "./app" and you get error in
> "foreign function: call_into_lisp_".
>
> Looks like the error is because it can't initialize the foreign
> function correctly.
>
> - Qian
>
> On 9/24/24 9:51 PM, Qian Yun wrote:
> > One of the goals of FriCAS is:
> >    make it easier for external programs to interface with FriCAS
> >
> > Currently we have SageMath and jfricas to interface with FriCAS,
> > SageMath is using pexpect which is like terminal IO,
> > while jfricas is using hunchentoot which is IO via HTTP.
> >
> > I think a C interface would be most performant, and convenient for
> > some use cases.
> >
> > The disadvantage would be that for different Lisp, it needs different
> > code for the C interface.
> >
> > (SageMath has a C interface for Maxima with ECL.)
> >
> > Since SBCL has the best performance, I'd like to try to write
> > a C interface for it first.
> >
> > This needs SBCL >= 2.1.11, and "libsbcl.so" built by
> > "make-shared-library.sh" in the sbcl repo.
> >
> > I can call Lisp function from C now, but I have not called/exported
> > FriCAS functions yet.  I'll keep you posted.
> >
> > - Qian
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/fricas-devel/6e3d477d-71e7-4980-b561-9409ec9f1ccd%40gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAHnU2dapnodiVOgbqbLc-9Zct9%2B3M%2BGFriU88HZ02wUbwDY8Yg%40mail.gmail.com.

Reply via email to