|
|
last edited 16 years ago by Bill Page |
1 2 | ||
Editor: 127.0.0.1
Time: 2007/11/11 11:30:52 GMT-8 |
||
Note: transferred from axiom-developer |
changed: - On Wednesday, May 31, 2006 2:54 AM Gernot Hueber wrote: Due to that I want to call external library functions from within Aldor/Axiom I did some trials with Aldors "Foreign" and GCL "defentry" commands. First of all, an example that work (partly), adapted from the aldor users guide. The following definition needs to be compiled by lisp: \begin{lisp} (defentry |myprintf| (string) (int "printf")) \end{lisp} When this is compiled inside Axiom, the symbol |myprintf| becomes known inside the 'BOOT::' package. When we compile the Aldor code we need to include the package name. \begin{aldor} #include "axiom.as" SI ==> SingleInteger; arigato():PositiveInteger == { import { BOOT_:_:myprintf: (String) -> SI } from Foreign C; import from SI; BOOT_:_:myprintf("Arigato gozaimasu!"); 1; } \end{aldor} Now call it: \begin{axiom} arigato() \end{axiom} Here is a slightly more interesting example that compiles some C language code and calls it from Aldor. Note: clines is a GCL-specific extension \begin{lisp} (clines " /* * nputs.c: A simple C function. */ void nputs(int n, char *s) { int i; for (i = 0; i < n; i++) puts(s); } ") (defentry |nputs| (int string) (void "nputs")) \end{lisp} \begin{aldor} #include "axiom.as" SI ==> SingleInteger; arigato2():PositiveInteger == { import { BOOT_:_:nputs: (SI, String) -> SI } from Foreign C; import from SI; BOOT_:_:nputs(3,"Arigato gozaimasu!"); 1; } \end{aldor} Now try it: \begin{axiom} arigato2() \end{axiom}
Due to that I want to call external library functions from within Aldor/Axiom I did some trials with Aldors "Foreign" and GCL "defentry" commands.
First of all, an example that work (partly), adapted from the aldor users guide.
The following definition needs to be compiled by lisp:
lisp(defentry |myprintf| (string) (int "printf"))
>> System error: (SYSTEM "gcc -c -Wall -DVOL=volatile -fsigned-char -pipe -I/usr/local/lib/gcl-2.6.8/unixport/../h -O3 -fomit-frame-pointer -c \"/var/zope2/var/LatexWiki/8624266922497102717-25px001.c\" -o \"/var/zope2/var/LatexWiki/8624266922497102717-25px001.o\" -w") returned a non-zero value 0.
When this is compiled inside Axiom, the symbol |myprintf|
becomes known inside the BOOT::
package. When we compile
the Aldor code we need to include the package name.
aldor#include "axiom.as" SI ==> SingleInteger; arigato():PositiveInteger == { import { BOOT_:_:myprintf: (String) -> SI } from Foreign C; import from SI; BOOT_:_:myprintf("Arigato gozaimasu!"); 1; }
Compiling FriCAS source code from file /var/zope2/var/LatexWiki/6328445021691863648-25px002.as using AXIOM-XL compiler and options -O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra Use the system command )set compiler args to change these options. #1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL' Compiling Lisp source code from file ./6328445021691863648-25px002.lsp Issuing )library command for 6328445021691863648-25px002 Reading /var/zope2/var/LatexWiki/6328445021691863648-25px002.asy
Now call it:
axiomarigato() >> System error: |myprintf| is invalid as a function.
Here is a slightly more interesting example that compiles some C language code and calls it from Aldor. Note: clines is a GCL-specific extension
lisp(clines " /* * nputs.c: A simple C function. */ void nputs(int n, char *s) { int i; for (i = 0; i < n; i++) puts(s); } ") (defentry |nputs| (int string) (void "nputs"))
Value = 416
aldor#include "axiom.as" SI ==> SingleInteger; arigato2():PositiveInteger == { import { BOOT_:_:nputs: (SI, String) -> SI } from Foreign C; import from SI; BOOT_:_:nputs(3,"Arigato gozaimasu!"); 1; }
Compiling FriCAS source code from file /var/zope2/var/LatexWiki/4532111654619318497-25px005.as using AXIOM-XL compiler and options -O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra Use the system command )set compiler args to change these options. #1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL' Compiling Lisp source code from file ./4532111654619318497-25px005.lsp Issuing )library command for 4532111654619318497-25px005 Reading /var/zope2/var/LatexWiki/4532111654619318497-25px005.asy
Now try it:
axiomarigato2() Arigato gozaimasu! Arigato gozaimasu! Arigato gozaimasu!
(1) |