PHILLIP GEORGE REISER <pgr94@aber.ac.uk> writes:
> Date: Thu, 04 Apr 1996 16:21:43 +0100
> Organization: University of Wales - Aberystwyth - Prifysgol Cymru
>
> Dear all,
>
> I am currently calling some C functions from within Pop-11. This has
> worked fine, but I now need to pass more complex data structures. I
> would be really grateful if somebody could point me to some code that
> achieves this.
>
> (More specifically, I need to pass a pointer to a record, where one
> field is a pointer to a string.)
There is relevant information, including various examples, scattered
around the online Poplog documentation files:
HELP EXTERNAL
Gives an overview of external facilities and information about
other relevant documentation
HELP NEWC_DEC
Details of "higher level" facilities for declaring C datatypes,
structures and functions. Probably not as relevant as
shadowclass, below.
REF DEFSTRUCT
Pop-11 syntax for defining and accessing both Poplog and external
structures. Includes examples of construction of records
containing Pop-11 data structurs for passing to external
procedures.
REF SHADOWCLASS
Describes a utility designed to bridge the gap between ordinary
Poplog record and vectorclasses and external class
specifications. Ends with some examples. Here are some examples
that Roger Evans once provided:
create a pointer to a structure f including a 4 byte string
and two ints:
shadowclass short_string :byte[4];
shadowclass fooptr { a:int, b:int, c:short_string };
vars ss = consshort_string(#| `a`, `b`, `c`, `d` |#);
vars f = consfooptr(1,2,ss);
or for two way traffic:
p_typespec short_string :byte[4];
;;; create special purpose destroy/construct proc for short_string
define dest_short_string(s);
deststring(s) ->; ;;; don't want count
enddefine;
define updaterof dest_short_string();
consstring(4);
enddefine;
;;; register it with shadowclass
dest_short_string -> shadow_construct(TYPESPEC(:short_string));
shadowclass fooptr { a:int, b:int, c:short_string };
vars f = consfooptr(1,2,'abcd');
Now shadowclass will expect and return 4 element strings for the field c
The REF file shows how to use non-constructive mechanisms to avoid
repeated creation of new structures, reducing garbage collection.
REF EXTERNAL
The complete guide to the Poplog/External-procedure raw interface
mechanism, in conjunction with the following two files:
REF EXTERNAL_DATA
Using external data structures in Poplog, and Poplog data externally
REF INTVEC
Has an example involving passing a Ppo-11 intvec to C
The following extract from REF STRINGS is relevant:
(N.B. Like all byte vectorclasses, strings are guaranteed to be
null-terminated, that is, to have a 0 byte following the last
actual byte of the string. While this is irrelevant to internal
Poplog use, it means that strings can be passed to external C
functions without modification.)
I can't give you concrete examples as I don't use these facilities,
but if you browse in the Poplog X interface directory tree you will
probably find hundreds. Inside VED you can use "dired" to browse.
Try
ENTER dired $usepop/pop/x/pop/lib
That provides a VED buffer showing all the files and subdirectories.
You can then move the VED cursor to a file or directory you wish to
examine and repeat the dired command. (See HELP DIRED for
information about other options.)
Those files use various macros and other declarations in the *.ph
files in
ENTER dired $usepop/pop/x/pop/include
In particular the file lib/xpt_general.p includes a lot of examples
of shadowclass declarations, which in turn use declarations from
include/xpt_coretypes.ph
include/xpt_generaltypes.ph
Another directory to look in is the source directory for Xved
ENTER dired $usepop/pop/x/ved/src
(Sometimes source examples can give more up to date information than
the online documentation.)
If anyone has some nice simple examples of communication between
Pop-11 and C I would like to include them in the next edition of the
Pop-11 primer. (Second edition currently available {free of charge} in
various formats from our poplog ftp directory
ftp://ftp.cs.bham.ac.uk/pub/dist/poplog/
see the README file.)
Aaron
--
Aaron Sloman, ( http://www.cs.bham.ac.uk/~axs )
School of Computer Science, The University of Birmingham, B15 2TT, England
EMAIL A.Sloman@cs.bham.ac.uk
Phone: +44-121-414-4775 (Sec 3711) Fax: +44-121-414-4281
|