Commit 6106da45 by kollo

update manual (CALL) description of the parameter types and linktest.bas

parent 2aa1489c
......@@ -50,16 +50,27 @@ DESCRIPTION:
If you want to specify other types, please use prefixes:
----*
D: -- double (8-Bytes)
F: -- float (4-Bytes)
L: -- long int, pointer (4-Bytes)
D: -- double (8 bytes)
F: -- float (4 bytes)
L: -- integer (4 bytes)
R: -- long integer (8 bytes)
W: -- short integer (2 bytes)
B: -- byte (1 byte)
P: -- pointer (4 bytes or 8 bytes, depending on the OS)
*----
COMMENT:
The Option P: behaves the same as L: on 32bit operating systems. But you
should use P: for pointers (VARPTR() etc...) into memory so that it can
be translated from X11-Basic internal 32bit representation to the 64bit
adresses on 64it operating systems.
The B: and W: options behave the same as the L: option.
EXAMPLE:
DIM result(100)
LINK #1,"simlib.so"
adr%=SYM_ADR(#1,"CalcZeta")
ret%=CALL(adr%,D:1.2,L:0,L:VARPTR(result(0)))
ret%=CALL(adr%,D:1.2,L:0,P:VARPTR(result(0)))
UNLINK #1
SEE ALSO: CALL, EXEC
......
......@@ -639,8 +639,8 @@ IF NOT EXIST("./trackit.so")
SYSTEM "gcc -O3 -shared -o trackit.so trackit.c"
ENDIF
LINK #11,"./trackit.so"
~EXEC(SYM_ADR(#11,"binit"),L:n,L:200,L:VARPTR(x(0)), \
L:VARPTR(bins(0)))
~CALL(SYM_ADR(#11,"binit"),L:n,L:200,P:VARPTR(x(0)), \
P:VARPTR(bins(0)))
\end{verbatim}
\end{mdframed}
......@@ -679,30 +679,47 @@ UNLINK #11
\end{verbatim}
\end{mdframed}
X11-Basic currently allows only a float (double) type for the return value.
This is currently a limitation for the use of the standard libraries. If you
have written the library function yourself, you could bypass this limitation by
passing pointers to variables.
X11-Basic currently allows only an integer (int) type for the return value. This is
currently a limitation for the use of the standard libraries. If you have written the
library function yourself, you could bypass this limitation by passing a pointer to the
return variable.\footnote{If the called function returns a struct value, it expects a
pointer to a memory area where to store the return value as a first parameter (pointer).
Unfortunately, depending on the compiler and operating system, this pointer is sometimes
expected to be internally copied to and from the stack, so there is no possibility at the
moment to use this way of returning structs with X11-Basic.}
The following parameter types are possible:
\begin{center}
\begin{tabular}{|c|c|}
\hline
L: & 32-bits integers and pointers (long) (\%) \\
W: & 16-bits signed (short) \\
D: & 64-bit float (double) \\
L: & 32-bit integer (int) (\%) \\
W: & 16-bit signed (short) \\
B: & 8-bits signed (char) \\
F: & 8 byte float (double) \\
S: & 4 byte float (float) \\
F: & 4 byte float (float) \\
R: & 8 byte long integer (long long) \\
P: & 4 or 8 byte pointer (void *) \\
\hline
\end{tabular}
\end{center}
%It is also possible to pass a struct to a C function. In this case you need to assemble
%the data block for the struct in memory within the X11-Basic program, e.g. in a string,
%and then pass several integer parameters each containing 4 bytes of the data.
The Option P: behaves the same as L: on 32bit operating systems. But you
should use P: for pointers (VARPTR() etc...) into memory so that it can
be translated from X11-Basic internal 32bit representation to the 64bit
adresses on 64it operating systems.
The B: and W: options behave the same as the L: option.
The \verb|SYM_ADR| function determines the address of the function from its name.
The spelling of the function name must therefore be identical to the spelling
of the function in the \verb|.so|.
When passing the address of the string, a null byte must be added to the
When passing the address of a string, a null byte must be added to the
end of the string.
......@@ -746,9 +763,9 @@ FREE ptr%
\subsection{Shared memory}
Memory which has been allocated with \verb|MALLOC()| can only be accessed from within a
single process. If you want two different X11-Basic instances or in general two doifferent
single process. If you want two different X11-Basic instances or in general two different
running X11-Basic programs access the same memory (e.g. to share data or to communicate
with each other), you need to use shared memeory instead.
with each other), you need to use shared memory instead.
The shared memory segment needs to be created and allocated first. This should be done
only by one of the programs. The creator will also select a key (which is just an integer
......
......@@ -7,7 +7,7 @@ IF EXIST(t$)
LINK #1,t$
DUMP "#"
promt$=">>>"
adr%=CALL(SYM_ADR(#1,"readline"),L:VARPTR(promt$))
adr%=CALL(SYM_ADR(#1,"readline"),P:VARPTR(promt$))
r=adr%
WHILE PEEK(r)>0
PRINT CHR$(PEEK(r));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment