axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Axiom-developer] Call Foreign C from Aldor/Axiom


From: Gernot Hueber
Subject: RE: [Axiom-developer] Call Foreign C from Aldor/Axiom
Date: Fri, 02 Jun 2006 11:53:48 +0200

Hi,

On Thu, 2006-06-01 at 11:48 -0400, Page, Bill wrote:
> On Thursday, June 01, 2006 2:59 AM Gernot Hueber wrote:
> > > > ... 
> > > > Now, my questions:
> > > > .) s there a recommended/better way to call external functions
> > > > within Aldor/Axiom?
> > > > .) I think, the "defentry" part  could be added with an Aldor
> > > > "Foreign Lisp" call?
> > > > .) How can I "load", external libraries (e.g. nputs.o)?
> > > > 
> > > 
> > > See:
> > > 
> > > http://wiki.axiom-developer.org/SandBoxAldorForeign
> > > 
> > > The first section containing
> > > 
> > >   (defentry |myprintf| (string) (int "printf"))
> > > 
> > > is compiled as a lisp function but notice that it becomes
> > > part of the BOOT package.
> > 
> > Well, I don't get this point, but I have to admit, I have no
> > understanding of the BOOT package.
> >
> 
> "package" is a name space concept in common lisp. The
> package name becomes part of the full name of a symbol
> like this:
> 
>   BOOT::myprintf
> 
> BOOT is the name space used by Axiom.
> 
> When Aldor code is compiled in Axiom the symbols default to
> a different package, therefore you must use the full name to
> call myprint. In Aldor the : must be escaped by _ so it looks
> rather messy
> 
>   BOOT_:_:myprintf
> 
> Of course there might be other ways to accomplish this. Maybe
> someone more knowledgeable about lisp could help?
> 

Thanks for explaining this issue. Where/how did you place the defentry
line. It didn't work out for me with )lisp ?!

> > > 
> > > For loading an external library did you try the usual Axiom
> > > command
> > > 
> > >  )library nputs.o
> > > 
> > > Or via lisp like this:
> > > 
> > >  )lisp (load nputs.o)
> > > 
> > > ?
> > 
> > Sorry, no success: )lib nputs.o gives me ")library cannot 
> > find the file nputs.", )lisp (load nputs.o) returns
> > "<< System error: The variable NPUTS is unbound".
> 
> That's my confusion. I think what you need is (compiler::link ...)
> but that is beyond my level of competitence with GCL. Lisp
> users please help!
> 

Well, I never tried to use Lisp before using Axiom. What I found
googleing for compiler::link where examples generating a new lisp image
including addtional libs. Maybe it is possible to call functions from
this one??
My second idea was to use the dynamic loader (Linux: dlopen from libdl;
FreeBSD includes dlopen in libc), to load a missing library (converted
to from my custom object).
Actually Lisp told me, "dlopen" is not in the base image :-(
At least I expected it to be, because it is in libc.

faslink and FFI are not implemented in GCL (and/or Linux/BSD/...)


> > 
> > I am thinking of importing defentry into Aldor to define the
> > C command to Lisp. Something like
> > -------------
> > import {defentry: (??) -> ?} from Foreign Lisp;
> > 
> > -- call imported defentry to declare C command to underlying Lisp
> > defentry("printf","string","int");
> > -------------
> > Obviously the give syntax wont work. But you could move the Lisp
> > defentry into Aldor.
> >
> 
> I think you are right that Aldor should probably generate the
> defentry but foreign language interface is still not that
> standard in lisp, so what Aldor does might not be too portable.
> Since the current versiono of open source Axiom uses gcl, the
> foreign call mechanism would have to be compatible with this.
> 
> > 
> > > 
> > > Can you send me the example code for 'nputs.c'?
> > 
> > See for the full example: http://www.aldor.org/docs/HTML/chap19.html
> > ----
> > /*
> >  * nputs.c: A simple C function.
> >  */
> > void
> > nputs(int n, char *s)
> > {
> >         int     i;
> >         for (i = 0; i < n; i++) puts(s);
> > }
> > -----
> >
> 
> Although I still cannot call this routine as an external
> library routine, I was able to compile and call it from
> inside Axiom. See my extended example at:
>  
> http://wiki.axiom-developer.org/SandBoxAldorForeign
> 
Great. 

My idea of doing all that is to be able to integrate external libraries
into Axiom/Aldor. And there are plenty interesting candidates (e.g.
LAPACK, SDPA, ...)

Regards

Gernot





reply via email to

[Prev in Thread] Current Thread [Next in Thread]