7 - Interfacing with Spark
Published online by Cambridge University Press: 05 October 2015
Summary
It is often infeasible or even undesirable to write an entire program in Spark. Some portions of the program may need to be in full Ada to take advantage of Ada features that are not available in Spark such as access types and exceptions. It may be necessary for Spark programs to call third-party libraries written in Ada or some other programming language such as C. Of course Spark's assurances of correctness cannot be formally guaranteed when the execution of a program flows into the non-Spark components. However, mixing Spark and non-Spark code is of great practical importance. In this chapter we explore the issues around building programs that are only partially Spark. In Chapter 8 we look at how combining proof with testing can verify applications that are not all Spark.
Spark and Ada
In this section we discuss mixing Spark with full Ada. Calling Spark from Ada is trivial because Spark is a subset of Ada and thus appears entirely ordinary from the point of view of the full Ada compiler. Calling full Ada from Spark, however, presents more issues because the limitations of Spark require special handling at the interface between the two languages.
7.1.1 SparkMode
Conceptually each part or construct of your program is either “in Spark” or “not in Spark.” If a construct is in Spark, then it conforms to the restrictions of Spark, whereas if a construct is not in Spark, it can make use of all the features of full Ada as appropriate for the construct. It is not permitted for Spark constructs to directly reference non-Spark constructs. For example, a subprogram body that is in Spark cannot call a subprogram with a non-Spark declaration. However, as declarations and bodies are separate constructs, it is permitted for a Spark subprogram body to call a subprogram with a Spark declaration even if the body of the called subprogram is not in Spark.
It is up to you to mark the Spark constructs of your program as such by specifying their Sparkmode. This is done using the SPARK_Mode pragma or SPARK_Mode aspect as appropriate. The Spark mode can be explicitly set to either On or Off.
- Type
- Chapter
- Information
- Building High Integrity Applications with SPARK , pp. 247 - 285Publisher: Cambridge University PressPrint publication year: 2015