home *** CD-ROM | disk | FTP | other *** search
- $ ! Demo of FORTRAN 77 calling Ada
- $ ! Environment: DEC VAX 11/785, DEC FORTRAN-77, DEC Ada
- $ ! the FORTRAN mainline:
- $ type formain.for
-
- call adapr1
- i = 2
- call adapr2(i)
- x = 20.0
- call adapr3(x)
- j = iadapr4(0)
- print *, 'The value of J is ', j
- print *, 'The old value of X is ', x
- call adapr5(x)
- print *, 'The new value of X is ', x
-
- end
- $ ! the Ada subprograms:
- $ type adapr.ada
-
- WITH text_io;
- PACKAGE io_support is
- PACKAGE int_io IS NEW text_io.integer_io(integer);
- PACKAGE fl_io IS NEW text_io.float_io(float);
- END io_support;
-
- WITH text_io;
- PROCEDURE adapr1 IS
- BEGIN
- text_io.put ("This was printed by ADAPR1");
- text_io.new_line;
- END adapr1;
- PRAGMA export_procedure (adapr1);
-
- WITH io_support, text_io; USE io_support;
- PROCEDURE adapr2 (value : integer) IS
- BEGIN
- text_io.put ("Integer value from ADAPR2 IS ");
- int_io.put (value,8);
- text_io.new_line;
- END adapr2;
- PRAGMA export_procedure (adapr2);
-
- WITH io_support, text_io; USE io_support;
- PROCEDURE adapr3 (value : float) IS
- BEGIN
- text_io.put ("Float value from ADAPR3 IS ");
- fl_io.put (value,8,4);
- text_io.new_line;
- END adapr3;
- PRAGMA export_procedure (adapr3, parameter_types => (float));
-
- FUNCTION iadapr4 (value : integer) RETURN integer IS
- BEGIN
- RETURN 10;
- END iadapr4;
- PRAGMA export_function (iadapr4, parameter_types => (integer),
- result_type => integer);
-
- PROCEDURE adapr5 (value : IN OUT float) IS
- BEGIN
- value := value * 2.0;
- END adapr5;
- PRAGMA export_procedure (adapr5, parameter_types => (float));
-
-
-
- $ ! compile the FORTRAN source and Ada source:
- $ fortran formain
- $ ada adapr
- $ ! link, and generate ADAPR1.EXE
- $ ! note that I specify the Ada routines by name in the LINK
- $ acs link/nomain adapr1,adapr2,adapr3,iadapr4,adapr5 formain.obj
- Invoking the VAX/VMS Linker
- $ ! now to run it
- $ run adapr1
- This was printed by ADAPR1
- Integer value from ADAPR2 IS 2
- Float value from ADAPR3 IS 2.0000E+01
- The value of J is 10
- The old value of X is 20.00000
- The new value of X is 40.00000
- $ ! notes: re VAX Ada Language Reference Manual, Field Test Draft, Oct 84
- $ ! section 13.9 (Interface to Other Languages)
- $ ! pragmas provided are:
- $ ! INTERFACE
- $ ! IMPORT_PROCEDURE, EXPORT_PROCEDURE
- $ ! IMPORT_FUNCTION, EXPORT_FUNCTION
- $ ! IMPORT_VALUED_PROCEDURE
- $ ! IMPORT_OBJECT, EXPORT_OBJECT
- $ ! IMPORT_EXCEPTION, EXPORT_EXCEPTION
- $ ! parameters may be passed by VALUE, REFERENCE, or DESCRIPTOR
-