Skip to main content Accessibility help
×
Hostname: page-component-77c89778f8-n9wrp Total loading time: 0 Render date: 2024-07-20T22:33:28.762Z Has data issue: false hasContentIssue false

7 - Interfacing with Spark

Published online by Cambridge University Press:  05 October 2015

John W. McCormick
Affiliation:
University of Northern Iowa
Peter C. Chapin
Affiliation:
Vermont Technical College
Get access

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
Publisher: Cambridge University Press
Print publication year: 2015

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×