Complex Statements

Will Pittenger Bharath Gaddam

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.

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
    goto Loop

  label end
  label onbreak

Some notes:

  • In the first overload, \=\ causes the equal sign in actual calls to be treated properly. The slashes are needed to keep ASIL from seeing an operator to parse immediately.
  • In the second overload, you will see references to interfaces and generics. See the appropriate definitions in those sections.
  • If the label onnext is missing, the statement doesn’t allow use of the next keyword.
  • If the label onbreak is missing, the statement doesn’t allow use of the break keyword.
  • The second overload assumes the types shown below.

    interface IIndexable<IndexType>
      property IIndexer<IndexType> Indexer
    interface IIndexer<IndexType>
      property boolean isLast
      property boolean hasMore
      property IndexType Current
      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