A complex statement is how you would create something like the FOR statement in BASIC. In fact, ASIL’s FOR is described below in the sample code. The keyword instructions is how you specify where to run the code that was passed. instructions can take a comma delimited list of variables known to the statement being declared. So “instructions a, b, c” will allow the code being called with the instructions statement to reference a, b, and c as though they were keywords. Complex statements don’t have a return value. All variables passed to instructions are implicitly treated as constant by the calling code. You don’t need to take into account that the code might modify them. Any variables declared while passing actual parameters go out of scope the moment the complex statement returns. At that point, they might become subject to garbage collection.
You could use ASIL’s statement keyword to declare something like the for keyword in C if you wanted. Complex statements are the only place ASIL allows use of the Goto statement or labels.
Please note the version below is overloaded. Also, the out keyword causes the compiler to require a variable rather than a constant. (The ref by itself would do that as well, but out specifies the function will initialize the variable. ref corresponds to the C# keyword ref while out corresponds to C#’s out.) Formal parameters in complex statement declarations declared as out are the only procedure parameters that allow the caller to declare a variable in the call. See [Scope rules] for more information.
:::text
statement For var out Index% \=\ var InitialValue% \To\ var EndingValue% \Step\ var Skip%
Index% = InitialValue%
if not \Step\ then
Skip% = 1
label Loop
instructions ' Index% is already visible as it was passed to For.
label onnext
Index% ++ Skip%
If Index% <= EndingValue% Then
goto Loop
goto End
label onbreak
label End
statement <IndexType> For var out type CurItem \in\ var IIndexable<IndexType> Set
var IIndexer<IndexType> indexer = Set.Indexer
label Loop
label onnext
if indexer.isLast then
goto end
instructions indexer ' CurItem is already accessible as it was passed to For.
if not indexer.isLast then
indexer.next
goto Loop
label end
label onbreak
Some notes:
The second overload assumes the types shown below.
~~~~
:::text
interface IIndexable<indextype>
property IIndexer<indextype> Indexer
get</indextype></indextype>
interface IIndexer<indextype>
property boolean isLast
get</indextype>
property boolean hasMore
get
property IndexType Current
get
set
function next
returns IndexType
REM Should an IIndexer be bi-directional?
~~~~
Wiki: Home
Wiki: Scope rules
Wiki: When is it a procedure, command, function, property, property accessor, method, complex statement, or type cast?
Wiki: keywords-break
Wiki: keywords-instructions
Wiki: keywords-next
Wiki: keywords-onbreak
Wiki: keywords-onnext
Wiki: keywords-out
Wiki: keywords-ref
Wiki: keywords-statement
Wiki: keywords-static
Wiki: keywords-throws
Should an early return inside a instructions block be treated as a break? Sound off on it.
Related
Wiki: keywords-instructions
Last edit: Will Pittenger 2014-02-16