Next: Embedding XASM-programs in C-applications
Up: The XASM External Language
Previous: The XASM External Language
In the previous section we have shown, that external function can be
specified in XASM using the asm construct. Alternatively,
external functions can be implemented in C. The corresponding
XASM-declaration is given as follows:
The c_name specifies the name of the C function; it can be omitted,
if it is equal to the XASM-name of the function. Depending on the
access mode of the XASM-function, the corresponding C-function
prototypes differ slightly:
- If the access mode is ``monitored'', the C-functions are
defined as follows:
- ASMOBJ c_name(ASM a, int argc, ASMOBJ* argv);
where ``ASMOBJ'' is the C-type representing elements of the
superuniverse; ``ASM'' is a C-struct containing information related to
parent asm. These types are specified in the header file
``xasm.h'' which must be included in those files containing external
function implementations. The arguments of the function call can be
accessed via the ``argv'' field using ``argc'' as argument count. The
first argument, argv[0], always contains the name of the corresponding
XASM-function as string element. The result of the external function
that is accessible in the calling asm is returned by the
C-function as ``ASMOBJ''.
- If the access mode is ``output'', the C-functions are
defined as follows:
- void cname(ASM a, int argc, ASMOBJ* argv, ASMOBJ val);
In this case, additionally the value that is used in the update
representing the call of the external function can be accessed using
the ``val'' parameter.
As an example, the following C-code contains the implementation of the
``stderr'' function previously used in one of the examples:
The XASM-library function ``str_obj'' returns the string
representation of an ASMOBJ. The corresponding declaration of the
external C-function in an asm has the following format:
Next: Embedding XASM-programs in C-applications
Up: The XASM External Language
Previous: The XASM External Language
Philipp Kutter
2002-03-18