[Next] [Previous] [Up] [Top] [Contents] [Index]

2.2 Methods

2.2.3 Primitive Methods

prim_body	::=	"prim" { language_binding }
language_binding	::=	language ":" code_string
	|	language "{" code_chars "}"
language	::=	name
code_string	::=	string
code_chars	::=	brace_balanced_chars	any characters, with balanced use of "{" and "}"

Low-level operations, such as integer arithmetic, vector indexing, looping, and file I/O, are implemented through the use of primitive methods. A primitive method's body is a list of (language name, implementation source code) pairs. The details of the protocol for writing code in another language inside a Cecil primitive method are implementation-specific. The UW Cecil implementation recognizes the c_++ and rtl language names, for primitives written in C++ and the compiler's internal intermediate language, respectively. It is fairly straightforward to make calls to routines written in C++ from Cecil by defining a primitive method whose body is written in C++.

Looping primitive behavior is provided by the loop primitive method specialized on the closure predefined object. This method repeatedly invokes its argument closure until some closure performs a non-local return to break out of the loop. Other languages such as Scheme [Rees & Clinger 86] avoid the need for such a primitive by relying instead on user-level tail recursion and implementation-provided tail-recursion elimination. However, tail-recursion elimination precludes complete source-level debugging [Chambers 92a, Hölzle et al. 92] and consequently is undesirable in general. The primitive loop method may be viewed as a simple tail-recursive method for which the implementation has been instructed to perform tail-recursion elimination.

A primitive body may be included at the top-level using a primitive body declaration:

prim_decl	::=	prim_body ";"

This construct allows code from other languages to be included outside of any compiled routines. Primitive declarations can be used to include global declarations used by primitive methods. Again, the detailed semantics of this construct are implementation-specific.