[Next] [Previous] [Top]

RTL Grammar

2 Global Declarations


Declarations at the top level can appear in any order, and can be mutually recursive. Evaluation of global variable initializers is done top-down in the order given.

An object declaration introduces a new class. Abstract classes cannot be instantiated directly. The isa list names its immediate superclasses. (There is a root class implicitly defined, and all classes inherit (directly or indirectly) from this root class implicitly.) Inheritance defines a partial order on objects; redundant or transitively-implied inheritance links are ignored. In the presence of diamond-shaped multiple inheritance, shared ancestor classes are including only once in the hierarchy, as if all classes were virtual base classes in C++ terminology.

rtl_object_decl	::=	[rtl_obj_role] "object" rtl_name ["isa" rtl_names]
		    [object_id_pragma] ";"
rtl_obj_role	::=	"abstract" | "concrete"
rtl_names	::=	rtl_name {"," rtl_name}
An object_id_pragma is attached to an object_decl, and specifies the names of the symbols to use as class identifiers for that class, when it is viewed from particular static types.

object_id_pragma	::=	"(**" "ID" "(" "[" object_id_pair {"," object_id_pair } "]"
		"**)"
object_id_pair	::=	"[" static_type "," rtl_name "]"
A method declaration defines a procedure in the intermediate program.

rtl_method_decl	::= 	"method" [rtl_visibility] rtl_name "(" {rtl_formals} ")"
		  ":" representation [pragma] "{" rtl_stmts "}" [";"]
rtl_formals	::=	rtl_formal {"," rtl_formal}
Each formal has a name (can be omitted if it's not used within the body of the method), a specializer class (if omitted or if given as @any, then the argument is unspecialized), and a representation (if omitted, then it defaults to OOP). If formals_are_immutable is defined, then formal variables cannot be assigned, otherwise they can be. If uses_PIC_based_runtime is set, then only OOP formals can be specialized to something other than any. Formal parameters and results are passed by value (i.e. shallow-copied), including formals represented using bytes[n], unlike C which passes arrays by reference.

rtl_formal	::=	[rtl_name] ["@" rtl_name] [":" representation]
A method (or field or global variable declaration) can be marked private (meaning that it is scoped within the current file, as in C; static has the same meaning), or extern (meaning that it is visible to other files, as in C, and that it has been declared already in some other file).

rtl_visibility	::=	"private" | "static" | "extern"
An extern method declaration declares a method and says that its definition may be external to the part of the program that the compiler sees. It is allowable to provide an extern method declaration in one source file and the definition of the method in another source file. In this case, the actual definition of the method takes precedence over the extern declaration.

rtl_extern_method_decl	::= 	"extern" "method" rtl_name "(" {rtl_formals} ")"
		  ":" representation ";"
A field declaration declares an instance variable on a class. If var is present, the field is mutable, otherwise the field is considered immutable. The formal parameter specifies which class the instance variable is part of. If front_end_does_field_layout is set, then field declarations are unnecessary, and only low-level object allocation (with precomputed size) and pointer load & store operations are supported, otherwise field declarations should be provided and high-level object allocation operations and field load and store operations are provided. If generate_field_accessors is set, then a field declaration implicitly generates a get accessor method (and a set accessor method, if mutable).

rtl_field_decl	::= 	["var"] "field" [rtl_visibility] rtl_name
		  "(" rtl_formal ")" ":" representation [pragma]
		  [":=" literal] ";"
A global variable declaration introduces a variable in the global (current) scope, with the given visibility and representation. Variables (global and local) are assumed to be assignable.

rtl_var_decl	::=	"decl" [rtl_visibility] representation rtl_name 
		  [":=" (literal | static_init)] ";"
A static initializer provides the mechanism for specifying the static initial value of a global variable whose representation is an array of bytes. It provides a sequence of initializers, each of which specifies an offset, a representation, and an initial value of that representation placed at that offset. The different kinds of initial values are pad (uninitialized data), the address of some global variable plus the given offset, a procedure address (also specifying the return type of the procedure), an integer constant (possibly given in a string literal), a float constant (possibly given in a string literal), and a byte sequence.

static_init	::=	"static_init" "{" {static_init_entry} "}" ";"
static_init_entry	::=	"[" int "," representation "," static_init_value "]"
static_init_value	::=	"pad"
	|	"&" rtl_name ["+" integer]
	|	"&_proc" rtl_name representation
	|	integer | "istr" "(" string ")"
	|	float | double | "fstr" "(" string ")"
	|	"str" "(" string ")"
An associate declaration treats the named method as a method in the given message set with the listed specializers.

rtl_assoc_decl	::=	"associate" rtl_name "with"
		  rtl_name "(" rtl_formals ")" ";"
For example:

	associate wrapper__3FooFi with wrapper__Fi(@Foo, @any);
This says consider the routine named wrapper__3FooFi to be an implementation of the message wrapper__Fi attached at class Foo.

An include declaration names another file of RTL code to include as part of the program.

rtl_include_decl	 ::= "include" string ";"
A top-level statement block is a list of RTL statements that are to be executed upon program start-up. These expressions are evaluated in the order encountered during reading of the input files.

rtl_top_level_stmts ::=	 "rtl" "{" rtl_stmts "}" [";"]

RTL Grammar - 25 MARCH 1997
[Next] [Previous] [Top]

Generated with Harlequin WebMaker